[🐴] Swap in new package, update usages (#3992)

* Swap in new package, update usages

* Remove uneccessary patch

* Override type in safe place
zio/stable
Eric Bailey 2024-05-14 09:22:09 -05:00 committed by GitHub
parent 107760d551
commit 9173be686c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 79 additions and 173 deletions

View File

@ -49,8 +49,7 @@
"open-analyzer": "EXPO_PUBLIC_OPEN_ANALYZER=1 yarn build-web" "open-analyzer": "EXPO_PUBLIC_OPEN_ANALYZER=1 yarn build-web"
}, },
"dependencies": { "dependencies": {
"@atproto-labs/api": "^0.12.8-clipclops.0", "@atproto/api": "^0.12.10",
"@atproto/api": "^0.12.9",
"@bam.tech/react-native-image-resizer": "^3.0.4", "@bam.tech/react-native-image-resizer": "^3.0.4",
"@braintree/sanitize-url": "^6.0.2", "@braintree/sanitize-url": "^6.0.2",
"@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet", "@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet",

View File

@ -7,7 +7,7 @@ import Animated, {
useSharedValue, useSharedValue,
withTiming, withTiming,
} from 'react-native-reanimated' } from 'react-native-reanimated'
import {ChatBskyConvoDefs} from '@atproto-labs/api' import {ChatBskyConvoDefs} from '@atproto/api'
import {HITSLOP_10} from 'lib/constants' import {HITSLOP_10} from 'lib/constants'
import {useHaptics} from 'lib/haptics' import {useHaptics} from 'lib/haptics'

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import {StyleSheet, View} from 'react-native' import {StyleSheet, View} from 'react-native'
import {ChatBskyConvoDefs} from '@atproto-labs/api' import {ChatBskyConvoDefs} from '@atproto/api'
import {atoms as a} from '#/alf' import {atoms as a} from '#/alf'
import {MessageMenu} from '#/components/dms/MessageMenu' import {MessageMenu} from '#/components/dms/MessageMenu'

View File

@ -1,8 +1,6 @@
import React, {useCallback} from 'react' import React, {useCallback} from 'react'
import {Keyboard, Pressable, View} from 'react-native' import {Keyboard, Pressable, View} from 'react-native'
import {AppBskyActorDefs} from '@atproto/api' import {AppBskyActorDefs, ChatBskyConvoDefs} from '@atproto/api'
import {ChatBskyConvoDefs} from '@atproto-labs/api'
import {ConvoView} from '@atproto-labs/api/dist/client/types/chat/bsky/convo/defs'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {useNavigation} from '@react-navigation/native' import {useNavigation} from '@react-navigation/native'
@ -37,7 +35,7 @@ let ConvoMenu = ({
hideTrigger, hideTrigger,
triggerOpacity, triggerOpacity,
}: { }: {
convo: ConvoView convo: ChatBskyConvoDefs.ConvoView
profile: AppBskyActorDefs.ProfileViewBasic profile: AppBskyActorDefs.ProfileViewBasic
onUpdateConvo?: (convo: ChatBskyConvoDefs.ConvoView) => void onUpdateConvo?: (convo: ChatBskyConvoDefs.ConvoView) => void
control?: Menu.MenuControlProps control?: Menu.MenuControlProps

View File

@ -1,7 +1,6 @@
import React, {useCallback, useMemo, useRef} from 'react' import React, {useCallback, useMemo, useRef} from 'react'
import {LayoutAnimation, StyleProp, TextStyle, View} from 'react-native' import {LayoutAnimation, StyleProp, TextStyle, View} from 'react-native'
import {RichText as RichTextAPI} from '@atproto/api' import {ChatBskyConvoDefs, RichText as RichTextAPI} from '@atproto/api'
import {ChatBskyConvoDefs} from '@atproto-labs/api'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'

View File

@ -1,8 +1,7 @@
import React from 'react' import React from 'react'
import {LayoutAnimation, Pressable, View} from 'react-native' import {LayoutAnimation, Pressable, View} from 'react-native'
import * as Clipboard from 'expo-clipboard' import * as Clipboard from 'expo-clipboard'
import {RichText} from '@atproto/api' import {ChatBskyConvoDefs, RichText} from '@atproto/api'
import {ChatBskyConvoDefs} from '@atproto-labs/api'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'

View File

@ -1,10 +1,10 @@
import React, {memo, useMemo, useState} from 'react' import React, {memo, useMemo, useState} from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {RichText as RichTextAPI} from '@atproto/api'
import { import {
ChatBskyConvoDefs, ChatBskyConvoDefs,
ComAtprotoModerationCreateReport, ComAtprotoModerationCreateReport,
} from '@atproto-labs/api' RichText as RichTextAPI,
} from '@atproto/api'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {useMutation} from '@tanstack/react-query' import {useMutation} from '@tanstack/react-query'

View File

@ -1,6 +1,6 @@
import React, {useCallback, useMemo, useState} from 'react' import React, {useCallback, useMemo, useState} from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {ChatBskyConvoDefs} from '@atproto-labs/api' import {ChatBskyConvoDefs} from '@atproto/api'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {useNavigation} from '@react-navigation/native' import {useNavigation} from '@react-navigation/native'

View File

@ -1,10 +1,10 @@
import {AppBskyActorDefs} from '@atproto/api'
import { import {
AppBskyActorDefs,
BskyAgent, BskyAgent,
ChatBskyConvoDefs, ChatBskyConvoDefs,
ChatBskyConvoGetLog, ChatBskyConvoGetLog,
ChatBskyConvoSendMessage, ChatBskyConvoSendMessage,
} from '@atproto-labs/api' } from '@atproto/api'
import {nanoid} from 'nanoid/non-secure' import {nanoid} from 'nanoid/non-secure'
import {networkRetry} from '#/lib/async/retry' import {networkRetry} from '#/lib/async/retry'
@ -26,6 +26,7 @@ import {
} from '#/state/messages/convo/types' } from '#/state/messages/convo/types'
import {MessagesEventBus} from '#/state/messages/events/agent' import {MessagesEventBus} from '#/state/messages/events/agent'
import {MessagesEventBusError} from '#/state/messages/events/types' import {MessagesEventBusError} from '#/state/messages/events/types'
import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const'
// TODO temporary // TODO temporary
let DEBUG_ACTIVE_CHAT: string | undefined let DEBUG_ACTIVE_CHAT: string | undefined
@ -46,7 +47,7 @@ export class Convo {
private agent: BskyAgent private agent: BskyAgent
private events: MessagesEventBus private events: MessagesEventBus
private __tempFromUserDid: string private senderUserDid: string
private status: ConvoStatus = ConvoStatus.Uninitialized private status: ConvoStatus = ConvoStatus.Uninitialized
private error: private error:
@ -89,7 +90,7 @@ export class Convo {
this.convoId = params.convoId this.convoId = params.convoId
this.agent = params.agent this.agent = params.agent
this.events = params.events this.events = params.events
this.__tempFromUserDid = params.__tempFromUserDid this.senderUserDid = params.agent.session?.did!
this.subscribe = this.subscribe.bind(this) this.subscribe = this.subscribe.bind(this)
this.getSnapshot = this.getSnapshot.bind(this) this.getSnapshot = this.getSnapshot.bind(this)
@ -467,11 +468,7 @@ export class Convo {
{ {
convoId: this.convoId, convoId: this.convoId,
}, },
{ {headers: DM_SERVICE_HEADERS},
headers: {
Authorization: this.__tempFromUserDid,
},
},
) )
}) })
@ -479,10 +476,8 @@ export class Convo {
resolve({ resolve({
convo, convo,
sender: convo.members.find(m => m.did === this.__tempFromUserDid), sender: convo.members.find(m => m.did === this.senderUserDid),
recipients: convo.members.filter( recipients: convo.members.filter(m => m.did !== this.senderUserDid),
m => m.did !== this.__tempFromUserDid,
),
}) })
} catch (e) { } catch (e) {
reject(e) reject(e)
@ -557,11 +552,7 @@ export class Convo {
convoId: this.convoId, convoId: this.convoId,
limit: isNative ? 30 : 60, limit: isNative ? 30 : 60,
}, },
{ {headers: DM_SERVICE_HEADERS},
headers: {
Authorization: this.__tempFromUserDid,
},
},
) )
}) })
const {cursor, messages} = response.data const {cursor, messages} = response.data
@ -775,12 +766,7 @@ export class Convo {
convoId: this.convoId, convoId: this.convoId,
message, message,
}, },
{ {encoding: 'application/json', headers: DM_SERVICE_HEADERS},
encoding: 'application/json',
headers: {
Authorization: this.__tempFromUserDid,
},
},
) )
}) })
const res = response.data const res = response.data
@ -792,7 +778,6 @@ export class Convo {
this.newMessages.set(res.id, { this.newMessages.set(res.id, {
...res, ...res,
$type: 'chat.bsky.convo.defs#messageView', $type: 'chat.bsky.convo.defs#messageView',
sender: this.sender,
}) })
this.pendingMessages.delete(id) this.pendingMessages.delete(id)
@ -835,12 +820,7 @@ export class Convo {
message, message,
})), })),
}, },
{ {encoding: 'application/json', headers: DM_SERVICE_HEADERS},
encoding: 'application/json',
headers: {
Authorization: this.__tempFromUserDid,
},
},
) )
}) })
const {items} = data const {items} = data
@ -853,9 +833,6 @@ export class Convo {
this.newMessages.set(item.id, { this.newMessages.set(item.id, {
...item, ...item,
$type: 'chat.bsky.convo.defs#messageView', $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, convoId: this.convoId,
messageId, messageId,
}, },
{ {encoding: 'application/json', headers: DM_SERVICE_HEADERS},
encoding: 'application/json',
headers: {
Authorization: this.__tempFromUserDid,
},
},
) )
}) })
} catch (e: any) { } catch (e: any) {
@ -970,7 +942,11 @@ export class Convo {
id: nanoid(), id: nanoid(),
rev: '__fake__', rev: '__fake__',
sentAt: new Date().toISOString(), 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, nextMessage: null,
}) })

