Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use recent convos for share via dialog (#4352)

authored by

Eric Bailey and committed by
GitHub
a49fe132 9f001526

+81 -11
+74 -10
src/components/dms/dialogs/SearchablePeopleList.tsx
··· 16 16 import {sanitizeHandle} from '#/lib/strings/handles' 17 17 import {isWeb} from '#/platform/detection' 18 18 import {useModerationOpts} from '#/state/preferences/moderation-opts' 19 + import {useListConvosQuery} from '#/state/queries/messages/list-converations' 19 20 import {useProfileFollowsQuery} from '#/state/queries/profile-follows' 20 21 import {useSession} from '#/state/session' 21 22 import {useActorAutocompleteQuery} from 'state/queries/actor-autocomplete' ··· 55 56 export function SearchablePeopleList({ 56 57 title, 57 58 onSelectChat, 59 + showRecentConvos, 58 60 }: { 59 61 title: string 60 62 onSelectChat: (did: string) => void 63 + showRecentConvos?: boolean 61 64 }) { 62 65 const t = useTheme() 63 66 const {_} = useLingui() ··· 75 78 isFetching, 76 79 } = useActorAutocompleteQuery(searchText, true, 12) 77 80 const {data: follows} = useProfileFollowsQuery(currentAccount?.did) 81 + const {data: convos} = useListConvosQuery({enabled: showRecentConvos}) 78 82 79 83 const items = useMemo(() => { 80 84 let _items: Item[] = [] ··· 103 107 }) 104 108 } 105 109 } else { 106 - if (follows) { 110 + const placeholders: Item[] = Array(10) 111 + .fill(0) 112 + .map((_, i) => ({ 113 + type: 'placeholder', 114 + key: i + '', 115 + })) 116 + 117 + if (showRecentConvos) { 118 + if (convos && follows) { 119 + const usedDids = new Set() 120 + 121 + for (const page of convos.pages) { 122 + for (const convo of page.convos) { 123 + const profiles = convo.members.filter( 124 + m => m.did !== currentAccount?.did, 125 + ) 126 + 127 + for (const profile of profiles) { 128 + if (usedDids.has(profile.did)) continue 129 + 130 + usedDids.add(profile.did) 131 + 132 + _items.push({ 133 + type: 'profile', 134 + key: profile.did, 135 + enabled: true, 136 + profile, 137 + }) 138 + } 139 + } 140 + } 141 + 142 + let followsItems: typeof _items = [] 143 + 144 + for (const page of follows.pages) { 145 + for (const profile of page.follows) { 146 + if (usedDids.has(profile.did)) continue 147 + 148 + followsItems.push({ 149 + type: 'profile', 150 + key: profile.did, 151 + enabled: canBeMessaged(profile), 152 + profile, 153 + }) 154 + } 155 + } 156 + 157 + // only sort follows 158 + followsItems = followsItems.sort(a => { 159 + // @ts-ignore 160 + return a.enabled ? -1 : 1 161 + }) 162 + 163 + // then append 164 + _items.push(...followsItems) 165 + } else { 166 + _items.push(...placeholders) 167 + } 168 + } else if (follows) { 107 169 for (const page of follows.pages) { 108 170 for (const profile of page.follows) { 109 171 _items.push({ ··· 120 182 return a.enabled ? -1 : 1 121 183 }) 122 184 } else { 123 - Array(10) 124 - .fill(0) 125 - .forEach((_, i) => { 126 - _items.push({ 127 - type: 'placeholder', 128 - key: i + '', 129 - }) 130 - }) 185 + _items.push(...placeholders) 131 186 } 132 187 } 133 188 134 189 return _items 135 - }, [_, searchText, results, isError, currentAccount?.did, follows]) 190 + }, [ 191 + _, 192 + searchText, 193 + results, 194 + isError, 195 + currentAccount?.did, 196 + follows, 197 + convos, 198 + showRecentConvos, 199 + ]) 136 200 137 201 if (searchText && !isFetching && !items.length && !isError) { 138 202 items.push({type: 'empty', key: 'empty', message: _(msg`No results`)})
+1
src/components/dms/dialogs/ShareViaChatDialog.tsx
··· 46 46 <SearchablePeopleList 47 47 title={_(msg`Send post to...`)} 48 48 onSelectChat={onCreateChat} 49 + showRecentConvos 49 50 /> 50 51 </Dialog.Outer> 51 52 )
+6 -1
src/state/queries/messages/list-converations.tsx
··· 26 26 export const RQKEY = ['convo-list'] 27 27 type RQPageParam = string | undefined 28 28 29 - export function useListConvosQuery() { 29 + export function useListConvosQuery({ 30 + enabled, 31 + }: { 32 + enabled?: boolean 33 + } = {}) { 30 34 const agent = useAgent() 31 35 32 36 return useInfiniteQuery({ 37 + enabled, 33 38 queryKey: RQKEY, 34 39 queryFn: async ({pageParam}) => { 35 40 const {data} = await agent.api.chat.bsky.convo.listConvos(