add relatedProfiles to ConvoItem types and list-convo-members query
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import {IS_NATIVE} from '#/env'
|
||||
|
||||
export const ACTIVE_POLL_INTERVAL = 4e3
|
||||
export const MESSAGE_SCREEN_POLL_INTERVAL = 30e3
|
||||
export const BACKGROUND_POLL_INTERVAL = 60e3
|
||||
@@ -6,3 +8,5 @@ export const INACTIVE_TIMEOUT = 60e3 * 5
|
||||
export const NETWORK_FAILURE_STATUSES = [
|
||||
1, 408, 425, 429, 500, 502, 503, 504, 522, 524,
|
||||
]
|
||||
|
||||
export const GET_MESSAGE_HISTORY_LIMIT = IS_NATIVE ? 40 : 60
|
||||
|
||||
@@ -6,13 +6,16 @@ import {
|
||||
} from '@atproto/api'
|
||||
|
||||
import {type MessagesEventBus} from '#/state/messages/events/agent'
|
||||
import {type ConvoWithDetails} from '#/components/dms/util'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
|
||||
export type ConvoParams = {
|
||||
convoId: string
|
||||
agent: BskyAgent
|
||||
events: MessagesEventBus
|
||||
placeholderData?: {
|
||||
convo: ChatBskyConvoDefs.ConvoView
|
||||
initialData?: {
|
||||
convo?: ChatBskyConvoDefs.ConvoView
|
||||
members?: ChatBskyActorDefs.ProfileViewBasic[]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +89,7 @@ export type ConvoItem =
|
||||
type: 'message'
|
||||
key: string
|
||||
message: ChatBskyConvoDefs.MessageView
|
||||
relatedProfiles: bsky.profile.AnyProfileView[]
|
||||
nextMessage:
|
||||
| ChatBskyConvoDefs.MessageView
|
||||
| ChatBskyConvoDefs.DeletedMessageView
|
||||
@@ -130,7 +134,7 @@ export type ConvoItem =
|
||||
type: 'system-message'
|
||||
key: string
|
||||
message: ChatBskyConvoDefs.SystemMessageView
|
||||
relatedProfiles: ChatBskyActorDefs.ProfileViewBasic[]
|
||||
relatedProfiles: bsky.profile.AnyProfileView[]
|
||||
}
|
||||
| {
|
||||
type: 'error'
|
||||
@@ -150,17 +154,12 @@ type FetchMessageHistory = () => Promise<void>
|
||||
type MarkConvoAccepted = () => void
|
||||
type AddReaction = (messageId: string, reaction: string) => Promise<void>
|
||||
type RemoveReaction = (messageId: string, reaction: string) => Promise<void>
|
||||
type IsGroup = () => boolean | undefined
|
||||
type GetGroupInfo = () => ChatBskyConvoDefs.GroupConvo | undefined
|
||||
type GetPrimaryMember = () => ChatBskyActorDefs.ProfileViewBasic | undefined
|
||||
|
||||
export type ConvoStateUninitialized = {
|
||||
status: ConvoStatus.Uninitialized
|
||||
items: []
|
||||
convo: ChatBskyConvoDefs.ConvoView | undefined
|
||||
convo: ConvoWithDetails | undefined
|
||||
error: undefined
|
||||
sender: ChatBskyActorDefs.ProfileViewBasic | undefined
|
||||
recipients: ChatBskyActorDefs.ProfileViewBasic[] | undefined
|
||||
isFetchingHistory: false
|
||||
hasAllHistory: boolean
|
||||
deleteMessage: undefined
|
||||
@@ -169,17 +168,12 @@ export type ConvoStateUninitialized = {
|
||||
markConvoAccepted: undefined
|
||||
addReaction: undefined
|
||||
removeReaction: undefined
|
||||
isGroup: IsGroup
|
||||
getGroupInfo: GetGroupInfo
|
||||
getPrimaryMember: GetPrimaryMember
|
||||
}
|
||||
export type ConvoStateInitializing = {
|
||||
status: ConvoStatus.Initializing
|
||||
items: []
|
||||
convo: ChatBskyConvoDefs.ConvoView | undefined
|
||||
convo: ConvoWithDetails | undefined
|
||||
error: undefined
|
||||
sender: ChatBskyActorDefs.ProfileViewBasic | undefined
|
||||
recipients: ChatBskyActorDefs.ProfileViewBasic[] | undefined
|
||||
isFetchingHistory: boolean
|
||||
hasAllHistory: boolean
|
||||
deleteMessage: undefined
|
||||
@@ -188,17 +182,12 @@ export type ConvoStateInitializing = {
|
||||
markConvoAccepted: undefined
|
||||
addReaction: undefined
|
||||
removeReaction: undefined
|
||||
isGroup: IsGroup
|
||||
getGroupInfo: GetGroupInfo
|
||||
getPrimaryMember: GetPrimaryMember
|
||||
}
|
||||
export type ConvoStateReady = {
|
||||
status: ConvoStatus.Ready
|
||||
items: ConvoItem[]
|
||||
convo: ChatBskyConvoDefs.ConvoView
|
||||
convo: ConvoWithDetails
|
||||
error: undefined
|
||||
sender: ChatBskyActorDefs.ProfileViewBasic
|
||||
recipients: ChatBskyActorDefs.ProfileViewBasic[]
|
||||
isFetchingHistory: boolean
|
||||
hasAllHistory: boolean
|
||||
deleteMessage: DeleteMessage
|
||||
@@ -207,17 +196,12 @@ export type ConvoStateReady = {
|
||||
markConvoAccepted: MarkConvoAccepted
|
||||
addReaction: AddReaction
|
||||
removeReaction: RemoveReaction
|
||||
isGroup: IsGroup
|
||||
getGroupInfo: GetGroupInfo
|
||||
getPrimaryMember: GetPrimaryMember
|
||||
}
|
||||
export type ConvoStateBackgrounded = {
|
||||
status: ConvoStatus.Backgrounded
|
||||
items: ConvoItem[]
|
||||
convo: ChatBskyConvoDefs.ConvoView
|
||||
convo: ConvoWithDetails
|
||||
error: undefined
|
||||
sender: ChatBskyActorDefs.ProfileViewBasic
|
||||
recipients: ChatBskyActorDefs.ProfileViewBasic[]
|
||||
isFetchingHistory: boolean
|
||||
hasAllHistory: boolean
|
||||
deleteMessage: DeleteMessage
|
||||
@@ -226,17 +210,12 @@ export type ConvoStateBackgrounded = {
|
||||
markConvoAccepted: MarkConvoAccepted
|
||||
addReaction: AddReaction
|
||||
removeReaction: RemoveReaction
|
||||
isGroup: IsGroup
|
||||
getGroupInfo: GetGroupInfo
|
||||
getPrimaryMember: GetPrimaryMember
|
||||
}
|
||||
export type ConvoStateSuspended = {
|
||||
status: ConvoStatus.Suspended
|
||||
items: ConvoItem[]
|
||||
convo: ChatBskyConvoDefs.ConvoView
|
||||
convo: ConvoWithDetails
|
||||
error: undefined
|
||||
sender: ChatBskyActorDefs.ProfileViewBasic
|
||||
recipients: ChatBskyActorDefs.ProfileViewBasic[]
|
||||
isFetchingHistory: boolean
|
||||
hasAllHistory: boolean
|
||||
deleteMessage: DeleteMessage
|
||||
@@ -245,17 +224,12 @@ export type ConvoStateSuspended = {
|
||||
markConvoAccepted: MarkConvoAccepted
|
||||
addReaction: AddReaction
|
||||
removeReaction: RemoveReaction
|
||||
isGroup: IsGroup
|
||||
getGroupInfo: GetGroupInfo
|
||||
getPrimaryMember: GetPrimaryMember
|
||||
}
|
||||
export type ConvoStateError = {
|
||||
status: ConvoStatus.Error
|
||||
items: []
|
||||
convo: undefined
|
||||
error: ConvoError
|
||||
sender: undefined
|
||||
recipients: undefined
|
||||
isFetchingHistory: false
|
||||
hasAllHistory: false
|
||||
deleteMessage: undefined
|
||||
@@ -264,17 +238,12 @@ export type ConvoStateError = {
|
||||
markConvoAccepted: undefined
|
||||
addReaction: undefined
|
||||
removeReaction: undefined
|
||||
isGroup: undefined
|
||||
getGroupInfo: undefined
|
||||
getPrimaryMember: undefined
|
||||
}
|
||||
export type ConvoStateDisabled = {
|
||||
status: ConvoStatus.Disabled
|
||||
items: ConvoItem[]
|
||||
convo: ChatBskyConvoDefs.ConvoView
|
||||
convo: ConvoWithDetails
|
||||
error: undefined
|
||||
sender: ChatBskyActorDefs.ProfileViewBasic
|
||||
recipients: ChatBskyActorDefs.ProfileViewBasic[]
|
||||
isFetchingHistory: boolean
|
||||
hasAllHistory: boolean
|
||||
deleteMessage: DeleteMessage
|
||||
@@ -283,9 +252,6 @@ export type ConvoStateDisabled = {
|
||||
markConvoAccepted: MarkConvoAccepted
|
||||
addReaction: AddReaction
|
||||
removeReaction: RemoveReaction
|
||||
isGroup: IsGroup
|
||||
getGroupInfo: GetGroupInfo
|
||||
getPrimaryMember: GetPrimaryMember
|
||||
}
|
||||
export type ConvoState =
|
||||
| ConvoStateUninitialized
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import {useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {DM_SERVICE_HEADERS} from '#/lib/constants'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {RQKEY_ROOT as GET_CONVOS_KEY} from './conversation'
|
||||
|
||||
const RQKEY_SEGMENT = 'members'
|
||||
export const RQKEY = (convoId: string) => [
|
||||
GET_CONVOS_KEY,
|
||||
convoId,
|
||||
RQKEY_SEGMENT,
|
||||
]
|
||||
|
||||
// group chat size is 50, so should fetch the whole list in one go
|
||||
const LIMIT = 50
|
||||
|
||||
export function useListConvoMembersQuery({convoId}: {convoId: string}) {
|
||||
const agent = useAgent()
|
||||
|
||||
return useQuery({
|
||||
queryKey: RQKEY(convoId),
|
||||
queryFn: async () => {
|
||||
const members = []
|
||||
let cursor
|
||||
|
||||
do {
|
||||
const {data} = await agent.chat.bsky.convo.getConvoMembers(
|
||||
{convoId, cursor, limit: LIMIT},
|
||||
{headers: DM_SERVICE_HEADERS},
|
||||
)
|
||||
members.push(...data.members)
|
||||
cursor = data.cursor
|
||||
} while (cursor)
|
||||
|
||||
return members
|
||||
},
|
||||
staleTime: STALE.MINUTES.THIRTY,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user