diff options
Diffstat (limited to 'src/state/queries')
-rw-r--r-- | src/state/queries/messages/const.ts | 3 | ||||
-rw-r--r-- | src/state/queries/messages/conversation.ts | 25 | ||||
-rw-r--r-- | src/state/queries/messages/get-convo-for-members.ts | 14 | ||||
-rw-r--r-- | src/state/queries/messages/leave-conversation.ts | 18 | ||||
-rw-r--r-- | src/state/queries/messages/list-converations.ts | 18 | ||||
-rw-r--r-- | src/state/queries/messages/mute-conversation.ts | 16 | ||||
-rw-r--r-- | src/state/queries/messages/temp-headers.ts | 11 |
7 files changed, 38 insertions, 67 deletions
diff --git a/src/state/queries/messages/const.ts b/src/state/queries/messages/const.ts new file mode 100644 index 000000000..98916b737 --- /dev/null +++ b/src/state/queries/messages/const.ts @@ -0,0 +1,3 @@ +export const DM_SERVICE_HEADERS = { + 'atproto-proxy': 'did:web:dms.divy.zone#bsky_chat', +} diff --git a/src/state/queries/messages/conversation.ts b/src/state/queries/messages/conversation.ts index e420ba736..bd5b746f1 100644 --- a/src/state/queries/messages/conversation.ts +++ b/src/state/queries/messages/conversation.ts @@ -1,26 +1,23 @@ -import {BskyAgent} from '@atproto-labs/api' -import {ConvoView} from '@atproto-labs/api/dist/client/types/chat/bsky/convo/defs' +import {ChatBskyConvoDefs} from '@atproto/api' import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' +import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' import {useOnMarkAsRead} from '#/state/queries/messages/list-converations' -import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage' +import {useAgent} from '#/state/session' import {RQKEY as LIST_CONVOS_KEY} from './list-converations' -import {useHeaders} from './temp-headers' const RQKEY_ROOT = 'convo' export const RQKEY = (convoId: string) => [RQKEY_ROOT, convoId] -export function useConvoQuery(convo: ConvoView) { - const headers = useHeaders() - const {serviceUrl} = useDmServiceUrlStorage() +export function useConvoQuery(convo: ChatBskyConvoDefs.ConvoView) { + const {getAgent} = useAgent() return useQuery({ queryKey: RQKEY(convo.id), queryFn: async () => { - const agent = new BskyAgent({service: serviceUrl}) - const {data} = await agent.api.chat.bsky.convo.getConvo( + const {data} = await getAgent().api.chat.bsky.convo.getConvo( {convoId: convo.id}, - {headers}, + {headers: DM_SERVICE_HEADERS}, ) return data.convo }, @@ -29,10 +26,9 @@ export function useConvoQuery(convo: ConvoView) { } export function useMarkAsReadMutation() { - const headers = useHeaders() - const {serviceUrl} = useDmServiceUrlStorage() const optimisticUpdate = useOnMarkAsRead() const queryClient = useQueryClient() + const {getAgent} = useAgent() return useMutation({ mutationFn: async ({ @@ -44,15 +40,14 @@ export function useMarkAsReadMutation() { }) => { if (!convoId) throw new Error('No convoId provided') - const agent = new BskyAgent({service: serviceUrl}) - await agent.api.chat.bsky.convo.updateRead( + await getAgent().api.chat.bsky.convo.updateRead( { convoId, messageId, }, { encoding: 'application/json', - headers, + headers: DM_SERVICE_HEADERS, }, ) }, diff --git a/src/state/queries/messages/get-convo-for-members.ts b/src/state/queries/messages/get-convo-for-members.ts index 0a657c07e..083146b83 100644 --- a/src/state/queries/messages/get-convo-for-members.ts +++ b/src/state/queries/messages/get-convo-for-members.ts @@ -1,10 +1,10 @@ -import {BskyAgent, ChatBskyConvoGetConvoForMembers} from '@atproto-labs/api' +import {ChatBskyConvoGetConvoForMembers} from '@atproto/api' import {useMutation, useQueryClient} from '@tanstack/react-query' import {logger} from '#/logger' -import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage' +import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' +import {useAgent} from '#/state/session' import {RQKEY as CONVO_KEY} from './conversation' -import {useHeaders} from './temp-headers' export function useGetConvoForMembers({ onSuccess, @@ -14,15 +14,13 @@ export function useGetConvoForMembers({ onError?: (error: Error) => void }) { const queryClient = useQueryClient() - const headers = useHeaders() - const {serviceUrl} = useDmServiceUrlStorage() + const {getAgent} = useAgent() return useMutation({ mutationFn: async (members: string[]) => { - const agent = new BskyAgent({service: serviceUrl}) - const {data} = await agent.api.chat.bsky.convo.getConvoForMembers( + const {data} = await getAgent().api.chat.bsky.convo.getConvoForMembers( {members: members}, - {headers}, + {headers: DM_SERVICE_HEADERS}, ) return data diff --git a/src/state/queries/messages/leave-conversation.ts b/src/state/queries/messages/leave-conversation.ts index 5d5c64c5b..d7d47b274 100644 --- a/src/state/queries/messages/leave-conversation.ts +++ b/src/state/queries/messages/leave-conversation.ts @@ -1,14 +1,10 @@ -import { - BskyAgent, - ChatBskyConvoLeaveConvo, - ChatBskyConvoListConvos, -} from '@atproto-labs/api' +import {ChatBskyConvoLeaveConvo, ChatBskyConvoListConvos} from '@atproto/api' import {useMutation, useQueryClient} from '@tanstack/react-query' import {logger} from '#/logger' -import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage' +import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' +import {useAgent} from '#/state/session' import {RQKEY as CONVO_LIST_KEY} from './list-converations' -import {useHeaders} from './temp-headers' export function useLeaveConvo( convoId: string | undefined, @@ -21,17 +17,15 @@ export function useLeaveConvo( }, ) { const queryClient = useQueryClient() - const headers = useHeaders() - const {serviceUrl} = useDmServiceUrlStorage() + const {getAgent} = useAgent() return useMutation({ mutationFn: async () => { if (!convoId) throw new Error('No convoId provided') - const agent = new BskyAgent({service: serviceUrl}) - const {data} = await agent.api.chat.bsky.convo.leaveConvo( + const {data} = await getAgent().api.chat.bsky.convo.leaveConvo( {convoId}, - {headers, encoding: 'application/json'}, + {headers: DM_SERVICE_HEADERS, encoding: 'application/json'}, ) return data diff --git a/src/state/queries/messages/list-converations.ts b/src/state/queries/messages/list-converations.ts index 936dd3a4a..368962417 100644 --- a/src/state/queries/messages/list-converations.ts +++ b/src/state/queries/messages/list-converations.ts @@ -1,29 +1,23 @@ import {useCallback, useMemo} from 'react' -import { - BskyAgent, - ChatBskyConvoDefs, - ChatBskyConvoListConvos, -} from '@atproto-labs/api' +import {ChatBskyConvoDefs, ChatBskyConvoListConvos} from '@atproto/api' import {useInfiniteQuery, useQueryClient} from '@tanstack/react-query' import {useCurrentConvoId} from '#/state/messages/current-convo-id' -import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage' -import {useHeaders} from './temp-headers' +import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' +import {useAgent} from '#/state/session' export const RQKEY = ['convo-list'] type RQPageParam = string | undefined export function useListConvos({refetchInterval}: {refetchInterval: number}) { - const headers = useHeaders() - const {serviceUrl} = useDmServiceUrlStorage() + const {getAgent} = useAgent() return useInfiniteQuery({ queryKey: RQKEY, queryFn: async ({pageParam}) => { - const agent = new BskyAgent({service: serviceUrl}) - const {data} = await agent.api.chat.bsky.convo.listConvos( + const {data} = await getAgent().api.chat.bsky.convo.listConvos( {cursor: pageParam}, - {headers}, + {headers: DM_SERVICE_HEADERS}, ) return data diff --git a/src/state/queries/messages/mute-conversation.ts b/src/state/queries/messages/mute-conversation.ts index f30612c73..fa760e00d 100644 --- a/src/state/queries/messages/mute-conversation.ts +++ b/src/state/queries/messages/mute-conversation.ts @@ -1,15 +1,14 @@ import { - BskyAgent, ChatBskyConvoDefs, ChatBskyConvoListConvos, ChatBskyConvoMuteConvo, -} from '@atproto-labs/api' +} from '@atproto/api' import {InfiniteData, useMutation, useQueryClient} from '@tanstack/react-query' -import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage' +import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' +import {useAgent} from '#/state/session' import {RQKEY as CONVO_KEY} from './conversation' import {RQKEY as CONVO_LIST_KEY} from './list-converations' -import {useHeaders} from './temp-headers' export function useMuteConvo( convoId: string | undefined, @@ -22,24 +21,23 @@ export function useMuteConvo( }, ) { const queryClient = useQueryClient() - const headers = useHeaders() - const {serviceUrl} = useDmServiceUrlStorage() + const {getAgent} = useAgent() return useMutation({ mutationFn: async ({mute}: {mute: boolean}) => { if (!convoId) throw new Error('No convoId provided') - const agent = new BskyAgent({service: serviceUrl}) + const agent = getAgent() if (mute) { const {data} = await agent.api.chat.bsky.convo.muteConvo( {convoId}, - {headers, encoding: 'application/json'}, + {headers: DM_SERVICE_HEADERS, encoding: 'application/json'}, ) return data } else { const {data} = await agent.api.chat.bsky.convo.unmuteConvo( {convoId}, - {headers, encoding: 'application/json'}, + {headers: DM_SERVICE_HEADERS, encoding: 'application/json'}, ) return data } diff --git a/src/state/queries/messages/temp-headers.ts b/src/state/queries/messages/temp-headers.ts deleted file mode 100644 index 9e46e8a61..000000000 --- a/src/state/queries/messages/temp-headers.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {useSession} from '#/state/session' - -// toy auth -export const useHeaders = () => { - const {currentAccount} = useSession() - return { - get Authorization() { - return currentAccount!.did - }, - } -} |