View File

@ -1,6 +1,5 @@
import React, {useContext, useState, useSyncExternalStore} from 'react' import React, {useContext, useState, useSyncExternalStore} from 'react'
import {AppState} from 'react-native' import {AppState} from 'react-native'
import {BskyAgent} from '@atproto-labs/api'
import {useFocusEffect, useIsFocused} from '@react-navigation/native' import {useFocusEffect, useIsFocused} from '@react-navigation/native'
import {Convo} from '#/state/messages/convo/agent' 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 {useMessagesEventBus} from '#/state/messages/events'
import {useMarkAsReadMutation} from '#/state/queries/messages/conversation' import {useMarkAsReadMutation} from '#/state/queries/messages/conversation'
import {useAgent} from '#/state/session' import {useAgent} from '#/state/session'
import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage'
const ChatContext = React.createContext<ConvoState | null>(null) const ChatContext = React.createContext<ConvoState | null>(null)
@ -25,18 +23,14 @@ export function ConvoProvider({
convoId, convoId,
}: Pick<ConvoParams, 'convoId'> & {children: React.ReactNode}) { }: Pick<ConvoParams, 'convoId'> & {children: React.ReactNode}) {
const isScreenFocused = useIsFocused() const isScreenFocused = useIsFocused()
const {serviceUrl} = useDmServiceUrlStorage()
const {getAgent} = useAgent() const {getAgent} = useAgent()
const events = useMessagesEventBus() const events = useMessagesEventBus()
const [convo] = useState( const [convo] = useState(
() => () =>
new Convo({ new Convo({
convoId, convoId,
agent: new BskyAgent({ agent: getAgent(),
service: serviceUrl,
}),
events, events,
__tempFromUserDid: getAgent().session?.did!,
}), }),
) )
const service = useSyncExternalStore(convo.subscribe, convo.getSnapshot) const service = useSyncExternalStore(convo.subscribe, convo.getSnapshot)

View File

@ -1,9 +1,9 @@
import {AppBskyActorDefs} from '@atproto/api'
import { import {
AppBskyActorDefs,
BskyAgent, BskyAgent,
ChatBskyConvoDefs, ChatBskyConvoDefs,
ChatBskyConvoSendMessage, ChatBskyConvoSendMessage,
} from '@atproto-labs/api' } from '@atproto/api'
import {MessagesEventBus} from '#/state/messages/events/agent' import {MessagesEventBus} from '#/state/messages/events/agent'
@ -11,7 +11,6 @@ export type ConvoParams = {
convoId: string convoId: string
agent: BskyAgent agent: BskyAgent
events: MessagesEventBus events: MessagesEventBus
__tempFromUserDid: string
} }
export enum ConvoStatus { export enum ConvoStatus {

View File

@ -1,4 +1,4 @@
import {BskyAgent, ChatBskyConvoGetLog} from '@atproto-labs/api' import {BskyAgent, ChatBskyConvoGetLog} from '@atproto/api'
import EventEmitter from 'eventemitter3' import EventEmitter from 'eventemitter3'
import {nanoid} from 'nanoid/non-secure' import {nanoid} from 'nanoid/non-secure'
@ -13,6 +13,7 @@ import {
MessagesEventBusParams, MessagesEventBusParams,
MessagesEventBusStatus, MessagesEventBusStatus,
} from '#/state/messages/events/types' } from '#/state/messages/events/types'
import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const'
const LOGGER_CONTEXT = 'MessagesEventBus' const LOGGER_CONTEXT = 'MessagesEventBus'
@ -20,7 +21,6 @@ export class MessagesEventBus {
private id: string private id: string
private agent: BskyAgent private agent: BskyAgent
private __tempFromUserDid: string
private emitter = new EventEmitter<{event: [MessagesEventBusEvent]}>() private emitter = new EventEmitter<{event: [MessagesEventBusEvent]}>()
private status: MessagesEventBusStatus = MessagesEventBusStatus.Initializing private status: MessagesEventBusStatus = MessagesEventBusStatus.Initializing
@ -31,7 +31,6 @@ export class MessagesEventBus {
constructor(params: MessagesEventBusParams) { constructor(params: MessagesEventBusParams) {
this.id = nanoid(3) this.id = nanoid(3)
this.agent = params.agent this.agent = params.agent
this.__tempFromUserDid = params.__tempFromUserDid
this.init() this.init()
} }
@ -242,11 +241,7 @@ export class MessagesEventBus {
{ {
limit: 1, limit: 1,
}, },
{ {headers: DM_SERVICE_HEADERS},
headers: {
Authorization: this.__tempFromUserDid,
},
},
) )
}) })
// throw new Error('UNCOMMENT TO TEST INIT FAILURE') // throw new Error('UNCOMMENT TO TEST INIT FAILURE')
@ -337,11 +332,7 @@ export class MessagesEventBus {
{ {
cursor: this.latestRev, cursor: this.latestRev,
}, },
{ {headers: DM_SERVICE_HEADERS},
headers: {
Authorization: this.__tempFromUserDid,
},
},
) )
}) })

