[🐴] 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>
This commit is contained in:
Samuel Newman
2024-05-08 03:23:09 +01:00
committed by GitHub
parent 0c41b3188a
commit 4fe5a869c3
5 changed files with 162 additions and 8 deletions
+35 -1
View File
@@ -1,6 +1,7 @@
import {BskyAgent} from '@atproto-labs/api'
import {useQuery} from '@tanstack/react-query'
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
import {RQKEY as ListConvosQueryKey} from '#/state/queries/messages/list-converations'
import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage'
import {useHeaders} from './temp-headers'
@@ -23,3 +24,36 @@ export function useConvoQuery(convoId: string) {
},
})
}
export function useMarkAsReadMutation() {
const headers = useHeaders()
const {serviceUrl} = useDmServiceUrlStorage()
const queryClient = useQueryClient()
return useMutation({
mutationFn: async ({
convoId,
messageId,
}: {
convoId: string
messageId?: string
}) => {
const agent = new BskyAgent({service: serviceUrl})
await agent.api.chat.bsky.convo.updateRead(
{
convoId,
messageId,
},
{
encoding: 'application/json',
headers,
},
)
},
onSuccess() {
queryClient.invalidateQueries({
queryKey: ListConvosQueryKey,
})
},
})
}