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 ACTIVE_POLL_INTERVAL = 4e3
|
||||||
export const MESSAGE_SCREEN_POLL_INTERVAL = 30e3
|
export const MESSAGE_SCREEN_POLL_INTERVAL = 30e3
|
||||||
export const BACKGROUND_POLL_INTERVAL = 60e3
|
export const BACKGROUND_POLL_INTERVAL = 60e3
|
||||||
@@ -6,3 +8,5 @@ export const INACTIVE_TIMEOUT = 60e3 * 5
|
|||||||
export const NETWORK_FAILURE_STATUSES = [
|
export const NETWORK_FAILURE_STATUSES = [
|
||||||
1, 408, 425, 429, 500, 502, 503, 504, 522, 524,
|
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'
|
} from '@atproto/api'
|
||||||
|
|
||||||
import {type MessagesEventBus} from '#/state/messages/events/agent'
|
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 = {
|
export type ConvoParams = {
|
||||||
convoId: string
|
convoId: string
|
||||||
agent: BskyAgent
|
agent: BskyAgent
|
||||||
events: MessagesEventBus
|
events: MessagesEventBus
|
||||||
placeholderData?: {
|
initialData?: {
|
||||||
convo: ChatBskyConvoDefs.ConvoView
|
convo?: ChatBskyConvoDefs.ConvoView
|
||||||
|
members?: ChatBskyActorDefs.ProfileViewBasic[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +89,7 @@ export type ConvoItem =
|
|||||||
type: 'message'
|
type: 'message'
|
||||||
key: string
|
key: string
|
||||||
message: ChatBskyConvoDefs.MessageView
|
message: ChatBskyConvoDefs.MessageView
|
||||||
|
relatedProfiles: bsky.profile.AnyProfileView[]
|
||||||
nextMessage:
|
nextMessage:
|
||||||
| ChatBskyConvoDefs.MessageView
|
| ChatBskyConvoDefs.MessageView
|
||||||
| ChatBskyConvoDefs.DeletedMessageView
|
| ChatBskyConvoDefs.DeletedMessageView
|
||||||
@@ -130,7 +134,7 @@ export type ConvoItem =
|
|||||||
type: 'system-message'
|
type: 'system-message'
|
||||||
key: string
|
key: string
|
||||||
message: ChatBskyConvoDefs.SystemMessageView
|
message: ChatBskyConvoDefs.SystemMessageView
|
||||||
relatedProfiles: ChatBskyActorDefs.ProfileViewBasic[]
|
relatedProfiles: bsky.profile.AnyProfileView[]
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'error'
|
type: 'error'
|
||||||
@@ -150,17 +154,12 @@ type FetchMessageHistory = () => Promise<void>
|
|||||||
type MarkConvoAccepted = () => void
|
type MarkConvoAccepted = () => void
|
||||||
type AddReaction = (messageId: string, reaction: string) => Promise<void>
|
type AddReaction = (messageId: string, reaction: string) => Promise<void>
|
||||||
type RemoveReaction = (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 = {
|
export type ConvoStateUninitialized = {
|
||||||
status: ConvoStatus.Uninitialized
|
status: ConvoStatus.Uninitialized
|
||||||
items: []
|
items: []
|
||||||
convo: ChatBskyConvoDefs.ConvoView | undefined
|
convo: ConvoWithDetails | undefined
|
||||||
error: undefined
|
error: undefined
|
||||||
sender: ChatBskyActorDefs.ProfileViewBasic | undefined
|
|
||||||
recipients: ChatBskyActorDefs.ProfileViewBasic[] | undefined
|
|
||||||
isFetchingHistory: false
|
isFetchingHistory: false
|
||||||
hasAllHistory: boolean
|
hasAllHistory: boolean
|
||||||
deleteMessage: undefined
|
deleteMessage: undefined
|
||||||
@@ -169,17 +168,12 @@ export type ConvoStateUninitialized = {
|
|||||||
markConvoAccepted: undefined
|
markConvoAccepted: undefined
|
||||||
addReaction: undefined
|
addReaction: undefined
|
||||||
removeReaction: undefined
|
removeReaction: undefined
|
||||||
isGroup: IsGroup
|
|
||||||
getGroupInfo: GetGroupInfo
|
|
||||||
getPrimaryMember: GetPrimaryMember
|
|
||||||
}
|
}
|
||||||
export type ConvoStateInitializing = {
|
export type ConvoStateInitializing = {
|
||||||
status: ConvoStatus.Initializing
|
status: ConvoStatus.Initializing
|
||||||
items: []
|
items: []
|
||||||
convo: ChatBskyConvoDefs.ConvoView | undefined
|
convo: ConvoWithDetails | undefined
|
||||||
error: undefined
|
error: undefined
|
||||||
sender: ChatBskyActorDefs.ProfileViewBasic | undefined
|
|
||||||
recipients: ChatBskyActorDefs.ProfileViewBasic[] | undefined
|
|
||||||
isFetchingHistory: boolean
|
isFetchingHistory: boolean
|
||||||
hasAllHistory: boolean
|
hasAllHistory: boolean
|
||||||
deleteMessage: undefined
|
deleteMessage: undefined
|
||||||
@@ -188,17 +182,12 @@ export type ConvoStateInitializing = {
|
|||||||
markConvoAccepted: undefined
|
markConvoAccepted: undefined
|
||||||
addReaction: undefined
|
addReaction: undefined
|
||||||
removeReaction: undefined
|
removeReaction: undefined
|
||||||
isGroup: IsGroup
|
|
||||||
getGroupInfo: GetGroupInfo
|
|
||||||
getPrimaryMember: GetPrimaryMember
|
|
||||||
}
|
}
|
||||||
export type ConvoStateReady = {
|
export type ConvoStateReady = {
|
||||||
status: ConvoStatus.Ready
|
status: ConvoStatus.Ready
|
||||||
items: ConvoItem[]
|
items: ConvoItem[]
|
||||||
convo: ChatBskyConvoDefs.ConvoView
|
convo: ConvoWithDetails
|
||||||
error: undefined
|
error: undefined
|
||||||
sender: ChatBskyActorDefs.ProfileViewBasic
|
|
||||||
recipients: ChatBskyActorDefs.ProfileViewBasic[]
|
|
||||||
isFetchingHistory: boolean
|
isFetchingHistory: boolean
|
||||||
hasAllHistory: boolean
|
hasAllHistory: boolean
|
||||||
deleteMessage: DeleteMessage
|
deleteMessage: DeleteMessage
|
||||||
@@ -207,17 +196,12 @@ export type ConvoStateReady = {
|
|||||||
markConvoAccepted: MarkConvoAccepted
|
markConvoAccepted: MarkConvoAccepted
|
||||||
addReaction: AddReaction
|
addReaction: AddReaction
|
||||||
removeReaction: RemoveReaction
|
removeReaction: RemoveReaction
|
||||||
isGroup: IsGroup
|
|
||||||
getGroupInfo: GetGroupInfo
|
|
||||||
getPrimaryMember: GetPrimaryMember
|
|
||||||
}
|
}
|
||||||
export type ConvoStateBackgrounded = {
|
export type ConvoStateBackgrounded = {
|
||||||
status: ConvoStatus.Backgrounded
|
status: ConvoStatus.Backgrounded
|
||||||
items: ConvoItem[]
|
items: ConvoItem[]
|
||||||
convo: ChatBskyConvoDefs.ConvoView
|
convo: ConvoWithDetails
|
||||||
error: undefined
|
error: undefined
|
||||||
sender: ChatBskyActorDefs.ProfileViewBasic
|
|
||||||
recipients: ChatBskyActorDefs.ProfileViewBasic[]
|
|
||||||
isFetchingHistory: boolean
|
isFetchingHistory: boolean
|
||||||
hasAllHistory: boolean
|
hasAllHistory: boolean
|
||||||
deleteMessage: DeleteMessage
|
deleteMessage: DeleteMessage
|
||||||
@@ -226,17 +210,12 @@ export type ConvoStateBackgrounded = {
|
|||||||
markConvoAccepted: MarkConvoAccepted
|
markConvoAccepted: MarkConvoAccepted
|
||||||
addReaction: AddReaction
|
addReaction: AddReaction
|
||||||
removeReaction: RemoveReaction
|
removeReaction: RemoveReaction
|
||||||
isGroup: IsGroup
|
|
||||||
getGroupInfo: GetGroupInfo
|
|
||||||
getPrimaryMember: GetPrimaryMember
|
|
||||||
}
|
}
|
||||||
export type ConvoStateSuspended = {
|
export type ConvoStateSuspended = {
|
||||||
status: ConvoStatus.Suspended
|
status: ConvoStatus.Suspended
|
||||||
items: ConvoItem[]
|
items: ConvoItem[]
|
||||||
convo: ChatBskyConvoDefs.ConvoView
|
convo: ConvoWithDetails
|
||||||
error: undefined
|
error: undefined
|
||||||
sender: ChatBskyActorDefs.ProfileViewBasic
|
|
||||||
recipients: ChatBskyActorDefs.ProfileViewBasic[]
|
|
||||||
isFetchingHistory: boolean
|
isFetchingHistory: boolean
|
||||||
hasAllHistory: boolean
|
hasAllHistory: boolean
|
||||||
deleteMessage: DeleteMessage
|
deleteMessage: DeleteMessage
|
||||||
@@ -245,17 +224,12 @@ export type ConvoStateSuspended = {
|
|||||||
markConvoAccepted: MarkConvoAccepted
|
markConvoAccepted: MarkConvoAccepted
|
||||||
addReaction: AddReaction
|
addReaction: AddReaction
|
||||||
removeReaction: RemoveReaction
|
removeReaction: RemoveReaction
|
||||||
isGroup: IsGroup
|
|
||||||
getGroupInfo: GetGroupInfo
|
|
||||||
getPrimaryMember: GetPrimaryMember
|
|
||||||
}
|
}
|
||||||
export type ConvoStateError = {
|
export type ConvoStateError = {
|
||||||
status: ConvoStatus.Error
|
status: ConvoStatus.Error
|
||||||
items: []
|
items: []
|
||||||
convo: undefined
|
convo: undefined
|
||||||
error: ConvoError
|
error: ConvoError
|
||||||
sender: undefined
|
|
||||||
recipients: undefined
|
|
||||||
isFetchingHistory: false
|
isFetchingHistory: false
|
||||||
hasAllHistory: false
|
hasAllHistory: false
|
||||||
deleteMessage: undefined
|
deleteMessage: undefined
|
||||||
@@ -264,17 +238,12 @@ export type ConvoStateError = {
|
|||||||
markConvoAccepted: undefined
|
markConvoAccepted: undefined
|
||||||
addReaction: undefined
|
addReaction: undefined
|
||||||
removeReaction: undefined
|
removeReaction: undefined
|
||||||
isGroup: undefined
|
|
||||||
getGroupInfo: undefined
|
|
||||||
getPrimaryMember: undefined
|
|
||||||
}
|
}
|
||||||
export type ConvoStateDisabled = {
|
export type ConvoStateDisabled = {
|
||||||
status: ConvoStatus.Disabled
|
status: ConvoStatus.Disabled
|
||||||
items: ConvoItem[]
|
items: ConvoItem[]
|
||||||
convo: ChatBskyConvoDefs.ConvoView
|
convo: ConvoWithDetails
|
||||||
error: undefined
|
error: undefined
|
||||||
sender: ChatBskyActorDefs.ProfileViewBasic
|
|
||||||
recipients: ChatBskyActorDefs.ProfileViewBasic[]
|
|
||||||
isFetchingHistory: boolean
|
isFetchingHistory: boolean
|
||||||
hasAllHistory: boolean
|
hasAllHistory: boolean
|
||||||
deleteMessage: DeleteMessage
|
deleteMessage: DeleteMessage
|
||||||
@@ -283,9 +252,6 @@ export type ConvoStateDisabled = {
|
|||||||
markConvoAccepted: MarkConvoAccepted
|
markConvoAccepted: MarkConvoAccepted
|
||||||
addReaction: AddReaction
|
addReaction: AddReaction
|
||||||
removeReaction: RemoveReaction
|
removeReaction: RemoveReaction
|
||||||
isGroup: IsGroup
|
|
||||||
getGroupInfo: GetGroupInfo
|
|
||||||
getPrimaryMember: GetPrimaryMember
|
|
||||||
}
|
}
|
||||||
export type ConvoState =
|
export type ConvoState =
|
||||||
| ConvoStateUninitialized
|
| 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