From 99def58c8b1799ad4f18c0e8f8752259d1fc4f15 Mon Sep 17 00:00:00 2001 From: mae taylor Date: Tue, 15 Jul 2025 15:37:03 +0100 Subject: [PATCH] feat: partial favourites --- src/lib/api.js | 24 ++++++++++++++++++++ src/lib/timeline.js | 29 +++++++++++++++++------- src/routes/favourites/+page.svelte | 36 ++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 src/routes/favourites/+page.svelte diff --git a/src/lib/api.js b/src/lib/api.js index 4fc3606..4c8c38c 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -242,6 +242,8 @@ export async function rejectFollowRequest(host, token, account_id) { * @param {string} token - The application token. * @param {string} timeline - The name of the timeline to pull (default "home"). * @param {string} max_id - If provided, only shows posts after this ID. + * @param {boolean} local_only - If provided, only shows posts from the local instance + * @param {boolean} remote_only - If provided, only shows posts from other instances */ export async function getTimeline(host, token, timeline, max_id, local_only, remote_only) { let url = `https://${host}/api/v1/timelines/${timeline || "home"}`; @@ -558,3 +560,25 @@ export async function getUserPinnedPosts(host, token, user_id) { return data; } + +/** + * GET /api/v1/favourites + * @param {string} host - The domain of the target server. + * @param {string} token - The application token. + * @param {string} max_id - If provided, only shows posts after this ID. + */ +export async function getFavourites(host, token, timeline, max_id) { + let url = `https://${host}/api/v1/favourites`; + + let params = new URLSearchParams(); + if (max_id) params.append("max_id", max_id); + const params_string = params.toString(); + if (params_string) url += '?' + params_string; + + const data = await fetch(url, { + method: 'GET', + headers: { "Authorization": token ? `Bearer ${token}` : null } + }).then(res => res.json()); + + return data; +} diff --git a/src/lib/timeline.js b/src/lib/timeline.js index b5f8c2e..0f54e91 100644 --- a/src/lib/timeline.js +++ b/src/lib/timeline.js @@ -19,14 +19,27 @@ export async function getTimeline(timelineType = "home", clean, localOnly = fals if (!clean && get(timeline).length > 0) last_post = get(timeline)[get(timeline).length - 1].id; - const timeline_data = await api.getTimeline( - get(server).host, - get(app).token, - timelineType, - last_post, - localOnly, - remoteOnly -); + let timeline_data; + switch(timelineType) { + case "favourites": + timeline_data = await api.getFavourites( + get(server).host, + get(app).token, + last_post, + ) + break; + + default: + timeline_data = await api.getTimeline( + get(server).host, + get(app).token, + timelineType, + last_post, + localOnly, + remoteOnly + ); + break; + } if (!timeline_data) { console.error(lang.string('logs.timeline_fetch_failed')); diff --git a/src/routes/favourites/+page.svelte b/src/routes/favourites/+page.svelte new file mode 100644 index 0000000..0fa8d44 --- /dev/null +++ b/src/routes/favourites/+page.svelte @@ -0,0 +1,36 @@ + + + + +
+ {#if $timeline.length <= 0} +
+ {lang.string('timeline.fetching')} +
+ {/if} + {#each $timeline as post} + + {/each} +
\ No newline at end of file