diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-05-08 03:23:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-07 21:23:09 -0500 |
commit | 4fe5a869c32c696862308cb8ff4537f34f43f06a (patch) | |
tree | dcaa40e286d18ffb45f591c911d9464145525010 /src/state/queries/messages/conversation.ts | |
parent | 0c41b3188a4f4ffc701b980d98e3e7560ee2bc7b (diff) | |
download | voidsky-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/queries/messages/conversation.ts')
-rw-r--r-- | src/state/queries/messages/conversation.ts | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/state/queries/messages/conversation.ts b/src/state/queries/messages/conversation.ts index 9456861d2..c322e0c62 100644 --- a/src/state/queries/messages/conversation.ts +++ b/src/state/queries/messages/conversation.ts @@ -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, + }) + }, + }) +} |