diff options
author | Eric Bailey <git@esb.lol> | 2024-05-14 09:22:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-14 09:22:09 -0500 |
commit | 9173be686c1df9adc6cbb9cc2175f8909a868c35 (patch) | |
tree | 25ea67a686969a086249769a1a3a445cd819a9ff | |
parent | 107760d551dee695f76409337048cd8c7917b784 (diff) | |
download | voidsky-9173be686c1df9adc6cbb9cc2175f8909a868c35.tar.zst |
[🐴] Swap in new package, update usages (#3992)
* Swap in new package, update usages * Remove uneccessary patch * Override type in safe place
22 files changed, 79 insertions, 173 deletions
diff --git a/package.json b/package.json index 13ffc35c8..0a52aa97b 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,7 @@ "open-analyzer": "EXPO_PUBLIC_OPEN_ANALYZER=1 yarn build-web" }, "dependencies": { - "@atproto-labs/api": "^0.12.8-clipclops.0", - "@atproto/api": "^0.12.9", + "@atproto/api": "^0.12.10", "@bam.tech/react-native-image-resizer": "^3.0.4", "@braintree/sanitize-url": "^6.0.2", "@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet", diff --git a/src/components/dms/ActionsWrapper.tsx b/src/components/dms/ActionsWrapper.tsx index 5c34ef9ba..9c58b6214 100644 --- a/src/components/dms/ActionsWrapper.tsx +++ b/src/components/dms/ActionsWrapper.tsx @@ -7,7 +7,7 @@ import Animated, { useSharedValue, withTiming, } from 'react-native-reanimated' -import {ChatBskyConvoDefs} from '@atproto-labs/api' +import {ChatBskyConvoDefs} from '@atproto/api' import {HITSLOP_10} from 'lib/constants' import {useHaptics} from 'lib/haptics' diff --git a/src/components/dms/ActionsWrapper.web.tsx b/src/components/dms/ActionsWrapper.web.tsx index 7725ca3b7..29cc89dd1 100644 --- a/src/components/dms/ActionsWrapper.web.tsx +++ b/src/components/dms/ActionsWrapper.web.tsx @@ -1,6 +1,6 @@ import React from 'react' import {StyleSheet, View} from 'react-native' -import {ChatBskyConvoDefs} from '@atproto-labs/api' +import {ChatBskyConvoDefs} from '@atproto/api' import {atoms as a} from '#/alf' import {MessageMenu} from '#/components/dms/MessageMenu' diff --git a/src/components/dms/ConvoMenu.tsx b/src/components/dms/ConvoMenu.tsx index 68d815074..0a1d3f01c 100644 --- a/src/components/dms/ConvoMenu.tsx +++ b/src/components/dms/ConvoMenu.tsx @@ -1,8 +1,6 @@ import React, {useCallback} from 'react' import {Keyboard, Pressable, View} from 'react-native' -import {AppBskyActorDefs} from '@atproto/api' -import {ChatBskyConvoDefs} from '@atproto-labs/api' -import {ConvoView} from '@atproto-labs/api/dist/client/types/chat/bsky/convo/defs' +import {AppBskyActorDefs, ChatBskyConvoDefs} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useNavigation} from '@react-navigation/native' @@ -37,7 +35,7 @@ let ConvoMenu = ({ hideTrigger, triggerOpacity, }: { - convo: ConvoView + convo: ChatBskyConvoDefs.ConvoView profile: AppBskyActorDefs.ProfileViewBasic onUpdateConvo?: (convo: ChatBskyConvoDefs.ConvoView) => void control?: Menu.MenuControlProps diff --git a/src/components/dms/MessageItem.tsx b/src/components/dms/MessageItem.tsx index e162e40ee..f8ab85188 100644 --- a/src/components/dms/MessageItem.tsx +++ b/src/components/dms/MessageItem.tsx @@ -1,7 +1,6 @@ import React, {useCallback, useMemo, useRef} from 'react' import {LayoutAnimation, StyleProp, TextStyle, View} from 'react-native' -import {RichText as RichTextAPI} from '@atproto/api' -import {ChatBskyConvoDefs} from '@atproto-labs/api' +import {ChatBskyConvoDefs, RichText as RichTextAPI} from '@atproto/api' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' diff --git a/src/components/dms/MessageMenu.tsx b/src/components/dms/MessageMenu.tsx index c6abd5110..3349b2ff8 100644 --- a/src/components/dms/MessageMenu.tsx +++ b/src/components/dms/MessageMenu.tsx @@ -1,8 +1,7 @@ import React from 'react' import {LayoutAnimation, Pressable, View} from 'react-native' import * as Clipboard from 'expo-clipboard' -import {RichText} from '@atproto/api' -import {ChatBskyConvoDefs} from '@atproto-labs/api' +import {ChatBskyConvoDefs, RichText} from '@atproto/api' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' diff --git a/src/components/dms/MessageReportDialog.tsx b/src/components/dms/MessageReportDialog.tsx index eedb12440..6071312e9 100644 --- a/src/components/dms/MessageReportDialog.tsx +++ b/src/components/dms/MessageReportDialog.tsx @@ -1,10 +1,10 @@ import React, {memo, useMemo, useState} from 'react' import {View} from 'react-native' -import {RichText as RichTextAPI} from '@atproto/api' import { ChatBskyConvoDefs, ComAtprotoModerationCreateReport, -} from '@atproto-labs/api' + RichText as RichTextAPI, +} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useMutation} from '@tanstack/react-query' diff --git a/src/screens/Messages/List/index.tsx b/src/screens/Messages/List/index.tsx index 55d65a888..b9ce8f251 100644 --- a/src/screens/Messages/List/index.tsx +++ b/src/screens/Messages/List/index.tsx @@ -1,6 +1,6 @@ import React, {useCallback, useMemo, useState} from 'react' import {View} from 'react-native' -import {ChatBskyConvoDefs} from '@atproto-labs/api' +import {ChatBskyConvoDefs} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useNavigation} from '@react-navigation/native' diff --git a/src/state/messages/convo/agent.ts b/src/state/messages/convo/agent.ts index 79406d155..a453e81c6 100644 --- a/src/state/messages/convo/agent.ts +++ b/src/state/messages/convo/agent.ts @@ -1,10 +1,10 @@ -import {AppBskyActorDefs} from '@atproto/api' import { + AppBskyActorDefs, BskyAgent, ChatBskyConvoDefs, ChatBskyConvoGetLog, ChatBskyConvoSendMessage, -} from '@atproto-labs/api' +} from '@atproto/api' import {nanoid} from 'nanoid/non-secure' import {networkRetry} from '#/lib/async/retry' @@ -26,6 +26,7 @@ import { } from '#/state/messages/convo/types' import {MessagesEventBus} from '#/state/messages/events/agent' import {MessagesEventBusError} from '#/state/messages/events/types' +import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' // TODO temporary let DEBUG_ACTIVE_CHAT: string | undefined @@ -46,7 +47,7 @@ export class Convo { private agent: BskyAgent private events: MessagesEventBus - private __tempFromUserDid: string + private senderUserDid: string private status: ConvoStatus = ConvoStatus.Uninitialized private error: @@ -89,7 +90,7 @@ export class Convo { this.convoId = params.convoId this.agent = params.agent this.events = params.events - this.__tempFromUserDid = params.__tempFromUserDid + this.senderUserDid = params.agent.session?.did! this.subscribe = this.subscribe.bind(this) this.getSnapshot = this.getSnapshot.bind(this) @@ -467,11 +468,7 @@ export class Convo { { convoId: this.convoId, }, - { - headers: { - Authorization: this.__tempFromUserDid, - }, - }, + {headers: DM_SERVICE_HEADERS}, ) }) @@ -479,10 +476,8 @@ export class Convo { resolve({ convo, - sender: convo.members.find(m => m.did === this.__tempFromUserDid), - recipients: convo.members.filter( - m => m.did !== this.__tempFromUserDid, - ), + sender: convo.members.find(m => m.did === this.senderUserDid), + recipients: convo.members.filter(m => m.did !== this.senderUserDid), }) } catch (e) { reject(e) @@ -557,11 +552,7 @@ export class Convo { convoId: this.convoId, limit: isNative ? 30 : 60, }, - { - headers: { - Authorization: this.__tempFromUserDid, - }, - }, + {headers: DM_SERVICE_HEADERS}, ) }) const {cursor, messages} = response.data @@ -775,12 +766,7 @@ export class Convo { convoId: this.convoId, message, }, - { - encoding: 'application/json', - headers: { - Authorization: this.__tempFromUserDid, - }, - }, + {encoding: 'application/json', headers: DM_SERVICE_HEADERS}, ) }) const res = response.data @@ -792,7 +778,6 @@ export class Convo { this.newMessages.set(res.id, { ...res, $type: 'chat.bsky.convo.defs#messageView', - sender: this.sender, }) this.pendingMessages.delete(id) @@ -835,12 +820,7 @@ export class Convo { message, })), }, - { - encoding: 'application/json', - headers: { - Authorization: this.__tempFromUserDid, - }, - }, + {encoding: 'application/json', headers: DM_SERVICE_HEADERS}, ) }) const {items} = data @@ -853,9 +833,6 @@ export class Convo { this.newMessages.set(item.id, { ...item, $type: 'chat.bsky.convo.defs#messageView', - sender: this.convo?.members.find( - m => m.did === this.__tempFromUserDid, - ), }) } @@ -899,12 +876,7 @@ export class Convo { convoId: this.convoId, messageId, }, - { - encoding: 'application/json', - headers: { - Authorization: this.__tempFromUserDid, - }, - }, + {encoding: 'application/json', headers: DM_SERVICE_HEADERS}, ) }) } catch (e: any) { @@ -970,7 +942,11 @@ export class Convo { id: nanoid(), rev: '__fake__', sentAt: new Date().toISOString(), - sender: this.sender, + /* + * `getItems` is only run in "active" status states, where + * `this.sender` is defined + */ + sender: this.sender!, }, nextMessage: null, }) diff --git a/src/state/messages/convo/index.tsx b/src/state/messages/convo/index.tsx index 311e8ce05..9c5295832 100644 --- a/src/state/messages/convo/index.tsx +++ b/src/state/messages/convo/index.tsx @@ -1,6 +1,5 @@ import React, {useContext, useState, useSyncExternalStore} from 'react' import {AppState} from 'react-native' -import {BskyAgent} from '@atproto-labs/api' import {useFocusEffect, useIsFocused} from '@react-navigation/native' import {Convo} from '#/state/messages/convo/agent' @@ -8,7 +7,6 @@ import {ConvoParams, ConvoState} from '#/state/messages/convo/types' import {useMessagesEventBus} from '#/state/messages/events' import {useMarkAsReadMutation} from '#/state/queries/messages/conversation' import {useAgent} from '#/state/session' -import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage' const ChatContext = React.createContext<ConvoState | null>(null) @@ -25,18 +23,14 @@ export function ConvoProvider({ convoId, }: Pick<ConvoParams, 'convoId'> & {children: React.ReactNode}) { const isScreenFocused = useIsFocused() - const {serviceUrl} = useDmServiceUrlStorage() const {getAgent} = useAgent() const events = useMessagesEventBus() const [convo] = useState( () => new Convo({ convoId, - agent: new BskyAgent({ - service: serviceUrl, - }), + agent: getAgent(), events, - __tempFromUserDid: getAgent().session?.did!, }), ) const service = useSyncExternalStore(convo.subscribe, convo.getSnapshot) diff --git a/src/state/messages/convo/types.ts b/src/state/messages/convo/types.ts index 920635c8c..4615acc2d 100644 --- a/src/state/messages/convo/types.ts +++ b/src/state/messages/convo/types.ts @@ -1,9 +1,9 @@ -import {AppBskyActorDefs} from '@atproto/api' import { + AppBskyActorDefs, BskyAgent, ChatBskyConvoDefs, ChatBskyConvoSendMessage, -} from '@atproto-labs/api' +} from '@atproto/api' import {MessagesEventBus} from '#/state/messages/events/agent' @@ -11,7 +11,6 @@ export type ConvoParams = { convoId: string agent: BskyAgent events: MessagesEventBus - __tempFromUserDid: string } export enum ConvoStatus { diff --git a/src/state/messages/events/agent.ts b/src/state/messages/events/agent.ts index 68225e595..3759eb3a0 100644 --- a/src/state/messages/events/agent.ts +++ b/src/state/messages/events/agent.ts @@ -1,4 +1,4 @@ -import {BskyAgent, ChatBskyConvoGetLog} from '@atproto-labs/api' +import {BskyAgent, ChatBskyConvoGetLog} from '@atproto/api' import EventEmitter from 'eventemitter3' import {nanoid} from 'nanoid/non-secure' @@ -13,6 +13,7 @@ import { MessagesEventBusParams, MessagesEventBusStatus, } from '#/state/messages/events/types' +import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' const LOGGER_CONTEXT = 'MessagesEventBus' @@ -20,7 +21,6 @@ export class MessagesEventBus { private id: string private agent: BskyAgent - private __tempFromUserDid: string private emitter = new EventEmitter<{event: [MessagesEventBusEvent]}>() private status: MessagesEventBusStatus = MessagesEventBusStatus.Initializing @@ -31,7 +31,6 @@ export class MessagesEventBus { constructor(params: MessagesEventBusParams) { this.id = nanoid(3) this.agent = params.agent - this.__tempFromUserDid = params.__tempFromUserDid this.init() } @@ -242,11 +241,7 @@ export class MessagesEventBus { { limit: 1, }, - { - headers: { - Authorization: this.__tempFromUserDid, - }, - }, + {headers: DM_SERVICE_HEADERS}, ) }) // throw new Error('UNCOMMENT TO TEST INIT FAILURE') @@ -337,11 +332,7 @@ export class MessagesEventBus { { cursor: this.latestRev, }, - { - headers: { - Authorization: this.__tempFromUserDid, - }, - }, + {headers: DM_SERVICE_HEADERS}, ) }) diff --git a/src/state/messages/events/index.tsx b/src/state/messages/events/index.tsx index 08ec77503..e8768573b 100644 --- a/src/state/messages/events/index.tsx +++ b/src/state/messages/events/index.tsx @@ -1,12 +1,10 @@ import React from 'react' import {AppState} from 'react-native' -import {BskyAgent} from '@atproto-labs/api' import {useGate} from '#/lib/statsig/statsig' import {isWeb} from '#/platform/detection' import {MessagesEventBus} from '#/state/messages/events/agent' import {useAgent} from '#/state/session' -import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage' import {IS_DEV} from '#/env' const MessagesEventBusContext = React.createContext<MessagesEventBus | null>( @@ -26,15 +24,11 @@ export function Temp_MessagesEventBusProvider({ }: { children: React.ReactNode }) { - const {serviceUrl} = useDmServiceUrlStorage() const {getAgent} = useAgent() const [bus] = React.useState( () => new MessagesEventBus({ - agent: new BskyAgent({ - service: serviceUrl, - }), - __tempFromUserDid: getAgent().session?.did!, + agent: getAgent(), }), ) @@ -74,8 +68,7 @@ export function MessagesEventBusProvider({ children: React.ReactNode }) { const gate = useGate() - const {serviceUrl} = useDmServiceUrlStorage() - if (gate('dms') && serviceUrl) { + if (gate('dms')) { return ( <Temp_MessagesEventBusProvider>{children}</Temp_MessagesEventBusProvider> ) diff --git a/src/state/messages/events/types.ts b/src/state/messages/events/types.ts index e65136e4b..305418bd3 100644 --- a/src/state/messages/events/types.ts +++ b/src/state/messages/events/types.ts @@ -1,8 +1,7 @@ -import {BskyAgent, ChatBskyConvoGetLog} from '@atproto-labs/api' +import {BskyAgent, ChatBskyConvoGetLog} from '@atproto/api' export type MessagesEventBusParams = { agent: BskyAgent - __tempFromUserDid: string } export enum MessagesEventBusStatus { 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 - }, - } -} diff --git a/yarn.lock b/yarn.lock index 5029f1259..ca2ae379c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -34,10 +34,10 @@ jsonpointer "^5.0.0" leven "^3.1.0" -"@atproto-labs/api@^0.12.8-clipclops.0": - version "0.12.8-clipclops.0" - resolved "https://registry.yarnpkg.com/@atproto-labs/api/-/api-0.12.8-clipclops.0.tgz#1c5d41d3396e439a0b645f7e1ccf500cc4b42580" - integrity sha512-YYDtWWk6BR+aRBVja/1v+gceNK81lkmF5bi6O4pTmJhFt/321XATx/ql8uTWta4VnVThoFeNPG6nLr7hs8b9cA== +"@atproto/api@^0.12.10": + version "0.12.10" + resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.12.10.tgz#a745f0e9a273a8e42d208e6d7f91535b73619720" + integrity sha512-WhZXvtVENdWSqfiPKiVIjX84r1zFnpEKApyh8rBjxBzGstWfabiz7bKW2eybZNHMty1IyFHwMHaLXPruoSJlHQ== dependencies: "@atproto/common-web" "^0.3.0" "@atproto/lexicon" "^0.4.0" @@ -58,18 +58,6 @@ multiformats "^9.9.0" tlds "^1.234.0" -"@atproto/api@^0.12.9": - version "0.12.9" - resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.12.9.tgz#5ae040980e574a5d9496368c4ca032c0cda174ec" - integrity sha512-3D4n2ZAAsDRnjevvcoIxQxuMMoqc+7vtVyP7EnrEdeOmRSCF9j8yXTqhn6rcHCbzcs3DKyYR26nQemtZsMsE0g== - dependencies: - "@atproto/common-web" "^0.3.0" - "@atproto/lexicon" "^0.4.0" - "@atproto/syntax" "^0.3.0" - "@atproto/xrpc" "^0.5.0" - multiformats "^9.9.0" - tlds "^1.234.0" - "@atproto/aws@^0.2.0": version "0.2.0" resolved "https://registry.yarnpkg.com/@atproto/aws/-/aws-0.2.0.tgz#17f3faf744824457cabd62f87be8bf08cacf8029" |