about summary refs log tree commit diff
path: root/src/state/queries/messages/list-converations.ts
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-05-08 15:48:05 +0100
committerGitHub <noreply@github.com>2024-05-08 15:48:05 +0100
commit38198fdf7f858a819891e39d418b74cc6b94d756 (patch)
treecbc23d418dff3ab8ed1ce76b669b2dc2e12447a0 /src/state/queries/messages/list-converations.ts
parent56f713077f6e663ac77df20f1d67b55fd1da153a (diff)
downloadvoidsky-38198fdf7f858a819891e39d418b74cc6b94d756.tar.zst
[🐴] Mark as read in convo menu (#3913)
* add mark as read option

* optimistic update + link up menu

* rm messageid
Diffstat (limited to 'src/state/queries/messages/list-converations.ts')
-rw-r--r--src/state/queries/messages/list-converations.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/state/queries/messages/list-converations.ts b/src/state/queries/messages/list-converations.ts
index e66551ceb..32107c0cd 100644
--- a/src/state/queries/messages/list-converations.ts
+++ b/src/state/queries/messages/list-converations.ts
@@ -111,6 +111,23 @@ export function useOnCreateConvo() {
   }, [queryClient])
 }
 
+export function useOnMarkAsRead() {
+  const queryClient = useQueryClient()
+
+  return useCallback(
+    (chatId: string) => {
+      queryClient.setQueryData(RQKEY, (old: ConvoListQueryData) => {
+        return optimisticUpdate(chatId, old, convo => ({
+          ...convo,
+          unreadCount: 0,
+        }))
+      })
+      queryClient.invalidateQueries({queryKey: RQKEY})
+    },
+    [queryClient],
+  )
+}
+
 function optimisticUpdate(
   chatId: string,
   old: ConvoListQueryData,