diff --git a/src/lang/en_GB.json b/src/lang/en_GB.json index 0ffc265..38b7f75 100644 --- a/src/lang/en_GB.json +++ b/src/lang/en_GB.json @@ -94,7 +94,9 @@ "posts": "Posts", "replies": "Replies", - "media": "Media" + "media": "Media", + + "loading": "loading profile..." }, "logs": { @@ -104,9 +106,12 @@ "no_hostname": "Attempted to connect to a server without providing a hostname", "no_https": "Cowardly refusing to connect to an insecure server", "connection_failed": "Failed to connect to %1", - "post_fetch_failed": "Failed to fetch post %1", + "post_fetch_failed": "Failed to fetch post", + "post_fetch_failed_id": "Failed to fetch post %1", "post_parse_failed": "Failed to parse post", "post_parse_failed_id": "Failed to parse post %1", + "profile_fetch_failed": "Failed to fetch profile", + "profile_fetch_failed_id": "Failed to fetch profile %1", "token_revoke_failed": "Token revocation failed! Dumping data anyways", "sound_does_not_exist": "Attempted to play sound \"%1\", which does not exist!", "account_data_empty": "Attempted to parse account data but no data was provided", diff --git a/src/lib/account.js b/src/lib/account.js index 394fe0f..50ff0b3 100644 --- a/src/lib/account.js +++ b/src/lib/account.js @@ -27,7 +27,12 @@ export function parseAccount(data) { account.username = data.username; account.name = account.nickname || account.username; account.avatar_url = data.avatar; + account.banner_url = data.header; account.url = data.url; + account.followers_count = data.followers_count; + account.following_count = data.following_count; + account.posts_count = data.statuses_count; + account.bio = data.note; if (data.acct.includes('@')) account.host = data.acct.split('@')[1]; diff --git a/src/lib/api.js b/src/lib/api.js index 61f6bd9..c9b97ba 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -1,3 +1,7 @@ +const errors = { + AUTHENTICATION_FAILED: "AUTHENTICATION_FAILED", +}; + /** * GET /api/v1/instance * @param {string} host - The domain of the target server. @@ -421,3 +425,26 @@ export async function getUser(host, token, user_id) { return data; } + +/** + * GET /api/v1/accounts/lookup?acct={handle} + * @param {string} host - The domain of the target server. + * @param {string} token - The application token. + * @param {string} handle - The handle of the user to fetch. + */ +export async function lookupUser(host, token, handle) { + let url = `https://${host}/api/v1/accounts/lookup?acct=${handle}`; + + const res = await fetch(url, { + method: 'GET', + headers: { "Authorization": token ? `Bearer ${token}` : null } + }); + if (!res.ok) { + const json = await res.json(); + if (json.error = errors.AUTHENTICATION_FAILED) + throw new Error("This method requires authentication"); + } + const data = await res.json(); + + return data; +} diff --git a/src/lib/client/server.js b/src/lib/client/server.js index 3c85647..c1d6426 100644 --- a/src/lib/client/server.js +++ b/src/lib/client/server.js @@ -2,6 +2,9 @@ import * as api from '$lib/api.js'; import { writable } from 'svelte/store'; import { app_name } from '$lib/config.js'; import { browser } from "$app/environment"; +import Lang from '$lib/lang'; + +const lang = Lang('en_GB'); const server_types = { UNSUPPORTED: "unsupported", diff --git a/src/lib/ui/Button.svelte b/src/lib/ui/Button.svelte index c20c923..788828f 100644 --- a/src/lib/ui/Button.svelte +++ b/src/lib/ui/Button.svelte @@ -18,9 +18,21 @@ function click() { if (disabled) return; if (href) { - location = href; + const link = document.createElement('a'); + link.href = href; + link.dispatchEvent(new MouseEvent('click', { + bubbles: true, + cancelable: true, + view: window, + ctrlKey: event.ctrlKey, + metaKey: event.metaKey, + shiftKey: event.shiftKey, + altKey: event.altKey, + button: event.button, + })); return; } + playSound(sound); dispatch('click'); } diff --git a/src/lib/ui/Composer.svelte b/src/lib/ui/Composer.svelte index 7859a7e..f2664fa 100644 --- a/src/lib/ui/Composer.svelte +++ b/src/lib/ui/Composer.svelte @@ -90,7 +90,8 @@
- + +
diff --git a/src/lib/ui/Navigation.svelte b/src/lib/ui/Navigation.svelte index 96f4879..8cbb351 100644 --- a/src/lib/ui/Navigation.svelte +++ b/src/lib/ui/Navigation.svelte @@ -61,6 +61,16 @@ goto(route); } + function gotoProfile() { + if (!$account) return; + playSound(); + window.scrollTo({ + top: 0, + behavior: "smooth" + }); + goto(`/${$server.host}/${$account.username}`); + } + async function log_out() { if (!confirm("This will log you out. Are you sure?")) return; @@ -171,9 +181,9 @@
- playSound()}> + gotoProfile()}>