diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcde5d7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.afdesign filter=lfs diff=lfs merge=lfs -text +*.woff2 filter=lfs diff=lfs merge=lfs -text diff --git a/index.html b/index.html index 82774d3..84feba1 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@
- + diff --git a/package.json b/package.json index 28b14be..d98a5c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spacesocial-client", - "version": "0.1.1", + "version": "0.2.0_rev1", "description": "social media for the galaxy-wide-web! 🌌", "type": "module", "scripts": { diff --git a/public/font/inter/Inter-Black.woff2 b/public/font/inter/Inter-Black.woff2 index 18b35db..b6f300b 100644 Binary files a/public/font/inter/Inter-Black.woff2 and b/public/font/inter/Inter-Black.woff2 differ diff --git a/public/font/inter/Inter-BlackItalic.woff2 b/public/font/inter/Inter-BlackItalic.woff2 index 02c9d8e..6c4e15a 100644 Binary files a/public/font/inter/Inter-BlackItalic.woff2 and b/public/font/inter/Inter-BlackItalic.woff2 differ diff --git a/public/font/inter/Inter-Bold.woff2 b/public/font/inter/Inter-Bold.woff2 index 0f1b157..cdb746b 100644 Binary files a/public/font/inter/Inter-Bold.woff2 and b/public/font/inter/Inter-Bold.woff2 differ diff --git a/public/font/inter/Inter-BoldItalic.woff2 b/public/font/inter/Inter-BoldItalic.woff2 index bc50f24..237102f 100644 Binary files a/public/font/inter/Inter-BoldItalic.woff2 and b/public/font/inter/Inter-BoldItalic.woff2 differ diff --git a/public/font/inter/Inter-ExtraBold.woff2 b/public/font/inter/Inter-ExtraBold.woff2 index b113368..8348666 100644 Binary files a/public/font/inter/Inter-ExtraBold.woff2 and b/public/font/inter/Inter-ExtraBold.woff2 differ diff --git a/public/font/inter/Inter-ExtraBoldItalic.woff2 b/public/font/inter/Inter-ExtraBoldItalic.woff2 index a5b76ca..5987daa 100644 Binary files a/public/font/inter/Inter-ExtraBoldItalic.woff2 and b/public/font/inter/Inter-ExtraBoldItalic.woff2 differ diff --git a/public/font/inter/Inter-ExtraLight.woff2 b/public/font/inter/Inter-ExtraLight.woff2 index 1d77ae8..3e72fc2 100644 Binary files a/public/font/inter/Inter-ExtraLight.woff2 and b/public/font/inter/Inter-ExtraLight.woff2 differ diff --git a/public/font/inter/Inter-ExtraLightItalic.woff2 b/public/font/inter/Inter-ExtraLightItalic.woff2 index 8c68492..d7cf078 100644 Binary files a/public/font/inter/Inter-ExtraLightItalic.woff2 and b/public/font/inter/Inter-ExtraLightItalic.woff2 differ diff --git a/public/font/inter/Inter-Italic.woff2 b/public/font/inter/Inter-Italic.woff2 index 4c24ce2..8516a24 100644 Binary files a/public/font/inter/Inter-Italic.woff2 and b/public/font/inter/Inter-Italic.woff2 differ diff --git a/public/font/inter/Inter-Light.woff2 b/public/font/inter/Inter-Light.woff2 index dbe6143..d104fb9 100644 Binary files a/public/font/inter/Inter-Light.woff2 and b/public/font/inter/Inter-Light.woff2 differ diff --git a/public/font/inter/Inter-LightItalic.woff2 b/public/font/inter/Inter-LightItalic.woff2 index a40d042..22cbd0f 100644 Binary files a/public/font/inter/Inter-LightItalic.woff2 and b/public/font/inter/Inter-LightItalic.woff2 differ diff --git a/public/font/inter/Inter-Medium.woff2 b/public/font/inter/Inter-Medium.woff2 index 0fd2ee7..1bc6931 100644 Binary files a/public/font/inter/Inter-Medium.woff2 and b/public/font/inter/Inter-Medium.woff2 differ diff --git a/public/font/inter/Inter-MediumItalic.woff2 b/public/font/inter/Inter-MediumItalic.woff2 index 9676715..e2595c6 100644 Binary files a/public/font/inter/Inter-MediumItalic.woff2 and b/public/font/inter/Inter-MediumItalic.woff2 differ diff --git a/public/font/inter/Inter-Regular.woff2 b/public/font/inter/Inter-Regular.woff2 index b8699af..f6de211 100644 Binary files a/public/font/inter/Inter-Regular.woff2 and b/public/font/inter/Inter-Regular.woff2 differ diff --git a/public/font/inter/Inter-SemiBold.woff2 b/public/font/inter/Inter-SemiBold.woff2 index 95c48b1..28b1b44 100644 Binary files a/public/font/inter/Inter-SemiBold.woff2 and b/public/font/inter/Inter-SemiBold.woff2 differ diff --git a/public/font/inter/Inter-SemiBoldItalic.woff2 b/public/font/inter/Inter-SemiBoldItalic.woff2 index ddfe19e..d94b237 100644 Binary files a/public/font/inter/Inter-SemiBoldItalic.woff2 and b/public/font/inter/Inter-SemiBoldItalic.woff2 differ diff --git a/public/font/inter/Inter-Thin.woff2 b/public/font/inter/Inter-Thin.woff2 index 0790960..28c6dbb 100644 Binary files a/public/font/inter/Inter-Thin.woff2 and b/public/font/inter/Inter-Thin.woff2 differ diff --git a/public/font/inter/Inter-ThinItalic.woff2 b/public/font/inter/Inter-ThinItalic.woff2 index a7bf213..a9002fe 100644 Binary files a/public/font/inter/Inter-ThinItalic.woff2 and b/public/font/inter/Inter-ThinItalic.woff2 differ diff --git a/public/font/inter/InterDisplay-Black.woff2 b/public/font/inter/InterDisplay-Black.woff2 index 8138123..9793f09 100644 Binary files a/public/font/inter/InterDisplay-Black.woff2 and b/public/font/inter/InterDisplay-Black.woff2 differ diff --git a/public/font/inter/InterDisplay-BlackItalic.woff2 b/public/font/inter/InterDisplay-BlackItalic.woff2 index 735ba21..5706f12 100644 Binary files a/public/font/inter/InterDisplay-BlackItalic.woff2 and b/public/font/inter/InterDisplay-BlackItalic.woff2 differ diff --git a/public/font/inter/InterDisplay-Bold.woff2 b/public/font/inter/InterDisplay-Bold.woff2 index 11c6719..a56a95d 100644 Binary files a/public/font/inter/InterDisplay-Bold.woff2 and b/public/font/inter/InterDisplay-Bold.woff2 differ diff --git a/public/font/inter/InterDisplay-BoldItalic.woff2 b/public/font/inter/InterDisplay-BoldItalic.woff2 index 5b6a1fb..777ba23 100644 Binary files a/public/font/inter/InterDisplay-BoldItalic.woff2 and b/public/font/inter/InterDisplay-BoldItalic.woff2 differ diff --git a/public/font/inter/InterDisplay-ExtraBold.woff2 b/public/font/inter/InterDisplay-ExtraBold.woff2 index 9058e98..95672a5 100644 Binary files a/public/font/inter/InterDisplay-ExtraBold.woff2 and b/public/font/inter/InterDisplay-ExtraBold.woff2 differ diff --git a/public/font/inter/InterDisplay-ExtraBoldItalic.woff2 b/public/font/inter/InterDisplay-ExtraBoldItalic.woff2 index 4cd61c0..c68e98a 100644 Binary files a/public/font/inter/InterDisplay-ExtraBoldItalic.woff2 and b/public/font/inter/InterDisplay-ExtraBoldItalic.woff2 differ diff --git a/public/font/inter/InterDisplay-ExtraLight.woff2 b/public/font/inter/InterDisplay-ExtraLight.woff2 index 8621b29..44c4de5 100644 Binary files a/public/font/inter/InterDisplay-ExtraLight.woff2 and b/public/font/inter/InterDisplay-ExtraLight.woff2 differ diff --git a/public/font/inter/InterDisplay-ExtraLightItalic.woff2 b/public/font/inter/InterDisplay-ExtraLightItalic.woff2 index 689c8d9..c36e4e0 100644 Binary files a/public/font/inter/InterDisplay-ExtraLightItalic.woff2 and b/public/font/inter/InterDisplay-ExtraLightItalic.woff2 differ diff --git a/public/font/inter/InterDisplay-Italic.woff2 b/public/font/inter/InterDisplay-Italic.woff2 index 11f20bc..02bddbe 100644 Binary files a/public/font/inter/InterDisplay-Italic.woff2 and b/public/font/inter/InterDisplay-Italic.woff2 differ diff --git a/public/font/inter/InterDisplay-Light.woff2 b/public/font/inter/InterDisplay-Light.woff2 index 446301c..8d008cb 100644 Binary files a/public/font/inter/InterDisplay-Light.woff2 and b/public/font/inter/InterDisplay-Light.woff2 differ diff --git a/public/font/inter/InterDisplay-LightItalic.woff2 b/public/font/inter/InterDisplay-LightItalic.woff2 index f688196..43a7705 100644 Binary files a/public/font/inter/InterDisplay-LightItalic.woff2 and b/public/font/inter/InterDisplay-LightItalic.woff2 differ diff --git a/public/font/inter/InterDisplay-Medium.woff2 b/public/font/inter/InterDisplay-Medium.woff2 index 29160b2..e7eaab7 100644 Binary files a/public/font/inter/InterDisplay-Medium.woff2 and b/public/font/inter/InterDisplay-Medium.woff2 differ diff --git a/public/font/inter/InterDisplay-MediumItalic.woff2 b/public/font/inter/InterDisplay-MediumItalic.woff2 index ef1bcbe..6e51841 100644 Binary files a/public/font/inter/InterDisplay-MediumItalic.woff2 and b/public/font/inter/InterDisplay-MediumItalic.woff2 differ diff --git a/public/font/inter/InterDisplay-Regular.woff2 b/public/font/inter/InterDisplay-Regular.woff2 index a6c04f6..e532c84 100644 Binary files a/public/font/inter/InterDisplay-Regular.woff2 and b/public/font/inter/InterDisplay-Regular.woff2 differ diff --git a/public/font/inter/InterDisplay-SemiBold.woff2 b/public/font/inter/InterDisplay-SemiBold.woff2 index 2b4db23..574aada 100644 Binary files a/public/font/inter/InterDisplay-SemiBold.woff2 and b/public/font/inter/InterDisplay-SemiBold.woff2 differ diff --git a/public/font/inter/InterDisplay-SemiBoldItalic.woff2 b/public/font/inter/InterDisplay-SemiBoldItalic.woff2 index 59091db..5103a6b 100644 Binary files a/public/font/inter/InterDisplay-SemiBoldItalic.woff2 and b/public/font/inter/InterDisplay-SemiBoldItalic.woff2 differ diff --git a/public/font/inter/InterDisplay-Thin.woff2 b/public/font/inter/InterDisplay-Thin.woff2 index dc0b948..c8231c3 100644 Binary files a/public/font/inter/InterDisplay-Thin.woff2 and b/public/font/inter/InterDisplay-Thin.woff2 differ diff --git a/public/font/inter/InterDisplay-ThinItalic.woff2 b/public/font/inter/InterDisplay-ThinItalic.woff2 index 96439c0..9be1cfb 100644 Binary files a/public/font/inter/InterDisplay-ThinItalic.woff2 and b/public/font/inter/InterDisplay-ThinItalic.woff2 differ diff --git a/public/font/inter/InterVariable-Italic.woff2 b/public/font/inter/InterVariable-Italic.woff2 index f22ec25..aa582c3 100644 Binary files a/public/font/inter/InterVariable-Italic.woff2 and b/public/font/inter/InterVariable-Italic.woff2 differ diff --git a/public/font/inter/InterVariable.woff2 b/public/font/inter/InterVariable.woff2 index 22a12b0..b7bcaf7 100644 Binary files a/public/font/inter/InterVariable.woff2 and b/public/font/inter/InterVariable.woff2 differ diff --git a/public/media/ariyeah-button.png b/public/media/ariyeah-button.png deleted file mode 100644 index c6eab57..0000000 Binary files a/public/media/ariyeah-button.png and /dev/null differ diff --git a/public/media/beer.jpg b/public/media/beer.jpg deleted file mode 100644 index c69af44..0000000 Binary files a/public/media/beer.jpg and /dev/null differ diff --git a/public/media/duck.jpg b/public/media/duck.jpg deleted file mode 100644 index d373efe..0000000 Binary files a/public/media/duck.jpg and /dev/null differ diff --git a/res/spacesocial-logo.afdesign b/res/spacesocial-logo.afdesign new file mode 100644 index 0000000..7e42a6e --- /dev/null +++ b/res/spacesocial-logo.afdesign @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a03c7e1af2cc54bbe621de3a68f41a75574dbcc498a9918e9fe387c5cb9d31c0 +size 41570 diff --git a/src/App.svelte b/src/App.svelte index 604190a..7538a88 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,92 +1,109 @@ -
-

