Use recent convos for share via dialog (#4352)
parent
9f001526d3
commit
a49fe13223
|
@ -16,6 +16,7 @@ import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||||
import {isWeb} from '#/platform/detection'
|
import {isWeb} from '#/platform/detection'
|
||||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||||
|
import {useListConvosQuery} from '#/state/queries/messages/list-converations'
|
||||||
import {useProfileFollowsQuery} from '#/state/queries/profile-follows'
|
import {useProfileFollowsQuery} from '#/state/queries/profile-follows'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
import {useActorAutocompleteQuery} from 'state/queries/actor-autocomplete'
|
import {useActorAutocompleteQuery} from 'state/queries/actor-autocomplete'
|
||||||
|
@ -55,9 +56,11 @@ type Item =
|
||||||
export function SearchablePeopleList({
|
export function SearchablePeopleList({
|
||||||
title,
|
title,
|
||||||
onSelectChat,
|
onSelectChat,
|
||||||
|
showRecentConvos,
|
||||||
}: {
|
}: {
|
||||||
title: string
|
title: string
|
||||||
onSelectChat: (did: string) => void
|
onSelectChat: (did: string) => void
|
||||||
|
showRecentConvos?: boolean
|
||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
@ -75,6 +78,7 @@ export function SearchablePeopleList({
|
||||||
isFetching,
|
isFetching,
|
||||||
} = useActorAutocompleteQuery(searchText, true, 12)
|
} = useActorAutocompleteQuery(searchText, true, 12)
|
||||||
const {data: follows} = useProfileFollowsQuery(currentAccount?.did)
|
const {data: follows} = useProfileFollowsQuery(currentAccount?.did)
|
||||||
|
const {data: convos} = useListConvosQuery({enabled: showRecentConvos})
|
||||||
|
|
||||||
const items = useMemo(() => {
|
const items = useMemo(() => {
|
||||||
let _items: Item[] = []
|
let _items: Item[] = []
|
||||||
|
@ -103,7 +107,65 @@ export function SearchablePeopleList({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (follows) {
|
const placeholders: Item[] = Array(10)
|
||||||
|
.fill(0)
|
||||||
|
.map((_, i) => ({
|
||||||
|
type: 'placeholder',
|
||||||
|
key: i + '',
|
||||||
|
}))
|
||||||
|
|
||||||
|
if (showRecentConvos) {
|
||||||
|
if (convos && follows) {
|
||||||
|
const usedDids = new Set()
|
||||||
|
|
||||||
|
for (const page of convos.pages) {
|
||||||
|
for (const convo of page.convos) {
|
||||||
|
const profiles = convo.members.filter(
|
||||||
|
m => m.did !== currentAccount?.did,
|
||||||
|
)
|
||||||
|
|
||||||
|
for (const profile of profiles) {
|
||||||
|
if (usedDids.has(profile.did)) continue
|
||||||
|
|
||||||
|
usedDids.add(profile.did)
|
||||||
|
|
||||||
|
_items.push({
|
||||||
|
type: 'profile',
|
||||||
|
key: profile.did,
|
||||||
|
enabled: true,
|
||||||
|
profile,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let followsItems: typeof _items = []
|
||||||
|
|
||||||
|
for (const page of follows.pages) {
|
||||||
|
for (const profile of page.follows) {
|
||||||
|
if (usedDids.has(profile.did)) continue
|
||||||
|
|
||||||
|
followsItems.push({
|
||||||
|
type: 'profile',
|
||||||
|
key: profile.did,
|
||||||
|
enabled: canBeMessaged(profile),
|
||||||
|
profile,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// only sort follows
|
||||||
|
followsItems = followsItems.sort(a => {
|
||||||
|
// @ts-ignore
|
||||||
|
return a.enabled ? -1 : 1
|
||||||
|
})
|
||||||
|
|
||||||
|
// then append
|
||||||
|
_items.push(...followsItems)
|
||||||
|
} else {
|
||||||
|
_items.push(...placeholders)
|
||||||
|
}
|
||||||
|
} else if (follows) {
|
||||||
for (const page of follows.pages) {
|
for (const page of follows.pages) {
|
||||||
for (const profile of page.follows) {
|
for (const profile of page.follows) {
|
||||||
_items.push({
|
_items.push({
|
||||||
|
@ -120,19 +182,21 @@ export function SearchablePeopleList({
|
||||||
return a.enabled ? -1 : 1
|
return a.enabled ? -1 : 1
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Array(10)
|
_items.push(...placeholders)
|
||||||
.fill(0)
|
|
||||||
.forEach((_, i) => {
|
|
||||||
_items.push({
|
|
||||||
type: 'placeholder',
|
|
||||||
key: i + '',
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _items
|
return _items
|
||||||
}, [_, searchText, results, isError, currentAccount?.did, follows])
|
}, [
|
||||||
|
_,
|
||||||
|
searchText,
|
||||||
|
results,
|
||||||
|
isError,
|
||||||
|
currentAccount?.did,
|
||||||
|
follows,
|
||||||
|
convos,
|
||||||
|
showRecentConvos,
|
||||||
|
])
|
||||||
|
|
||||||
if (searchText && !isFetching && !items.length && !isError) {
|
if (searchText && !isFetching && !items.length && !isError) {
|
||||||
items.push({type: 'empty', key: 'empty', message: _(msg`No results`)})
|
items.push({type: 'empty', key: 'empty', message: _(msg`No results`)})
|
||||||
|
|
|
@ -46,6 +46,7 @@ export function SendViaChatDialog({
|
||||||
<SearchablePeopleList
|
<SearchablePeopleList
|
||||||
title={_(msg`Send post to...`)}
|
title={_(msg`Send post to...`)}
|
||||||
onSelectChat={onCreateChat}
|
onSelectChat={onCreateChat}
|
||||||
|
showRecentConvos
|
||||||
/>
|
/>
|
||||||
</Dialog.Outer>
|
</Dialog.Outer>
|
||||||
)
|
)
|
||||||
|
|
|
@ -26,10 +26,15 @@ import {useAgent, useSession} from '#/state/session'
|
||||||
export const RQKEY = ['convo-list']
|
export const RQKEY = ['convo-list']
|
||||||
type RQPageParam = string | undefined
|
type RQPageParam = string | undefined
|
||||||
|
|
||||||
export function useListConvosQuery() {
|
export function useListConvosQuery({
|
||||||
|
enabled,
|
||||||
|
}: {
|
||||||
|
enabled?: boolean
|
||||||
|
} = {}) {
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
|
||||||
return useInfiniteQuery({
|
return useInfiniteQuery({
|
||||||
|
enabled,
|
||||||
queryKey: RQKEY,
|
queryKey: RQKEY,
|
||||||
queryFn: async ({pageParam}) => {
|
queryFn: async ({pageParam}) => {
|
||||||
const {data} = await agent.api.chat.bsky.convo.listConvos(
|
const {data} = await agent.api.chat.bsky.convo.listConvos(
|
||||||
|
|
Loading…
Reference in New Issue