about summary refs log tree commit diff
path: root/src/state/messages
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-05-08 03:23:09 +0100
committerGitHub <noreply@github.com>2024-05-07 21:23:09 -0500
commit4fe5a869c32c696862308cb8ff4537f34f43f06a (patch)
treedcaa40e286d18ffb45f591c911d9464145525010 /src/state/messages
parent0c41b3188a4f4ffc701b980d98e3e7560ee2bc7b (diff)
downloadvoidsky-4fe5a869c32c696862308cb8ff4537f34f43f06a.tar.zst
[🐴] Unread messages badge (#3901)
* add badge

* move stringify logic to hook

* add mutation hooks

* optimistic mark convo as read

* don't count muted chats

* Integrate new context

* Integrate mark unread mutation

* Remove unused edit

---------

Co-authored-by: Eric Bailey <git@esb.lol>
Diffstat (limited to 'src/state/messages')
-rw-r--r--src/state/messages/index.tsx10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/state/messages/index.tsx b/src/state/messages/index.tsx
index 7145e5d88..60538615a 100644
--- a/src/state/messages/index.tsx
+++ b/src/state/messages/index.tsx
@@ -6,6 +6,7 @@ import {useFocusEffect, useIsFocused} from '@react-navigation/native'
 import {Convo, ConvoParams, ConvoState} from '#/state/messages/convo'
 import {CurrentConvoIdProvider} from '#/state/messages/current-convo-id'
 import {MessagesEventBusProvider} from '#/state/messages/events'
+import {useMarkAsReadMutation} from '#/state/queries/messages/conversation'
 import {useAgent} from '#/state/session'
 import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage'
 
@@ -37,15 +38,18 @@ export function ChatProvider({
       }),
   )
   const service = useSyncExternalStore(convo.subscribe, convo.getSnapshot)
+  const {mutate: markAsRead} = useMarkAsReadMutation()
 
   useFocusEffect(
     React.useCallback(() => {
       convo.resume()
+      markAsRead({convoId})
 
       return () => {
         convo.background()
+        markAsRead({convoId})
       }
-    }, [convo]),
+    }, [convo, convoId, markAsRead]),
   )
 
   React.useEffect(() => {
@@ -56,6 +60,8 @@ export function ChatProvider({
         } else {
           convo.background()
         }
+
+        markAsRead({convoId})
       }
     }
 
@@ -64,7 +70,7 @@ export function ChatProvider({
     return () => {
       sub.remove()
     }
-  }, [convo, isScreenFocused])
+  }, [convoId, convo, isScreenFocused, markAsRead])
 
   return <ChatContext.Provider value={service}>{children}</ChatContext.Provider>
 }