space social

-

social media for the galaxy-wide-web! 🌌

- -
+
-
- {#if ready} - - {:else} -
-
-

welcome!

-

please enter your instance domain to log in.

- - -
+
+ +
-
+
+ {#if ready} + + {:else} +
+
+

Space Social

+

Welcome, fediverse user!

+

Please enter your instance domain to log in.

+
+ + {#if instance_url_error} +

{instance_url_error}

+ {/if} +
+
+ +

+ Please note this is + extremely experimental software; + things are likely to break! +
+ If that's all cool with you, welcome aboard! +

-

- please note this is extremely experimental software; - even if you use the exact same instance as me, you may encounter problems. - if that's all cool with you, welcome aboard! -

+ +
+
+ {/if} +
-

made with ❤ī¸ by ari melody, 2024

-
- {/if} -
+
+ +
- +
diff --git a/src/Feed.svelte b/src/Feed.svelte deleted file mode 100644 index cafdfa0..0000000 --- a/src/Feed.svelte +++ /dev/null @@ -1,101 +0,0 @@ - - -
- {#if error} - ')} /> - {/if} - {#if posts.length <= 0} -
- just a moment... -
- {/if} - {#each posts as post} - - {/each} -
- - diff --git a/src/app.css b/src/app.css index 6e36d45..6571118 100644 --- a/src/app.css +++ b/src/app.css @@ -1,20 +1,54 @@ @import url("/font/inter/inter.css"); :root { - --fg0: #eee; - --bg0: #080808; - --bg1: #101010; - --bg2: #121212; - --accent: #b7fd49; - --accent-bg: #242b1a; + --bg-1000: #fff6de; + --bg-900: #f9f1db; + --bg-800: #f1e8cf; + --bg-700: #d2c9b1; + --bg-600: #f0f6c2; + --accent: #8d9936; + --text: #322e1f; +} + +@media (prefers-color-scheme: dark) { + :root { + --bg-1000: #141016; + --bg-900: #1B141E; + --bg-800: #2A202F; + --bg-700: #443749; + --bg-600: #513D60; + --accent: #CDA1EC; + --text: #E2DFE3; + } +} + +@supports (font-variation-settings: normal) { + body { font-family: InterVariable, sans-serif; } } body { + width: 100vw; margin: 0; padding: 0; - color: var(--fg0); - background-color: var(--bg0); + color: var(--text); + background-color: var(--bg-1000); font-family: "Inter", sans-serif; + font-feature-settings: 'liga' 1, 'calt' 1; /* fix for Chrome */ + + box-sizing: border-box; +} + +.throb { + animation: .25s throb alternate infinite ease-in; +} + +@keyframes throb { + from { + opacity: .5; + } + to { + opacity: 1; + } } diff --git a/src/client/api.js b/src/client/api.js index 61cc5a3..dfcf733 100644 --- a/src/client/api.js +++ b/src/client/api.js @@ -1,8 +1,9 @@ import { Client } from '../client/client.js'; import { capabilities } from '../client/instance.js'; -import Post from '../post/post.js'; +import Post from '../post.js'; import User from '../user/user.js'; import Emoji from '../emoji.js'; +import { get } from 'svelte/store'; export async function createApp(host) { let form = new FormData(); @@ -30,7 +31,7 @@ export async function createApp(host) { } export function getOAuthUrl() { - let client = Client.get(); + let client = get(Client.get()); return `https://${client.instance.host}/oauth/authorize` + `?client_id=${client.app.id}` + "&scope=read+write+push" + @@ -39,7 +40,7 @@ export function getOAuthUrl() { } export async function getToken(code) { - let client = Client.get(); + let client = get(Client.get()); let form = new FormData(); form.append("client_id", client.app.id); form.append("client_secret", client.app.secret); @@ -64,7 +65,7 @@ export async function getToken(code) { } export async function revokeToken() { - let client = Client.get(); + let client = get(Client.get()); let form = new FormData(); form.append("client_id", client.app.id); form.append("client_secret", client.app.secret); @@ -83,8 +84,19 @@ export async function revokeToken() { return true; } +export async function verifyCredentials() { + let client = get(Client.get()); + let url = `https://${client.instance.host}/api/v1/accounts/verify_credentials`; + const data = await fetch(url, { + method: 'GET', + headers: { "Authorization": "Bearer " + client.app.token } + }).then(res => res.json()); + + return data; +} + export async function getTimeline(last_post_id) { - let client = Client.get(); + let client = get(Client.get()); let url = `https://${client.instance.host}/api/v1/timelines/home`; if (last_post_id) url += "?max_id=" + last_post_id; const data = await fetch(url, { @@ -95,8 +107,8 @@ export async function getTimeline(last_post_id) { return data; } -export async function getPost(post_id, num_replies) { - let client = Client.get(); +export async function getPost(post_id, parent_replies) { + let client = get(Client.get()); let url = `https://${client.instance.host}/api/v1/statuses/${post_id}`; const data = await fetch(url, { method: 'GET', @@ -104,23 +116,49 @@ export async function getPost(post_id, num_replies) { }).then(res => { return res.ok ? res.json() : false }); if (data === false) return false; - - const post = await parsePost(data, num_replies); - if (post === null || post === undefined) { - if (data.id) { - console.warn("Failed to parse post data #" + data.id); - } else { - console.warn("Failed to parse post data:"); - console.warn(data); - } - return false; - } - return post; + return data; } -export async function parsePost(data, num_replies) { - let client = Client.get(); - let post = new Post() +export async function getPostContext(post_id) { + let client = get(Client.get()); + let url = `https://${client.instance.host}/api/v1/statuses/${post_id}/context`; + const data = await fetch(url, { + method: 'GET', + headers: { "Authorization": "Bearer " + client.app.token } + }).then(res => { return res.ok ? res.json() : false }); + + if (data === false) return false; + return data; +} + +export async function parsePost(data, parent_replies, child_replies) { + let client = get(Client.get()); + let post = new Post(); + + // if (client.instance.capabilities.includes(capabilities.MARKDOWN_CONTENT)) + // post.text = data.text; + // else + post.text = data.content; + + post.reply = null; + if ((data.in_reply_to_id || data.reply) && parent_replies !== 0) { + const reply_data = data.reply || await getPost(data.in_reply_to_id, parent_replies - 1); + post.reply = await parsePost(reply_data, parent_replies - 1, false); + // if the post returns false, we probably don't have permission to read it. + // we'll respect the thread's privacy, and leave it alone :) + if (post.reply === false) return false; + } + post.boost = data.reblog ? await parsePost(data.reblog, 1, false) : null; + + post.replies = []; + if (child_replies) { + const replies_data = await getPostContext(data.id); + if (replies_data && replies_data.descendants) { + for (let i in replies_data.descendants) { + post.replies.push(await parsePost(replies_data.descendants[i], 0, false)); + } + } + } post.id = data.id; post.created_at = new Date(data.created_at); @@ -133,32 +171,20 @@ export async function parsePost(data, num_replies) { post.url = data.url; post.visibility = data.visibility; - if (client.instance.capabilities.includes(capabilities.MARKDOWN_CONTENT)) - post.text = data.text; - else - post.text = data.content; - - post.reply = null; - if (data.in_reply_to_id && num_replies > 0) { - post.reply = await getPost(data.in_reply_to_id, num_replies - 1); - // if the post returns false, we probably don't have permission to read it. - // we'll respect the thread's privacy, and leave it alone :) - if (post.reply === false) return false; - } - post.boost = data.reblog ? await parsePost(data.reblog, 1) : null; - post.emojis = []; - data.emojis.forEach(emoji_data => { - let name = emoji_data.shortcode.split('@')[0]; - post.emojis.push(parseEmoji({ - id: name + '@' + post.user.host, - name: name, - host: post.user.host, - url: emoji_data.url, - })); - }); + if (data.emojis) { + data.emojis.forEach(emoji_data => { + let name = emoji_data.shortcode.split('@')[0]; + post.emojis.push(parseEmoji({ + id: name + '@' + post.user.host, + name: name, + host: post.user.host, + url: emoji_data.url, + })); + }); + } - if (client.instance.capabilities.includes(capabilities.REACTIONS)) { + if (data.reactions && client.instance.capabilities.includes(capabilities.REACTIONS)) { post.reactions = []; data.reactions.forEach(reaction_data => { if (/^[\w\-.@]+$/g.exec(reaction_data.name)) { @@ -191,7 +217,17 @@ export async function parsePost(data, num_replies) { } export async function parseUser(data) { - let user = new User(); + if (!data) { + console.error("Attempted to parse user data but no data was provided"); + return null; + } + let client = get(Client.get()); + let user = await client.getCacheUser(data.id); + + if (user) return user; + // cache miss! + + user = new User(); user.id = data.id; user.nickname = data.display_name; user.username = data.username; @@ -201,7 +237,7 @@ export async function parseUser(data) { if (data.acct.includes('@')) user.host = data.acct.split('@')[1]; else - user.host = Client.get().instance.host; + user.host = get(Client.get()).instance.host; user.emojis = []; data.emojis.forEach(emoji_data => { @@ -211,7 +247,7 @@ export async function parseUser(data) { user.emojis.push(parseEmoji(emoji_data)); }); - Client.get().putCacheUser(user); + get(Client.get()).putCacheUser(user); return user; } @@ -222,12 +258,12 @@ export function parseEmoji(data) { data.host, data.url, ); - Client.get().putCacheEmoji(emoji); + get(Client.get()).putCacheEmoji(emoji); return emoji; } export async function getUser(user_id) { - let client = Client.get(); + let client = get(Client.get()); let url = `https://${client.instance.host}/api/v1/accounts/${user_id}`; const data = await fetch(url, { method: 'GET', diff --git a/src/client/client.js b/src/client/client.js index 2101b0f..575c293 100644 --- a/src/client/client.js +++ b/src/client/client.js @@ -1,14 +1,16 @@ import { version as APP_VERSION } from '../../package.json'; import { Instance, server_types } from './instance.js'; import * as api from './api.js'; +import { get, writable } from 'svelte/store'; -let client = false; +let client = writable(false); const save_name = "spacesocial"; export class Client { instance; app; + user; #cache; constructor() { @@ -21,10 +23,11 @@ export class Client { } static get() { - if (client) return client; - client = new Client(); - window.peekie = client; - client.load(); + if (get(client)) return client; + let new_client = new Client(); + window.peekie = new_client; + new_client.load(); + client.set(new_client); return client; } @@ -34,8 +37,7 @@ export class Client { const data = await fetch(url).then(res => res.json()).catch(error => { console.error(error) }); if (!data) { console.error(`Failed to connect to ${host}`); - alert(`Failed to connect to ${host}! Please try again later.`); - return false; + return `Failed to connect to ${host}!`; } this.instance = new Instance(host, data.version); @@ -59,6 +61,8 @@ export class Client { this.save(); + client.set(this); + return true; } @@ -73,31 +77,38 @@ export class Client { return false; } this.app.token = token; + client.set(this); } async revokeToken() { return await api.revokeToken(); } + async verifyCredentials() { + const data = await api.verifyCredentials(); + if (!data) return false; + this.user = await api.parseUser(data); + client.set(this); + return data; + } + async getTimeline(last_post_id) { return await api.getTimeline(last_post_id); } - async getPost(post_id, num_replies) { - return await api.getPost(post_id, num_replies); + async getPost(post_id, parent_replies, child_replies) { + return await api.getPost(post_id, parent_replies, child_replies); } putCacheUser(user) { this.cache.users[user.id] = user; + client.set(this); } - async getUser(user_id) { + async getCacheUser(user_id) { let user = this.cache.users[user_id]; if (user) return user; - user = await api.getUser(user_id); - if (user) return user; - return false; } @@ -112,6 +123,7 @@ export class Client { putCacheEmoji(emoji) { this.cache.emojis[emoji.id] = emoji; + client.set(this); } getEmoji(emoji_id) { @@ -142,6 +154,7 @@ export class Client { } this.instance = new Instance(saved.instance.host, saved.instance.version); this.app = saved.app; + client.set(this); return true; } @@ -151,7 +164,7 @@ export class Client { console.warn("Failed to log out correctly; ditching the old tokens anyways."); } localStorage.removeItem(save_name); - client = new Client(); + client.set(false); console.log("Logged out successfully."); } } diff --git a/src/emoji.js b/src/emoji.js index bddc8ea..9cd5e12 100644 --- a/src/emoji.js +++ b/src/emoji.js @@ -1,4 +1,5 @@ import { Client } from './client/client.js'; +import { get } from 'svelte/store'; export const EMOJI_REGEX = /:[\w\-.]{0,32}@[\w\-.]{0,32}:/g; export const EMOJI_NAME_REGEX = /:[\w\-.]{0,32}:/g; @@ -31,7 +32,7 @@ export function parseText(text, host) { let length = text.substring(index + 1).search(':'); if (length <= 0) return text; let emoji_name = text.substring(index + 1, index + length + 1); - let emoji = Client.get().getEmoji(emoji_name + '@' + host); + let emoji = get(Client.get()).getEmoji(emoji_name + '@' + host); if (emoji) { return text.substring(0, index) + emoji.html + @@ -44,7 +45,7 @@ export function parseText(text, host) { export function parseOne(emoji_id) { if (emoji_id == '❤') return '❤ī¸'; // stupid heart unicode if (EMOJI_REGEX.exec(':' + emoji_id + ':')) return emoji_id; - let cached_emoji = Client.get().getEmoji(emoji_id); + let cached_emoji = get(Client.get()).getEmoji(emoji_id); if (!cached_emoji) return emoji_id; return cached_emoji.html; } diff --git a/src/img/spacesocial-logo.svg b/src/img/spacesocial-logo.svg new file mode 100644 index 0000000..b4f6ac0 --- /dev/null +++ b/src/img/spacesocial-logo.svg @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + space social + + diff --git a/src/post/post.js b/src/post.js similarity index 98% rename from src/post/post.js rename to src/post.js index 3550c0f..1468ef9 100644 --- a/src/post/post.js +++ b/src/post.js @@ -1,4 +1,4 @@ -import { parseText as parseEmoji } from '../emoji.js'; +import { parseText as parseEmoji } from './emoji.js'; export default class Post { id; @@ -14,6 +14,7 @@ export default class Post { files; url; reply; + replies; boost; visibility; diff --git a/src/post/Post.svelte b/src/post/Post.svelte deleted file mode 100644 index 408fc5d..0000000 --- a/src/post/Post.svelte +++ /dev/null @@ -1,85 +0,0 @@ - - -
- {#if post.reply} - - {/if} - {#if is_boost && !post_context.text} - - {/if} -
-
- - -
-
- - diff --git a/src/post/ReplyContext.svelte b/src/post/ReplyContext.svelte deleted file mode 100644 index 497d2f1..0000000 --- a/src/post/ReplyContext.svelte +++ /dev/null @@ -1,153 +0,0 @@ - - -
-
- - - -
-
-
- -
-
-
- - -
-
- - - - -
-
- - diff --git a/src/sound.js b/src/sound.js index bbbd62f..c5dc1fb 100644 --- a/src/sound.js +++ b/src/sound.js @@ -12,6 +12,7 @@ export function play_sound(name) { return; } sound.pause(); + sound.volume = 0.25; sound.currentTime = 0; sound.play(); } diff --git a/src/ui/Button.svelte b/src/ui/Button.svelte new file mode 100644 index 0000000..1ea915f --- /dev/null +++ b/src/ui/Button.svelte @@ -0,0 +1,134 @@ + + + + + diff --git a/src/Error.svelte b/src/ui/Error.svelte similarity index 100% rename from src/Error.svelte rename to src/ui/Error.svelte diff --git a/src/ui/Feed.svelte b/src/ui/Feed.svelte new file mode 100644 index 0000000..a3a7062 --- /dev/null +++ b/src/ui/Feed.svelte @@ -0,0 +1,132 @@ + + +
+

Home

+ +
+ +
+ {#if posts.length <= 0} +
+ just a moment... +
+ {/if} + {#each posts as post} + + {/each} +
+ + diff --git a/src/ui/Navigation.svelte b/src/ui/Navigation.svelte new file mode 100644 index 0000000..5b77519 --- /dev/null +++ b/src/ui/Navigation.svelte @@ -0,0 +1,281 @@ + + + + + diff --git a/src/ui/Widgets.svelte b/src/ui/Widgets.svelte new file mode 100644 index 0000000..5830adf --- /dev/null +++ b/src/ui/Widgets.svelte @@ -0,0 +1,39 @@ +
+ +
+ + diff --git a/src/post/FooterButton.svelte b/src/ui/post/ActionButton.svelte similarity index 91% rename from src/post/FooterButton.svelte rename to src/ui/post/ActionButton.svelte index 79a355b..e62ce0f 100644 --- a/src/post/FooterButton.svelte +++ b/src/ui/post/ActionButton.svelte @@ -1,5 +1,5 @@ + +
+ {#if post.reply} + + {/if} + {#if is_boost && !post_context.text} + + {/if} +
+ + + +
+
+ + diff --git a/src/post/Header.svelte b/src/ui/post/PostHeader.svelte similarity index 73% rename from src/post/Header.svelte rename to src/ui/post/PostHeader.svelte index 56168b5..b773ed2 100644 --- a/src/post/Header.svelte +++ b/src/ui/post/PostHeader.svelte @@ -1,13 +1,14 @@ -
+
@@ -20,7 +21,8 @@ {#if post.visibility !== "public"} - ({post.visibility}) +
+ {post.visibility} {/if}
@@ -29,10 +31,16 @@ diff --git a/src/ui/post/ReactionButton.svelte b/src/ui/post/ReactionButton.svelte new file mode 100644 index 0000000..e62ce0f --- /dev/null +++ b/src/ui/post/ReactionButton.svelte @@ -0,0 +1,66 @@ + + + + + diff --git a/src/ui/post/ReplyContext.svelte b/src/ui/post/ReplyContext.svelte new file mode 100644 index 0000000..a5dab1f --- /dev/null +++ b/src/ui/post/ReplyContext.svelte @@ -0,0 +1,81 @@ + + +{#if post.reply} + +{/if} + +
gotoPost()}> +
+ +
+ + + + +
+
+ {#each post.reactions as reaction} + + {/each} +
+
+ + + + + + +
+
+
+
+ + diff --git a/src/user/user.js b/src/user/user.js index fb48edb..7b91fe8 100644 --- a/src/user/user.js +++ b/src/user/user.js @@ -1,5 +1,6 @@ import { Client } from '../client/client.js'; import { parseText as parseEmojis } from '../emoji.js'; +import { get } from 'svelte/store'; export default class User { id; @@ -16,7 +17,7 @@ export default class User { get mention() { let res = "@" + this.username; - if (this.host != Client.get().instance.host) + if (this.host != get(Client.get()).instance.host) res += "@" + this.host; return res; }