From 79221e2e53774114c2ca6381f6b7c7103341798c Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Sat, 19 Aug 2023 14:13:30 -0700 Subject: [PATCH] feat: add ability to mark individual posts as read, close #114 --- package.json | 2 +- .../components/lemmy/post/PostActions.svelte | 14 ++++++++++++-- src/lib/lemmy/contentview.ts | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 103aa55a..309a59a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "photon-lemmy", - "version": "0.9.10", + "version": "0.9.11", "private": true, "scripts": { "dev": "vite dev", diff --git a/src/lib/components/lemmy/post/PostActions.svelte b/src/lib/components/lemmy/post/PostActions.svelte index 30735d8f..e77cdb6d 100644 --- a/src/lib/components/lemmy/post/PostActions.svelte +++ b/src/lib/components/lemmy/post/PostActions.svelte @@ -7,6 +7,8 @@ BookmarkSlash, ChatBubbleOvalLeftEllipsis, EllipsisHorizontal, + Eye, + EyeSlash, Flag, Icon, Newspaper, @@ -31,7 +33,7 @@ import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte' import { profile } from '$lib/auth.js' import Spinner from '$lib/components/ui/loader/Spinner.svelte' - import { deleteItem, save } from '$lib/lemmy/contentview.js' + import { deleteItem, markAsRead, save } from '$lib/lemmy/contentview.js' export let post: PostView @@ -149,7 +151,15 @@ Edit - {/if} + {/if} { + if ($profile?.jwt) + post.read = await markAsRead(post.post, !post.read, $profile.jwt) + }} + > + + Mark as {post.read ? 'Unread' : 'Read'} + navigator.clipboard.writeText( diff --git a/src/lib/lemmy/contentview.ts b/src/lib/lemmy/contentview.ts index 447b67ab..2090983d 100644 --- a/src/lib/lemmy/contentview.ts +++ b/src/lib/lemmy/contentview.ts @@ -140,3 +140,22 @@ export async function vote( } return 0 } + +export async function markAsRead( + item: ContentView | Submission, + read: boolean, + jwt: string +): Promise { + if (isSubmission(item)) item = contentItem(item) + + if (item.type == 'post') { + return ( + await getClient().markPostAsRead({ + auth: jwt, + post_id: item.id, + read: read, + }) + ).post_view.read + } + return false +}