From ce2f09721d8ee01e5f461598a76e628f69fa56e1 Mon Sep 17 00:00:00 2001 From: ari melody Date: Tue, 2 Jul 2024 21:58:46 +0100 Subject: [PATCH 01/40] fixed emote display in usernames and reactions --- src/lib/app.css | 5 +++++ src/lib/ui/Navigation.svelte | 7 ++++++- src/lib/ui/post/ReactionButton.svelte | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/app.css b/src/lib/app.css index d010639..191f143 100644 --- a/src/lib/app.css +++ b/src/lib/app.css @@ -74,6 +74,11 @@ main { width: 732px; } +img.emoji { + height: 1.2em; + margin: -.1em 0; +} + .throb { animation: .25s throb alternate infinite ease-in; } diff --git a/src/lib/ui/Navigation.svelte b/src/lib/ui/Navigation.svelte index c4ce6e5..26cbed5 100644 --- a/src/lib/ui/Navigation.svelte +++ b/src/lib/ui/Navigation.svelte @@ -153,7 +153,7 @@
play_sound()}>

Welcome, fediverse user!

-

Please enter your instance domain to log in.

+

Please enter your server domain to log in.

- - {#if instance_url_error} -

{instance_url_error}

+ + {#if display_error} +

{display_error}

{/if}

diff --git a/src/lib/ui/Navigation.svelte b/src/lib/ui/Navigation.svelte index 26cbed5..6d514ef 100644 --- a/src/lib/ui/Navigation.svelte +++ b/src/lib/ui/Navigation.svelte @@ -1,18 +1,17 @@
- play_sound()}> + play_sound()}>
@@ -183,7 +182,7 @@ background-color: var(--bg-800); } - .instance-header { + .server-header { width: 100%; height: 172px; display: flex; @@ -196,7 +195,7 @@ background-image: linear-gradient(to top, var(--bg-800), var(--bg-600)); } - .instance-icon { + .server-icon { height: 50%; border-radius: 8px; } diff --git a/src/lib/ui/Notification.svelte b/src/lib/ui/Notification.svelte index f16abec..ecf5b26 100644 --- a/src/lib/ui/Notification.svelte +++ b/src/lib/ui/Notification.svelte @@ -1,5 +1,5 @@ diff --git a/src/lib/ui/post/Body.svelte b/src/lib/ui/post/Body.svelte index 6bc85f7..7b06bc6 100644 --- a/src/lib/ui/post/Body.svelte +++ b/src/lib/ui/post/Body.svelte @@ -1,8 +1,6 @@ @@ -22,22 +20,22 @@ {/if} {#if !post.warning || open_warned} - {#if post.text} - {@html rich_text} + {#if post.html} + {@html post.html} {/if} - {#if post.files && post.files.length > 0} -
- {#each post.files as file} -
- {#if ["image", "gifv", "gif"].includes(file.type)} - - {file.description} + {#if post.media && post.media.length > 0} +
+ {#each post.media as media} +
+ {#if ["image", "gifv", "gif"].includes(media.type)} + + {media.description} - {:else if file.type === "video"} + {:else if media.type === "video"} {/if}
diff --git a/src/lib/ui/post/BoostContext.svelte b/src/lib/ui/post/BoostContext.svelte index 2194ef2..8e2a97d 100644 --- a/src/lib/ui/post/BoostContext.svelte +++ b/src/lib/ui/post/BoostContext.svelte @@ -1,17 +1,16 @@
🔁 - - {@html parseEmojis(post.user.rich_name)} + + {@html post.account.rich_name} boosted this post. diff --git a/src/lib/ui/post/Post.svelte b/src/lib/ui/post/Post.svelte index 15f01aa..c3f430a 100644 --- a/src/lib/ui/post/Post.svelte +++ b/src/lib/ui/post/Post.svelte @@ -1,5 +1,4 @@
diff --git a/src/lib/ui/post/PostHeader.svelte b/src/lib/ui/post/PostHeader.svelte index 93b0949..3bb59b0 100644 --- a/src/lib/ui/post/PostHeader.svelte +++ b/src/lib/ui/post/PostHeader.svelte @@ -1,6 +1,5 @@
- - + +
- {#await ready} + {#await init()}
just a moment...
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 05c2764..c13c9bd 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,13 +1,11 @@
diff --git a/src/routes/post/[id]/+page.svelte b/src/routes/post/[id]/+page.svelte index e2e27aa..50593e0 100644 --- a/src/routes/post/[id]/+page.svelte +++ b/src/routes/post/[id]/+page.svelte @@ -1,7 +1,9 @@ + +
+
+ + + +
+ +
+
+
+
+ +
+
+ + + +
+ + diff --git a/src/lib/ui/Modal.svelte b/src/lib/ui/Modal.svelte new file mode 100644 index 0000000..695dc43 --- /dev/null +++ b/src/lib/ui/Modal.svelte @@ -0,0 +1,88 @@ + + +{#if visible} +
visible = !visible}>
+
+ +
+{/if} + + \ No newline at end of file diff --git a/src/lib/ui/Navigation.svelte b/src/lib/ui/Navigation.svelte index 6d514ef..a37365a 100644 --- a/src/lib/ui/Navigation.svelte +++ b/src/lib/ui/Navigation.svelte @@ -6,6 +6,7 @@ import { goto } from '$app/navigation'; import { page } from '$app/stores'; import { get } from 'svelte/store'; + import { createEventDispatcher } from 'svelte'; import { unread_notif_count, last_read_notif_id } from '$lib/notifications.js'; import Logo from '$lib/../img/campfire-logo.svg'; @@ -26,6 +27,8 @@ const VERSION = APP_VERSION; + const dispatch = createEventDispatcher(); + function handle_btn(name) { if (!get(logged_in)) return; let route; @@ -122,12 +125,12 @@
- +
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index ff9ede3..a718d7b 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -9,8 +9,12 @@ import { get } from 'svelte/store'; import Navigation from '$lib/ui/Navigation.svelte'; + import Modal from '@cf/ui/Modal.svelte'; + import Composer from '@cf/ui/Composer.svelte'; import Widgets from '$lib/ui/Widgets.svelte'; + let show_composer = false; + async function init() { if (!get(app) || !get(app).token) { account.set(false); @@ -40,9 +44,8 @@
-
- + show_composer = true} />
@@ -59,6 +62,9 @@
+ + +
diff --git a/src/lib/ui/post/ReactionButton.svelte b/src/lib/ui/post/ReactionButton.svelte index 7e51889..c6355f8 100644 --- a/src/lib/ui/post/ReactionButton.svelte +++ b/src/lib/ui/post/ReactionButton.svelte @@ -49,6 +49,7 @@ border-radius: 8px; transition: background-color .1s, color .1s; cursor: pointer; + border: 1px solid var(--bg-700); } button.active { From 7f993ee5381e3e48f01105a97d9f4d0c4abee843 Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 14:32:23 +0100 Subject: [PATCH 07/40] added foreign reaction capabilties (chuckya) --- src/lib/client/server.js | 4 +++- src/lib/ui/post/ActionBar.svelte | 18 ------------------ src/lib/ui/post/ReactionBar.svelte | 29 ++++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/lib/client/server.js b/src/lib/client/server.js index 292ed5d..91dcd48 100644 --- a/src/lib/client/server.js +++ b/src/lib/client/server.js @@ -16,8 +16,9 @@ const server_types = { }; export const capabilities = { - MARKDOWN_CONTENT: "mdcontent", + MARKDOWN_CONTENT: "markdown_content", REACTIONS: "reactions", + FOREIGN_REACTIONS: "foreign_reactions", }; // if server is falsy, assume user has not begun the login process. @@ -118,6 +119,7 @@ function getCapabilities(type) { break; case server_types.CHUCKYA: c.push(capabilities.REACTIONS); + c.push(capabilities.FOREIGN_REACTIONS); break; case server_types.FIREFISH: c.push(capabilities.REACTIONS); diff --git a/src/lib/ui/post/ActionBar.svelte b/src/lib/ui/post/ActionBar.svelte index 096cd1d..8f3e490 100644 --- a/src/lib/ui/post/ActionBar.svelte +++ b/src/lib/ui/post/ActionBar.svelte @@ -11,7 +11,6 @@ import RepostIcon from '../../../img/icons/repost.svg'; import FavouriteIcon from '../../../img/icons/like.svg'; import FavouriteIconFill from '../../../img/icons/like_fill.svg'; - import ReactIcon from '../../../img/icons/react.svg'; import QuoteIcon from '../../../img/icons/quote.svg'; import MoreIcon from '../../../img/icons/more.svg'; @@ -45,23 +44,6 @@ post.favourite_count = data.favourites_count; if (data.reactions) post.reactions = parseReactions(data.reactions); } - - async function toggleReaction(reaction) { - if (reaction.name.includes('@')) return; - - let data; - if (reaction.me) - data = await api.unreactPost(get(server).host, get(app).token, post.id, reaction.name); - else - data = await api.reactPost(get(server).host, get(app).token, post.id, reaction.name); - if (!data) { - console.error(`Failed to favourite post ${post.id}`); - return; - } - post.favourited = data.favourited; - post.favourite_count = data.favourites_count; - if (data.reactions) post.reactions = parseReactions(data.reactions); - }
diff --git a/src/lib/ui/post/ReactionBar.svelte b/src/lib/ui/post/ReactionBar.svelte index 0e7e4aa..9e907e6 100644 --- a/src/lib/ui/post/ReactionBar.svelte +++ b/src/lib/ui/post/ReactionBar.svelte @@ -1,8 +1,35 @@
@@ -12,7 +39,7 @@ on:click={() => toggleReaction(reaction)} bind:active={reaction.me} bind:count={reaction.count} - disabled={reaction.name.includes('@')} + disabled={reaction.name.includes('@') && !$server.capabilities.includes(capabilities.FOREIGN_REACTIONS)} title={reaction.name} label=""> {#if reaction.url} From 5e44cdf73a6da065e48ef478e797d6b7ac831f0f Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 14:47:17 +0100 Subject: [PATCH 08/40] fixed logout, now using account/app/server architecture --- src/lib/ui/Navigation.svelte | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lib/ui/Navigation.svelte b/src/lib/ui/Navigation.svelte index a37365a..856c02a 100644 --- a/src/lib/ui/Navigation.svelte +++ b/src/lib/ui/Navigation.svelte @@ -1,5 +1,8 @@ From 5acb2e1667a02e2eee5f831ccc11822ef9511ade Mon Sep 17 00:00:00 2001 From: vimaexd Date: Fri, 5 Jul 2024 14:51:32 +0100 Subject: [PATCH 09/40] very basic post support + misc --- package-lock.json | 15 +++++++ src/img/icons/bookmark.svg | 4 +- src/img/icons/dm.svg | 3 ++ src/img/icons/error.svg | 15 +++++++ src/img/icons/explore.svg | 6 +-- src/img/icons/followers.svg | 13 ++++++ src/img/icons/hashtag.svg | 18 ++++---- src/img/icons/info.svg | 6 +-- src/img/icons/like.svg | 4 +- src/img/icons/like_fill.svg | 6 +-- src/img/icons/lists.svg | 11 ++++- src/img/icons/logout.svg | 8 ++-- src/img/icons/media.svg | 12 +++++ src/img/icons/mention.svg | 3 ++ src/img/icons/more.svg | 6 +-- src/img/icons/notifications.svg | 8 ++-- src/img/icons/plus.svg | 11 +++++ src/img/icons/plus_fill.svg | 11 +++++ src/img/icons/poll.svg | 10 +++++ src/img/icons/post.svg | 4 +- src/img/icons/public.svg | 12 +++++ src/img/icons/quote.svg | 5 +-- src/img/icons/react.svg | 29 ++++++------- src/img/icons/reload.svg | 16 +++++++ src/img/icons/reply.svg | 4 +- src/img/icons/repost.svg | 10 ++--- src/img/icons/search.svg | 7 ++- src/img/icons/settings.svg | 8 ++-- src/img/icons/timeline.svg | 8 ++-- src/img/icons/unlisted.svg | 4 ++ src/img/icons/warning.svg | 3 ++ src/lib/api.js | 24 +++++++++- src/lib/ui/Composer.svelte | 77 ++++++++++++++++++++++++++++----- src/lib/ui/Modal.svelte | 19 +++++--- src/lib/ui/Navigation.svelte | 2 +- src/routes/+layout.svelte | 2 +- 36 files changed, 306 insertions(+), 98 deletions(-) create mode 100644 src/img/icons/dm.svg create mode 100644 src/img/icons/error.svg create mode 100644 src/img/icons/followers.svg create mode 100644 src/img/icons/media.svg create mode 100644 src/img/icons/mention.svg create mode 100644 src/img/icons/plus.svg create mode 100644 src/img/icons/plus_fill.svg create mode 100644 src/img/icons/poll.svg create mode 100644 src/img/icons/public.svg create mode 100644 src/img/icons/reload.svg create mode 100644 src/img/icons/unlisted.svg create mode 100644 src/img/icons/warning.svg diff --git a/package-lock.json b/package-lock.json index 68c3b16..742205a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "campfire-client", "version": "0.3.0", "license": "GPL-3.0", + "dependencies": { + "typescript": "^5.5.3" + }, "devDependencies": { "@poppanator/sveltekit-svg": "^4.2.1", "@sveltejs/adapter-auto": "^3.2.2", @@ -1567,6 +1570,18 @@ "node": ">=6" } }, + "node_modules/typescript": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/vite": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/vite/-/vite-5.3.1.tgz", diff --git a/src/img/icons/bookmark.svg b/src/img/icons/bookmark.svg index b9e9b8e..70f328d 100644 --- a/src/img/icons/bookmark.svg +++ b/src/img/icons/bookmark.svg @@ -1,3 +1,3 @@ - - + + diff --git a/src/img/icons/dm.svg b/src/img/icons/dm.svg new file mode 100644 index 0000000..41b64da --- /dev/null +++ b/src/img/icons/dm.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/img/icons/error.svg b/src/img/icons/error.svg new file mode 100644 index 0000000..cdcc032 --- /dev/null +++ b/src/img/icons/error.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/img/icons/explore.svg b/src/img/icons/explore.svg index 9699f07..e2a289c 100644 --- a/src/img/icons/explore.svg +++ b/src/img/icons/explore.svg @@ -1,10 +1,10 @@ - + - + - + diff --git a/src/img/icons/followers.svg b/src/img/icons/followers.svg new file mode 100644 index 0000000..7293c31 --- /dev/null +++ b/src/img/icons/followers.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/img/icons/hashtag.svg b/src/img/icons/hashtag.svg index 5a574d7..52f7097 100644 --- a/src/img/icons/hashtag.svg +++ b/src/img/icons/hashtag.svg @@ -1,10 +1,10 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/img/icons/info.svg b/src/img/icons/info.svg index 23077aa..e9342e4 100644 --- a/src/img/icons/info.svg +++ b/src/img/icons/info.svg @@ -1,5 +1,3 @@ - - - - + + diff --git a/src/img/icons/like.svg b/src/img/icons/like.svg index a2ffd55..45682c9 100644 --- a/src/img/icons/like.svg +++ b/src/img/icons/like.svg @@ -1,3 +1,3 @@ - - + + diff --git a/src/img/icons/like_fill.svg b/src/img/icons/like_fill.svg index 6d2eb3b..09aa5b8 100644 --- a/src/img/icons/like_fill.svg +++ b/src/img/icons/like_fill.svg @@ -1,10 +1,10 @@ - + - + - + diff --git a/src/img/icons/lists.svg b/src/img/icons/lists.svg index a3e5c30..47a99bb 100644 --- a/src/img/icons/lists.svg +++ b/src/img/icons/lists.svg @@ -1,3 +1,10 @@ - - + + + + + + + + + diff --git a/src/img/icons/logout.svg b/src/img/icons/logout.svg index 1a3cf80..d97e04d 100644 --- a/src/img/icons/logout.svg +++ b/src/img/icons/logout.svg @@ -1,11 +1,11 @@ - + - - + + - + diff --git a/src/img/icons/media.svg b/src/img/icons/media.svg new file mode 100644 index 0000000..f88b45e --- /dev/null +++ b/src/img/icons/media.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/img/icons/mention.svg b/src/img/icons/mention.svg new file mode 100644 index 0000000..3895acb --- /dev/null +++ b/src/img/icons/mention.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/img/icons/more.svg b/src/img/icons/more.svg index bc531b2..ab0f996 100644 --- a/src/img/icons/more.svg +++ b/src/img/icons/more.svg @@ -1,5 +1,3 @@ - - - - + + diff --git a/src/img/icons/notifications.svg b/src/img/icons/notifications.svg index e946ca5..7e3dfa6 100644 --- a/src/img/icons/notifications.svg +++ b/src/img/icons/notifications.svg @@ -1,11 +1,11 @@ - + - - + + - + diff --git a/src/img/icons/plus.svg b/src/img/icons/plus.svg new file mode 100644 index 0000000..0bcf501 --- /dev/null +++ b/src/img/icons/plus.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/img/icons/plus_fill.svg b/src/img/icons/plus_fill.svg new file mode 100644 index 0000000..cd16e2a --- /dev/null +++ b/src/img/icons/plus_fill.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/img/icons/poll.svg b/src/img/icons/poll.svg new file mode 100644 index 0000000..f258b9d --- /dev/null +++ b/src/img/icons/poll.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/img/icons/post.svg b/src/img/icons/post.svg index 79d5536..3d4ac43 100644 --- a/src/img/icons/post.svg +++ b/src/img/icons/post.svg @@ -1,3 +1,3 @@ - - + + diff --git a/src/img/icons/public.svg b/src/img/icons/public.svg new file mode 100644 index 0000000..c321adf --- /dev/null +++ b/src/img/icons/public.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/img/icons/quote.svg b/src/img/icons/quote.svg index 98ce541..5a74811 100644 --- a/src/img/icons/quote.svg +++ b/src/img/icons/quote.svg @@ -1,4 +1,3 @@ - - - + + diff --git a/src/img/icons/react.svg b/src/img/icons/react.svg index 532213d..e7396e9 100644 --- a/src/img/icons/react.svg +++ b/src/img/icons/react.svg @@ -1,15 +1,14 @@ - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + diff --git a/src/img/icons/reload.svg b/src/img/icons/reload.svg new file mode 100644 index 0000000..4e58201 --- /dev/null +++ b/src/img/icons/reload.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/img/icons/reply.svg b/src/img/icons/reply.svg index 5462c7b..dc18cb0 100644 --- a/src/img/icons/reply.svg +++ b/src/img/icons/reply.svg @@ -1,3 +1,3 @@ - - + + diff --git a/src/img/icons/repost.svg b/src/img/icons/repost.svg index c0f950f..b679f16 100644 --- a/src/img/icons/repost.svg +++ b/src/img/icons/repost.svg @@ -1,12 +1,12 @@ - + - - - + + + - + diff --git a/src/img/icons/search.svg b/src/img/icons/search.svg index 0864af4..eecb00c 100644 --- a/src/img/icons/search.svg +++ b/src/img/icons/search.svg @@ -1,11 +1,10 @@ - + - - + - + diff --git a/src/img/icons/settings.svg b/src/img/icons/settings.svg index be2926e..bfc8697 100644 --- a/src/img/icons/settings.svg +++ b/src/img/icons/settings.svg @@ -1,11 +1,11 @@ - + - + - + - + diff --git a/src/img/icons/timeline.svg b/src/img/icons/timeline.svg index a2be615..712e88f 100644 --- a/src/img/icons/timeline.svg +++ b/src/img/icons/timeline.svg @@ -1,12 +1,10 @@ - + - - - + - + diff --git a/src/img/icons/unlisted.svg b/src/img/icons/unlisted.svg new file mode 100644 index 0000000..6b88c40 --- /dev/null +++ b/src/img/icons/unlisted.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/img/icons/warning.svg b/src/img/icons/warning.svg new file mode 100644 index 0000000..0fffc6f --- /dev/null +++ b/src/img/icons/warning.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/lib/api.js b/src/lib/api.js index 8006213..372bd49 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -197,6 +197,28 @@ export async function getPost(host, token, post_id) { return data; } +/** + * POST /api/v1/statuses + * @param {string} host - The domain of the target server. + * @param {string} token - The application token + * @param {any} post_data - The post content + */ +export async function createPost(host, token, post_data) { + let formdata = new FormData(); + for (const key in post_data) { + formdata.append(key, post_data[key]); + } + + let url = `https://${host}/api/v1/statuses`; + const data = await fetch(url, { + method: 'POST', + headers: { "Authorization": `Bearer ${token}` }, + body: formdata + }) + + return await data.json() +} + /** * GET /api/v1/statuses/{post_id}/context. * @param {string} host - The domain of the target server. @@ -336,4 +358,4 @@ export async function getUser(host, token, user_id) { }).then(res => res.json()); return data; -} +} \ No newline at end of file diff --git a/src/lib/ui/Composer.svelte b/src/lib/ui/Composer.svelte index c8f474c..3be2a25 100644 --- a/src/lib/ui/Composer.svelte +++ b/src/lib/ui/Composer.svelte @@ -1,7 +1,42 @@ -
@@ -19,25 +54,35 @@
- - + {#if show_cw} + + {/if} + -
- + show_composer = false }/>
From 0d39ddd3d2c464e0f9b8ff9553dfb0bf728e8640 Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 14:56:46 +0100 Subject: [PATCH 10/40] do not parse post emojis if post.emoji is undefined --- src/lib/post.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/post.js b/src/lib/post.js index e8700f5..66ccf34 100644 --- a/src/lib/post.js +++ b/src/lib/post.js @@ -44,9 +44,11 @@ export async function parsePost(data, ancestor_count) { post.visibility = data.visibility; post.emojis = []; - data.emojis.forEach(emoji => { - post.emojis[emoji.shortcode] = parseEmoji(emoji.shortcode, emoji.url); - }); + if (post.emojis) { + data.emojis.forEach(emoji => { + post.emojis[emoji.shortcode] = parseEmoji(emoji.shortcode, emoji.url); + }); + } if (data.reactions) post.reactions = parseReactions(data.reactions); From d1d3b16cbf9fce59532da652e6c3e6bbc9461000 Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 15:03:30 +0100 Subject: [PATCH 11/40] fixed error when retrieving private replies in timeline --- src/lib/api.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/api.js b/src/lib/api.js index 372bd49..930b784 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -192,7 +192,9 @@ export async function getPost(host, token, post_id) { const data = await fetch(url, { method: 'GET', headers: { "Authorization": token ? `Bearer ${token}` : null } - }).then(res => res.json()); + }).then(res => res.json()) + + if (!data || data.error) return false; return data; } @@ -358,4 +360,4 @@ export async function getUser(host, token, user_id) { }).then(res => res.json()); return data; -} \ No newline at end of file +} From b064a90753a0af805d8922ef7a868c6aa3d87ccb Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 15:10:25 +0100 Subject: [PATCH 12/40] prefer content warnings in notifications --- src/lib/ui/Notification.svelte | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/lib/ui/Notification.svelte b/src/lib/ui/Notification.svelte index ecf5b26..12fb622 100644 --- a/src/lib/ui/Notification.svelte +++ b/src/lib/ui/Notification.svelte @@ -57,12 +57,12 @@ goto(`/post/${data.status.id}`); } - let aria_label = function () { - if (accounts.length == 1) + let aria_label = function (data) { + if (data.accounts.length == 1) return activity_text.replace("%1", account.username) + ' ' + new Date(data.created_at); else - return activity_text.replace("%1", `${account.username} and ${accounts.length - 1} others`) + ' ' + new Date(data.created_at); - } + return activity_text.replace("%1", `${account.username} and ${data.accounts.length - 1} others`) + ' ' + new Date(data.created_at); + }(data);
{#if data.status}
- {@html data.status.html} + {#if data.status.warning} +
+ {data.status.warning} +
+ {:else} + {@html data.status.html} + {/if}
{#if data.type === "mention"} {#if data.status.reactions} @@ -247,4 +253,21 @@ margin-right: 4px; border-radius: 4px; } + + .notif-content .warning { + width: 100%; + margin-bottom: 10px; + padding: 4px 8px; + --warn-bg: color-mix(in srgb, var(--bg-700), var(--accent) 1%); + background: repeating-linear-gradient(-45deg, transparent, transparent 10px, var(--warn-bg) 10px, var(--warn-bg) 20px); + font-family: inherit; + font-size: inherit; + color: inherit; + text-align: left; + border: none; + border-radius: 8px; + cursor: pointer; + outline-color: var(--warn-bg); + transition: outline .05s, box-shadow .05s; + } From 3a04ef7f810ba66331c3b115ba23d955ee9b1a03 Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 15:12:53 +0100 Subject: [PATCH 13/40] fixed alignment of notif content warning --- src/lib/ui/Notification.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/ui/Notification.svelte b/src/lib/ui/Notification.svelte index 12fb622..0e49e0a 100644 --- a/src/lib/ui/Notification.svelte +++ b/src/lib/ui/Notification.svelte @@ -255,7 +255,7 @@ } .notif-content .warning { - width: 100%; + width: calc(100% - 16px); margin-bottom: 10px; padding: 4px 8px; --warn-bg: color-mix(in srgb, var(--bg-700), var(--accent) 1%); From 5ea28dc078c45ce3cf1e1ddaf616bec035854c56 Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 15:31:35 +0100 Subject: [PATCH 14/40] add edit post api handler (#6) --- src/lib/api.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lib/api.js b/src/lib/api.js index 930b784..733e172 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -221,6 +221,29 @@ export async function createPost(host, token, post_data) { return await data.json() } +/** + * PUT /api/v1/statuses/{post_id} + * @param {string} host - The domain of the target server. + * @param {string} token - The application token + * @param {any} post_id - The ID of the post to edit. + * @param {any} post_data - The post content + */ +export async function editPost(host, token, post_id, post_data) { + let formdata = new FormData(); + for (const key in post_data) { + formdata.append(key, post_data[key]); + } + + let url = `https://${host}/api/v1/statuses/${post_id}`; + const data = await fetch(url, { + method: 'POST', + headers: { "Authorization": `Bearer ${token}` }, + body: formdata + }) + + return await data.json() +} + /** * GET /api/v1/statuses/{post_id}/context. * @param {string} host - The domain of the target server. From 0d9c7b1761785e3aedd78514b4bcfca1931f6484 Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 15:34:16 +0100 Subject: [PATCH 15/40] add delete post api handler (#7) --- src/lib/api.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib/api.js b/src/lib/api.js index 733e172..a13b6d5 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -244,6 +244,22 @@ export async function editPost(host, token, post_id, post_data) { return await data.json() } +/** + * DELETE /api/v1/statuses/{post_id} + * @param {string} host - The domain of the target server. + * @param {string} token - The application token + * @param {any} post_id - The ID of the post to delete. + */ +export async function editPost(host, token, post_id) { + let url = `https://${host}/api/v1/statuses/${post_id}`; + const data = await fetch(url, { + method: 'POST', + headers: { "Authorization": `Bearer ${token}` }, + }) + + return await data.json() +} + /** * GET /api/v1/statuses/{post_id}/context. * @param {string} host - The domain of the target server. From 048d158209e8387173899e80ea1118afcac3c1c4 Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 15:41:11 +0100 Subject: [PATCH 16/40] add stream health api endpoint (#24, #19) --- src/lib/api.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/api.js b/src/lib/api.js index a13b6d5..c9a70b6 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -131,6 +131,19 @@ export async function verifyCredentials(host, token) { return data; } +/** + * GET /api/v1/streaming/health + * Checks if the server's streaming service is alive + */ +export async function getStreamingHealth(host) { + let url = `https://${host}/api/v1/streaming/health`; + const res = await fetch(url, { + method: 'GET' + }); + + return res.ok; +} + /** * GET /api/v1/notifications * @param {string} host - The domain of the target server. @@ -250,7 +263,7 @@ export async function editPost(host, token, post_id, post_data) { * @param {string} token - The application token * @param {any} post_id - The ID of the post to delete. */ -export async function editPost(host, token, post_id) { +export async function deletePost(host, token, post_id) { let url = `https://${host}/api/v1/statuses/${post_id}`; const data = await fetch(url, { method: 'POST', From 08cd43bd7d4225434af40b03d48f70c888b33d7a Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 15:49:20 +0100 Subject: [PATCH 17/40] fixed notifications only getting older notifs instead of newer ones --- src/lib/api.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/api.js b/src/lib/api.js index c9a70b6..9cbf898 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -148,15 +148,15 @@ export async function getStreamingHealth(host) { * GET /api/v1/notifications * @param {string} host - The domain of the target server. * @param {string} token - The application token. - * @param {string} max_id - If provided, only shows notifications after this ID. + * @param {string} min_id - If provided, only shows notifications after this ID. * @param {string} limit - The maximum number of notifications to retrieve (default 40). * @param {string} types - A list of notification types to filter to. */ -export async function getNotifications(host, token, max_id, limit, types) { +export async function getNotifications(host, token, min_id, limit, types) { let url = `https://${host}/api/v1/notifications`; let params = new URLSearchParams(); - if (max_id) params.append("max_id", max_id); + if (min_id) params.append("min_id", min_id); if (limit) params.append("limit", limit); if (types) params.append("types", types.join(',')); const params_string = params.toString(); From 1773c936173ea73899157583c2b1cb69d7c67702 Mon Sep 17 00:00:00 2001 From: ari melody Date: Sun, 7 Jul 2024 12:22:29 +0100 Subject: [PATCH 18/40] random placeholder in composer + some cleanup --- src/lib/ui/Composer.svelte | 13 ++++++-- src/lib/ui/Feed.svelte | 62 ------------------------------------ src/lib/ui/Navigation.svelte | 3 +- src/lib/ui/post/Post.svelte | 9 ------ src/routes/+page.svelte | 55 +++++++++++++++++++++----------- 5 files changed, 49 insertions(+), 93 deletions(-) delete mode 100644 src/lib/ui/Feed.svelte diff --git a/src/lib/ui/Composer.svelte b/src/lib/ui/Composer.svelte index 3be2a25..8cddfb7 100644 --- a/src/lib/ui/Composer.svelte +++ b/src/lib/ui/Composer.svelte @@ -19,6 +19,15 @@ let content = ""; // let media_ids = []; let show_cw = false; + const placeholders = [ + "What's cooking, $1?", + "Speak your mind!", + "Federate something...", + "I sure love posting!", + "Another day, another $1 post!", + ]; + let placeholder = placeholders[Math.floor(placeholders.length * Math.random())] + .replaceAll("$1", $account.username); const dispatch = createEventDispatcher(); @@ -34,7 +43,7 @@ let new_post = await api.createPost($server.host, $app.token, postdata); let new_post_parsed = await parsePost(new_post); - timeline.update(current => [new_post_parsed ,...current]) + timeline.update(current => [new_post_parsed, ...current]); dispatch("compose_finished") } @@ -63,7 +72,7 @@ {#if show_cw} {/if} - +