diff --git a/apps/mobile/src/modules/context-menu/entry.tsx b/apps/mobile/src/modules/context-menu/entry.tsx index 0388859d2..200548df7 100644 --- a/apps/mobile/src/modules/context-menu/entry.tsx +++ b/apps/mobile/src/modules/context-menu/entry.tsx @@ -61,13 +61,17 @@ export const EntryItemContextMenu = ({ id, children }: PropsWithChildren<{ id: s { - unreadSyncService.markEntryAsRead(id) + entry.read + ? unreadSyncService.markEntryAsUnread(id) + : unreadSyncService.markEntryAsRead(id) }} > - {t("operation.mark_as_read")} + + {entry.read ? t("operation.mark_as_unread") : t("operation.mark_as_read")} + diff --git a/apps/mobile/src/store/unread/store.ts b/apps/mobile/src/store/unread/store.ts index 34127aa86..0ff3e93e0 100644 --- a/apps/mobile/src/store/unread/store.ts +++ b/apps/mobile/src/store/unread/store.ts @@ -97,6 +97,44 @@ class UnreadSyncService { await tx.run() } + + async markEntryAsUnread(entryId: string) { + const entry = getEntry(entryId) + if (!entry || !entry?.read) return + + const feedId = entry?.feedId + + const tx = createTransaction() + tx.store(() => { + entryActions.markEntryReadStatusInSession({ entryIds: [entryId], read: false }) + + if (feedId) { + unreadActions.addUnread(feedId) + } + }) + tx.rollback(() => { + entryActions.markEntryReadStatusInSession({ entryIds: [entryId], read: true }) + + if (feedId) { + unreadActions.removeUnread(feedId) + } + }) + + tx.request(() => { + apiClient.reads.$delete({ + json: { entryId }, + }) + }) + + tx.persist(() => { + return EntryService.patchMany({ + entry: { read: false }, + entryIds: [entryId], + }) + }) + + await tx.run() + } } class UnreadActions { diff --git a/locales/mobile/default/en.json b/locales/mobile/default/en.json index 2bf8cf15f..854239fa3 100644 --- a/locales/mobile/default/en.json +++ b/locales/mobile/default/en.json @@ -9,6 +9,7 @@ "operation.mark_all_as_read_which": "Mark {{which}} as read", "operation.mark_all_as_read_which_above": "above", "operation.mark_as_read": "Mark as Read", + "operation.mark_as_unread": "Mark as Unread", "operation.open_link": "Open Link", "operation.rename_category": "Rename Category", "operation.share": "Share",