fixed boosts not displaying properly; among

This commit is contained in:
ari melody 2024-06-29 23:10:29 +01:00
parent 5db825d97e
commit f2c96d5968
Signed by: ari
GPG key ID: CF99829C92678188
12 changed files with 70 additions and 74 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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("/");
}
</script>
@ -51,7 +51,7 @@
{/if}
<div id="nav-items">
<Button label="Timeline" on:click={() => goTimeline()} active>🖼️ Timeline</Button>
<Button label="Timeline" on:click={() => goTimeline()} active={client.user}>🖼️ Timeline</Button>
<Button label="Notifications" disabled>
🔔 Notifications
{#if notification_count}

View file

@ -42,8 +42,8 @@
console.error(`Failed to boost post ${post.id}`);
return;
}
post.boosted = data.boosted;
post.boost_count = data.reblogs_count;
post.boosted = data.reblog ? data.reblog.reblogged : data.boosted;
post.boost_count = data.reblog ? data.reblog.reblogs_count : data.reblogs_count;
}
async function toggleFavourite() {
@ -88,8 +88,6 @@
});
let aria_label = post.user.username + '; ' + post.text + '; ' + post.created_at;
if (post.reply && post.reply.id === undefined) console.log(post);
</script>
<div class="post-container">
@ -128,8 +126,8 @@
</div>
<div class="post-actions" aria-label="Post actions" on:click|stopPropagation on:keydown|stopPropagation>
<ActionButton type="reply" label="Reply" bind:count={post.reply_count} sound="post" disabled>🗨️</ActionButton>
<ActionButton type="boost" label="Boost" on:click={() => toggleBoost()} bind:active={post.boosted} bind:count={post.boost_count} sound="boost">🔁</ActionButton>
<ActionButton type="favourite" label="Favourite" on:click={() => toggleFavourite()} bind:active={post.favourited} bind:count={post.favourite_count}>⭐</ActionButton>
<ActionButton type="boost" label="Boost" on:click={toggleBoost} bind:active={post.boosted} bind:count={post.boost_count} sound="boost">🔁</ActionButton>
<ActionButton type="favourite" label="Favourite" on:click={toggleFavourite} bind:active={post.favourited} bind:count={post.favourite_count}>⭐</ActionButton>
<ActionButton type="react" label="React" disabled>😃</ActionButton>
<ActionButton type="quote" label="Quote" disabled>🗣️</ActionButton>
<ActionButton type="more" label="More" disabled>🛠️</ActionButton>

View file

@ -108,8 +108,8 @@
</div>
<div class="post-actions" aria-label="Post actions" on:click|stopPropagation on:keydown|stopPropagation>
<ActionButton type="reply" label="Reply" bind:count={post.reply_count} sound="post" disabled>🗨️</ActionButton>
<ActionButton type="boost" label="Boost" on:click={() => toggleBoost()} bind:active={post.boosted} bind:count={post.boost_count} sound="boost">🔁</ActionButton>
<ActionButton type="favourite" label="Favourite" on:click={() => toggleFavourite()} bind:active={post.favourited} bind:count={post.favourite_count}>⭐</ActionButton>
<ActionButton type="boost" label="Boost" on:click={toggleBoost} bind:active={post.boosted} bind:count={post.boost_count} sound="boost">🔁</ActionButton>
<ActionButton type="favourite" label="Favourite" on:click={toggleFavourite} bind:active={post.favourited} bind:count={post.favourite_count}>⭐</ActionButton>
<ActionButton type="react" label="React" disabled>😃</ActionButton>
<ActionButton type="quote" label="Quote" disabled>🗣️</ActionButton>
<ActionButton type="more" label="More" disabled>🛠️</ActionButton>