View File

@ -1,12 +1,10 @@
import React from 'react' import React from 'react'
import {AppState} from 'react-native' import {AppState} from 'react-native'
import {BskyAgent} from '@atproto-labs/api'
import {useGate} from '#/lib/statsig/statsig' import {useGate} from '#/lib/statsig/statsig'
import {isWeb} from '#/platform/detection' import {isWeb} from '#/platform/detection'
import {MessagesEventBus} from '#/state/messages/events/agent' import {MessagesEventBus} from '#/state/messages/events/agent'
import {useAgent} from '#/state/session' import {useAgent} from '#/state/session'
import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage'
import {IS_DEV} from '#/env' import {IS_DEV} from '#/env'
const MessagesEventBusContext = React.createContext<MessagesEventBus | null>( const MessagesEventBusContext = React.createContext<MessagesEventBus | null>(
@ -26,15 +24,11 @@ export function Temp_MessagesEventBusProvider({
}: { }: {
children: React.ReactNode children: React.ReactNode
}) { }) {
const {serviceUrl} = useDmServiceUrlStorage()
const {getAgent} = useAgent() const {getAgent} = useAgent()
const [bus] = React.useState( const [bus] = React.useState(
() => () =>
new MessagesEventBus({ new MessagesEventBus({
agent: new BskyAgent({ agent: getAgent(),
service: serviceUrl,
}),
__tempFromUserDid: getAgent().session?.did!,
}), }),
) )
@ -74,8 +68,7 @@ export function MessagesEventBusProvider({
children: React.ReactNode children: React.ReactNode
}) { }) {
const gate = useGate() const gate = useGate()
const {serviceUrl} = useDmServiceUrlStorage() if (gate('dms')) {
if (gate('dms') && serviceUrl) {
return ( return (
<Temp_MessagesEventBusProvider>{children}</Temp_MessagesEventBusProvider> <Temp_MessagesEventBusProvider>{children}</Temp_MessagesEventBusProvider>
) )

View File

@ -1,8 +1,7 @@
import {BskyAgent, ChatBskyConvoGetLog} from '@atproto-labs/api' import {BskyAgent, ChatBskyConvoGetLog} from '@atproto/api'
export type MessagesEventBusParams = { export type MessagesEventBusParams = {
agent: BskyAgent agent: BskyAgent
__tempFromUserDid: string
} }
export enum MessagesEventBusStatus { export enum MessagesEventBusStatus {

View File

@ -0,0 +1,3 @@
export const DM_SERVICE_HEADERS = {
'atproto-proxy': 'did:web:dms.divy.zone#bsky_chat',
}

View File

@ -1,26 +1,23 @@
import {BskyAgent} from '@atproto-labs/api' import {ChatBskyConvoDefs} from '@atproto/api'
import {ConvoView} from '@atproto-labs/api/dist/client/types/chat/bsky/convo/defs'
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' 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 {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 {RQKEY as LIST_CONVOS_KEY} from './list-converations'
import {useHeaders} from './temp-headers'
const RQKEY_ROOT = 'convo' const RQKEY_ROOT = 'convo'
export const RQKEY = (convoId: string) => [RQKEY_ROOT, convoId] export const RQKEY = (convoId: string) => [RQKEY_ROOT, convoId]
export function useConvoQuery(convo: ConvoView) { export function useConvoQuery(convo: ChatBskyConvoDefs.ConvoView) {
const headers = useHeaders() const {getAgent} = useAgent()
const {serviceUrl} = useDmServiceUrlStorage()
return useQuery({ return useQuery({
queryKey: RQKEY(convo.id), queryKey: RQKEY(convo.id),
queryFn: async () => { queryFn: async () => {
const agent = new BskyAgent({service: serviceUrl}) const {data} = await getAgent().api.chat.bsky.convo.getConvo(
const {data} = await agent.api.chat.bsky.convo.getConvo(
{convoId: convo.id}, {convoId: convo.id},
{headers}, {headers: DM_SERVICE_HEADERS},
) )
return data.convo return data.convo
}, },
@ -29,10 +26,9 @@ export function useConvoQuery(convo: ConvoView) {
} }
export function useMarkAsReadMutation() { export function useMarkAsReadMutation() {
const headers = useHeaders()
const {serviceUrl} = useDmServiceUrlStorage()
const optimisticUpdate = useOnMarkAsRead() const optimisticUpdate = useOnMarkAsRead()
const queryClient = useQueryClient() const queryClient = useQueryClient()
const {getAgent} = useAgent()
return useMutation({ return useMutation({
mutationFn: async ({ mutationFn: async ({
@ -44,15 +40,14 @@ export function useMarkAsReadMutation() {
}) => { }) => {
if (!convoId) throw new Error('No convoId provided') if (!convoId) throw new Error('No convoId provided')
const agent = new BskyAgent({service: serviceUrl}) await getAgent().api.chat.bsky.convo.updateRead(
await agent.api.chat.bsky.convo.updateRead(
{ {
convoId, convoId,
messageId, messageId,
}, },
{ {
encoding: 'application/json', encoding: 'application/json',
headers, headers: DM_SERVICE_HEADERS,
}, },
) )
}, },

View File

@ -1,10 +1,10 @@
import {BskyAgent, ChatBskyConvoGetConvoForMembers} from '@atproto-labs/api' import {ChatBskyConvoGetConvoForMembers} from '@atproto/api'
import {useMutation, useQueryClient} from '@tanstack/react-query' import {useMutation, useQueryClient} from '@tanstack/react-query'
import {logger} from '#/logger' 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 {RQKEY as CONVO_KEY} from './conversation'
import {useHeaders} from './temp-headers'
export function useGetConvoForMembers({ export function useGetConvoForMembers({
onSuccess, onSuccess,
@ -14,15 +14,13 @@ export function useGetConvoForMembers({
onError?: (error: Error) => void onError?: (error: Error) => void
}) { }) {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const headers = useHeaders() const {getAgent} = useAgent()
const {serviceUrl} = useDmServiceUrlStorage()
return useMutation({ return useMutation({
mutationFn: async (members: string[]) => { mutationFn: async (members: string[]) => {
const agent = new BskyAgent({service: serviceUrl}) const {data} = await getAgent().api.chat.bsky.convo.getConvoForMembers(
const {data} = await agent.api.chat.bsky.convo.getConvoForMembers(
{members: members}, {members: members},
{headers}, {headers: DM_SERVICE_HEADERS},
) )
return data return data

View File

@ -1,14 +1,10 @@
import { import {ChatBskyConvoLeaveConvo, ChatBskyConvoListConvos} from '@atproto/api'
BskyAgent,
ChatBskyConvoLeaveConvo,
ChatBskyConvoListConvos,
} from '@atproto-labs/api'
import {useMutation, useQueryClient} from '@tanstack/react-query' import {useMutation, useQueryClient} from '@tanstack/react-query'
import {logger} from '#/logger' 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 {RQKEY as CONVO_LIST_KEY} from './list-converations'
import {useHeaders} from './temp-headers'
export function useLeaveConvo( export function useLeaveConvo(
convoId: string | undefined, convoId: string | undefined,
@ -21,17 +17,15 @@ export function useLeaveConvo(
}, },
) { ) {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const headers = useHeaders() const {getAgent} = useAgent()
const {serviceUrl} = useDmServiceUrlStorage()
return useMutation({ return useMutation({
mutationFn: async () => { mutationFn: async () => {
if (!convoId) throw new Error('No convoId provided') if (!convoId) throw new Error('No convoId provided')
const agent = new BskyAgent({service: serviceUrl}) const {data} = await getAgent().api.chat.bsky.convo.leaveConvo(
const {data} = await agent.api.chat.bsky.convo.leaveConvo(
{convoId}, {convoId},
{headers, encoding: 'application/json'}, {headers: DM_SERVICE_HEADERS, encoding: 'application/json'},
) )
return data return data

View File

@ -1,29 +1,23 @@
import {useCallback, useMemo} from 'react' import {useCallback, useMemo} from 'react'
import { import {ChatBskyConvoDefs, ChatBskyConvoListConvos} from '@atproto/api'
BskyAgent,
ChatBskyConvoDefs,
ChatBskyConvoListConvos,
} from '@atproto-labs/api'
import {useInfiniteQuery, useQueryClient} from '@tanstack/react-query' import {useInfiniteQuery, useQueryClient} from '@tanstack/react-query'
import {useCurrentConvoId} from '#/state/messages/current-convo-id' import {useCurrentConvoId} from '#/state/messages/current-convo-id'
import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage' import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const'
import {useHeaders} from './temp-headers' import {useAgent} from '#/state/session'
export const RQKEY = ['convo-list'] export const RQKEY = ['convo-list']
type RQPageParam = string | undefined type RQPageParam = string | undefined
export function useListConvos({refetchInterval}: {refetchInterval: number}) { export function useListConvos({refetchInterval}: {refetchInterval: number}) {
const headers = useHeaders() const {getAgent} = useAgent()
const {serviceUrl} = useDmServiceUrlStorage()
return useInfiniteQuery({ return useInfiniteQuery({
queryKey: RQKEY, queryKey: RQKEY,
queryFn: async ({pageParam}) => { queryFn: async ({pageParam}) => {
const agent = new BskyAgent({service: serviceUrl}) const {data} = await getAgent().api.chat.bsky.convo.listConvos(
const {data} = await agent.api.chat.bsky.convo.listConvos(
{cursor: pageParam}, {cursor: pageParam},
{headers}, {headers: DM_SERVICE_HEADERS},
) )
return data return data

View File

@ -1,15 +1,14 @@
import { import {
BskyAgent,
ChatBskyConvoDefs, ChatBskyConvoDefs,
ChatBskyConvoListConvos, ChatBskyConvoListConvos,
ChatBskyConvoMuteConvo, ChatBskyConvoMuteConvo,
} from '@atproto-labs/api' } from '@atproto/api'
import {InfiniteData, useMutation, useQueryClient} from '@tanstack/react-query' 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_KEY} from './conversation'
import {RQKEY as CONVO_LIST_KEY} from './list-converations' import {RQKEY as CONVO_LIST_KEY} from './list-converations'
import {useHeaders} from './temp-headers'
export function useMuteConvo( export function useMuteConvo(
convoId: string | undefined, convoId: string | undefined,
@ -22,24 +21,23 @@ export function useMuteConvo(
}, },
) { ) {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const headers = useHeaders() const {getAgent} = useAgent()
const {serviceUrl} = useDmServiceUrlStorage()
return useMutation({ return useMutation({
mutationFn: async ({mute}: {mute: boolean}) => { mutationFn: async ({mute}: {mute: boolean}) => {
if (!convoId) throw new Error('No convoId provided') if (!convoId) throw new Error('No convoId provided')
const agent = new BskyAgent({service: serviceUrl}) const agent = getAgent()
if (mute) { if (mute) {
const {data} = await agent.api.chat.bsky.convo.muteConvo( const {data} = await agent.api.chat.bsky.convo.muteConvo(
{convoId}, {convoId},
{headers, encoding: 'application/json'}, {headers: DM_SERVICE_HEADERS, encoding: 'application/json'},
) )
return data return data
} else { } else {
const {data} = await agent.api.chat.bsky.convo.unmuteConvo( const {data} = await agent.api.chat.bsky.convo.unmuteConvo(
{convoId}, {convoId},
{headers, encoding: 'application/json'}, {headers: DM_SERVICE_HEADERS, encoding: 'application/json'},
) )
return data return data
} }

View File

@ -1,11 +0,0 @@
import {useSession} from '#/state/session'
// toy auth
export const useHeaders = () => {
const {currentAccount} = useSession()
return {
get Authorization() {
return currentAccount!.did
},
}
}

View File

@ -34,10 +34,10 @@
jsonpointer "^5.0.0" jsonpointer "^5.0.0"
leven "^3.1.0" leven "^3.1.0"
"@atproto-labs/api@^0.12.8-clipclops.0": "@atproto/api@^0.12.10":
version "0.12.8-clipclops.0" version "0.12.10"
resolved "https://registry.yarnpkg.com/@atproto-labs/api/-/api-0.12.8-clipclops.0.tgz#1c5d41d3396e439a0b645f7e1ccf500cc4b42580" resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.12.10.tgz#a745f0e9a273a8e42d208e6d7f91535b73619720"
integrity sha512-YYDtWWk6BR+aRBVja/1v+gceNK81lkmF5bi6O4pTmJhFt/321XATx/ql8uTWta4VnVThoFeNPG6nLr7hs8b9cA== integrity sha512-WhZXvtVENdWSqfiPKiVIjX84r1zFnpEKApyh8rBjxBzGstWfabiz7bKW2eybZNHMty1IyFHwMHaLXPruoSJlHQ==
dependencies: dependencies:
"@atproto/common-web" "^0.3.0" "@atproto/common-web" "^0.3.0"
"@atproto/lexicon" "^0.4.0" "@atproto/lexicon" "^0.4.0"
@ -58,18 +58,6 @@
multiformats "^9.9.0" multiformats "^9.9.0"
tlds "^1.234.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": "@atproto/aws@^0.2.0":
version "0.2.0" version "0.2.0"
resolved "https://registry.yarnpkg.com/@atproto/aws/-/aws-0.2.0.tgz#17f3faf744824457cabd62f87be8bf08cacf8029" resolved "https://registry.yarnpkg.com/@atproto/aws/-/aws-0.2.0.tgz#17f3faf744824457cabd62f87be8bf08cacf8029"