diff --git a/src/lang/en_GB.json b/src/lang/en_GB.json index 25b8e4d..52db85b 100644 --- a/src/lang/en_GB.json +++ b/src/lang/en_GB.json @@ -38,6 +38,10 @@ "back": "Back" }, + "follow_requests": { + "none": "no follow requests to action right now!" + }, + "timeline": { "home": "Home", "local": "Local", diff --git a/src/lib/api.js b/src/lib/api.js index ee6c913..07644a3 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -202,6 +202,40 @@ export async function getFollowRequests(host, token, since_id, max_id, limit) { return data; } +/** + * POST /api/v1/follow_requests/:account_id/authorize + * @param {string} host - The domain of the target server. + * @param {string} token - The application token. + * @param {string} account_id - The account ID of the follow request to accept + */ +export async function acceptFollowRequest(host, token, account_id) { + let url = `https://${host}/api/v1/follow_requests/${account_id}/authorize`; + + const data = await fetch(url, { + method: 'POST', + headers: { "Authorization": "Bearer " + token } + }).then(res => res.json()); + + return data; +} + +/** + * POST /api/v1/follow_requests/:account_id/reject + * @param {string} host - The domain of the target server. + * @param {string} token - The application token. + * @param {string} account_id - The account ID of the follow request to reject + */ +export async function rejectFollowRequest(host, token, account_id) { + let url = `https://${host}/api/v1/follow_requests/${account_id}/reject`; + + const data = await fetch(url, { + method: 'POST', + headers: { "Authorization": "Bearer " + token } + }).then(res => res.json()); + + return data; +} + /** * GET /api/v1/timelines/{timeline} * @param {string} host - The domain of the target server. diff --git a/src/lib/followRequests.js b/src/lib/followRequests.js index 38aa77c..38a4e2d 100644 --- a/src/lib/followRequests.js +++ b/src/lib/followRequests.js @@ -3,6 +3,7 @@ import { writable } from "svelte/store"; import * as api from "./api.js"; import { app } from './client/app.js'; import { get } from 'svelte/store'; +import { parseAccount } from './account.js'; // Cache for all requests export let followRequests = writable(); @@ -20,5 +21,8 @@ export async function fetchFollowRequests(force) { get(app).token ); + // parse accounts + newReqs = newReqs.map((r) => parseAccount(r)); + followRequests.set(newReqs); } \ No newline at end of file diff --git a/src/routes/follow-requests/+page.svelte b/src/routes/follow-requests/+page.svelte index d67ac7d..75e1760 100644 --- a/src/routes/follow-requests/+page.svelte +++ b/src/routes/follow-requests/+page.svelte @@ -1,10 +1,144 @@ -
{lang.string('follow_requests.none')}
+{/if} - \ No newline at end of file +{#each $followRequests as req} +