Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

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

Prefer full posts for post thread placeholder (#2943)

* Revert "Prefer post over quote when finding cached post (#2935)"

This reverts commit da62a77f05258ce2b0609248cb5677c2406a4e63.

* Prefer full posts for post thread placeholder

* Clarify with a comment

authored by

dan and committed by
GitHub
3a758556 fab6c286

+33 -67
-17
src/state/queries/notifications/feed.ts
··· 133 133 return query 134 134 } 135 135 136 - /** 137 - * This helper is used by the post-thread placeholder function to 138 - * find a post in the query-data cache 139 - */ 140 - export function findPostInQueryData( 141 - queryClient: QueryClient, 142 - uri: string, 143 - ): AppBskyFeedDefs.PostView | undefined { 144 - const generator = findAllPostsInQueryData(queryClient, uri) 145 - const result = generator.next() 146 - if (result.done) { 147 - return undefined 148 - } else { 149 - return result.value 150 - } 151 - } 152 - 153 136 export function* findAllPostsInQueryData( 154 137 queryClient: QueryClient, 155 138 uri: string,
+1 -25
src/state/queries/post-feed.ts
··· 365 365 } 366 366 } 367 367 368 - /** 369 - * This helper is used by the post-thread placeholder function to 370 - * find a post in the query-data cache 371 - */ 372 - export function findPostInQueryData( 373 - queryClient: QueryClient, 374 - uri: string, 375 - ): AppBskyFeedDefs.PostView | undefined { 376 - const generator = findAllPostsInQueryData(queryClient, uri) 377 - const result = generator.next() 378 - if (result.done) { 379 - return undefined 380 - } else { 381 - return result.value 382 - } 383 - } 384 - 385 368 export function* findAllPostsInQueryData( 386 369 queryClient: QueryClient, 387 370 uri: string, ··· 391 374 >({ 392 375 queryKey: ['post-feed'], 393 376 }) 394 - 395 - let foundEmbed: AppBskyFeedDefs.PostView | undefined 396 - 397 377 for (const [_queryKey, queryData] of queryDatas) { 398 378 if (!queryData?.pages) { 399 379 continue ··· 405 385 } 406 386 const quotedPost = getEmbeddedPost(item.post.embed) 407 387 if (quotedPost?.uri === uri) { 408 - foundEmbed = embedViewRecordToPostView(quotedPost) 388 + yield embedViewRecordToPostView(quotedPost) 409 389 } 410 390 if ( 411 391 AppBskyFeedDefs.isPostView(item.reply?.parent) && ··· 421 401 } 422 402 } 423 403 } 424 - } 425 - 426 - if (foundEmbed) { 427 - yield foundEmbed 428 404 } 429 405 } 430 406
+32 -25
src/state/queries/post-thread.ts
··· 8 8 9 9 import {getAgent} from '#/state/session' 10 10 import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types' 11 - import {findPostInQueryData as findPostInFeedQueryData} from './post-feed' 12 - import {findPostInQueryData as findPostInNotifsQueryData} from './notifications/feed' 11 + import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from './post-feed' 12 + import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from './notifications/feed' 13 13 import {precacheThreadPostProfiles} from './profile' 14 14 import {getEmbeddedPost} from './util' 15 15 ··· 82 82 return undefined 83 83 } 84 84 { 85 - const item = findPostInQueryData(queryClient, uri) 86 - if (item) { 87 - return threadNodeToPlaceholderThread(item) 88 - } 89 - } 90 - { 91 - const item = findPostInFeedQueryData(queryClient, uri) 92 - if (item) { 93 - return postViewToPlaceholderThread(item) 94 - } 95 - } 96 - { 97 - const item = findPostInNotifsQueryData(queryClient, uri) 98 - if (item) { 99 - return postViewToPlaceholderThread(item) 85 + const post = findPostInQueryData(queryClient, uri) 86 + if (post) { 87 + return post 100 88 } 101 89 } 102 90 return undefined ··· 213 201 function findPostInQueryData( 214 202 queryClient: QueryClient, 215 203 uri: string, 216 - ): ThreadNode | undefined { 217 - const generator = findAllPostsInQueryData(queryClient, uri) 218 - const result = generator.next() 219 - if (result.done) { 220 - return undefined 221 - } else { 222 - return result.value 204 + ): ThreadNode | void { 205 + let partial 206 + for (let item of findAllPostsInQueryData(queryClient, uri)) { 207 + if (item.type === 'post') { 208 + // Currently, the backend doesn't send full post info in some cases 209 + // (for example, for quoted posts). We use missing `likeCount` 210 + // as a way to detect that. In the future, we should fix this on 211 + // the backend, which will let us always stop on the first result. 212 + const hasAllInfo = item.post.likeCount != null 213 + if (hasAllInfo) { 214 + return item 215 + } else { 216 + partial = item 217 + // Keep searching, we might still find a full post in the cache. 218 + } 219 + } 223 220 } 221 + return partial 224 222 } 225 223 226 224 export function* findAllPostsInQueryData( ··· 236 234 } 237 235 for (const item of traverseThread(queryData)) { 238 236 if (item.uri === uri) { 239 - yield item 237 + const placeholder = threadNodeToPlaceholderThread(item) 238 + if (placeholder) { 239 + yield placeholder 240 + } 240 241 } 241 242 const quotedPost = 242 243 item.type === 'post' ? getEmbeddedPost(item.post.embed) : undefined ··· 244 245 yield embedViewRecordToPlaceholderThread(quotedPost) 245 246 } 246 247 } 248 + } 249 + for (let post of findAllPostsInFeedQueryData(queryClient, uri)) { 250 + yield postViewToPlaceholderThread(post) 251 + } 252 + for (let post of findAllPostsInNotifsQueryData(queryClient, uri)) { 253 + yield postViewToPlaceholderThread(post) 247 254 } 248 255 } 249 256