[🐴] 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"
},
"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",

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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,
})

View File

@ -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)

View File

@ -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 {

View File

@ -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},
)
})

View File

@ -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>
)

View File

@ -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 {

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 {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,
},
)
},

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 {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

View File

@ -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

View File

@ -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

View File

@ -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
}

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"
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"