From f2c96d596874b2a51c12adf8c53a2ed78133ef19 Mon Sep 17 00:00:00 2001 From: ari melody Date: Sat, 29 Jun 2024 23:10:29 +0100 Subject: [PATCH] fixed boosts not displaying properly; among --- src/lib/client/api.js | 6 ++-- src/lib/client/client.js | 28 +++++++++------- src/lib/timeline.js | 3 +- src/lib/ui/Navigation.svelte | 12 +++---- src/lib/ui/post/Post.svelte | 10 +++--- src/lib/ui/post/ReplyContext.svelte | 4 +-- src/routes/+page.js | 13 ++++++++ src/routes/+page.svelte | 51 +++++++++++------------------ src/routes/callback/+layout.svelte | 1 - src/routes/callback/+page.js | 2 +- src/routes/callback/+page.svelte | 0 src/routes/post/[id]/+page.js | 14 ++------ 12 files changed, 70 insertions(+), 74 deletions(-) delete mode 100644 src/routes/callback/+layout.svelte delete mode 100644 src/routes/callback/+page.svelte diff --git a/src/lib/client/api.js b/src/lib/client/api.js index 6769ef5..a6ae8b4 100644 --- a/src/lib/client/api.js +++ b/src/lib/client/api.js @@ -256,7 +256,7 @@ export async function parsePost(data, ancestor_count, with_context) { post.reply_count = data.replies_count; post.favourite_count = data.favourites_count; post.favourited = data.favourited; - post.boosted = data.boosted; + post.boosted = data.reblogged; post.mentions = data.mentions; post.files = data.media_attachments; post.url = data.url; @@ -302,7 +302,7 @@ export async function parseUser(data) { if (data.acct.includes('@')) user.host = data.acct.split('@')[1]; else - user.host = get(Client.get()).instance.host; + user.host = client.instance.host; user.emojis = []; data.emojis.forEach(emoji_data => { @@ -312,7 +312,7 @@ export async function parseUser(data) { user.emojis.push(parseEmoji(emoji_data)); }); - get(Client.get()).putCacheUser(user); + client.putCacheUser(user); return user; } diff --git a/src/lib/client/client.js b/src/lib/client/client.js index 8b6031f..e96f864 100644 --- a/src/lib/client/client.js +++ b/src/lib/client/client.js @@ -23,10 +23,9 @@ export class Client { } static get() { - if (get(client)) return client; + let current = get(client); + if (current && current.app) return client; let new_client = new Client(); - if (typeof window !== typeof undefined) - window.peekie = new_client; new_client.load(); client.set(new_client); return client; @@ -45,13 +44,13 @@ export class Client { if (this.instance.type == server_types.UNSUPPORTED) { console.warn(`Server ${host} is unsupported - ${data.version}`); if (!confirm( - `This app does not officially support ${host}. ` + - `Things may break, or otherwise not work as epxected! ` + - `Are you sure you wish to continue?` - )) return false; + `This app does not officially support ${host}. ` + + `Things may break, or otherwise not work as epxected! ` + + `Are you sure you wish to continue?` + )) return false; } else { - console.log(`Server is "${this.instance.type}" (or compatible) with capabilities: [${this.instance.capabilities}].`); - } + console.log(`Server is "${this.instance.type}" (or compatible) with capabilities: [${this.instance.capabilities}].`); + } this.app = await api.createApp(host); @@ -86,13 +85,20 @@ export class Client { } async verifyCredentials() { + if (this.user) return this.user; + if (!this.app || !this.app.token) { + this.user = false; + return false; + } const data = await api.verifyCredentials(); if (!data) { this.user = false; return false; } - this.user = await api.parseUser(data); - client.set(this); + await client.update(async c => { + c.user = await api.parseUser(data); + console.log(`Logged in as @${c.user.username}@${c.user.host}`); + }); return this.user; } diff --git a/src/lib/timeline.js b/src/lib/timeline.js index 667b4ee..5858199 100644 --- a/src/lib/timeline.js +++ b/src/lib/timeline.js @@ -4,13 +4,14 @@ import { parsePost } from '$lib/client/api.js'; export let posts = writable([]); -let client = get(Client.get()); let loading = false; export async function getTimeline(clean) { if (loading) return; // no spamming!! loading = true; + let client = get(Client.get()); + let timeline_data; if (clean || get(posts).length === 0) timeline_data = await client.getTimeline() else timeline_data = await client.getTimeline(get(posts)[get(posts).length - 1].id); diff --git a/src/lib/ui/Navigation.svelte b/src/lib/ui/Navigation.svelte index 0566ef2..44d46ec 100644 --- a/src/lib/ui/Navigation.svelte +++ b/src/lib/ui/Navigation.svelte @@ -7,9 +7,10 @@ import { play_sound } from '$lib/sound.js'; import { getTimeline } from '$lib/timeline.js'; import { goto } from '$app/navigation'; + import { get } from 'svelte/store'; const VERSION = APP_VERSION; - + let client = false; Client.get().subscribe(c => { client = c; @@ -30,11 +31,10 @@ goto("/"); } - function log_out() { + async function log_out() { if (!confirm("This will log you out. Are you sure?")) return; - client.logout().then(() => { - location = "/"; - }); + await get(Client.get()).logout(); + goto("/"); } @@ -51,7 +51,7 @@ {/if}