Bluesky app fork with some witchin' additions 💫

Rework how recently-created posts are added to the feed (repeat posts issue) (#527)

* Rework new-post behavior to just add the user's created post to the top

* Only add post to top when not a reply

* Fix: run update in action

authored by

Paul Frazee and committed by
GitHub
7a107627 df1791bd

+28 -26
+23 -24
src/state/models/feeds/posts.ts
··· 470 470 /** 471 471 * Check if new posts are available 472 472 */ 473 - async checkForLatest({autoPrepend}: {autoPrepend?: boolean} = {}) { 473 + async checkForLatest() { 474 474 if (this.hasNewLatest || this.feedType === 'suggested') { 475 475 return 476 476 } 477 477 const res = await this._getFeed({limit: PAGE_SIZE}) 478 478 const tuner = new FeedTuner() 479 479 const slices = tuner.tune(res.data.feed, this.feedTuners) 480 - if (slices[0]?.uri !== this.slices[0]?.uri) { 481 - if (!autoPrepend) { 482 - this.setHasNewLatest(true) 483 - } else { 484 - this.setHasNewLatest(false) 485 - runInAction(() => { 486 - const slicesModels = slices.map( 487 - slice => 488 - new PostsFeedSliceModel( 489 - this.rootStore, 490 - `item-${_idCounter++}`, 491 - slice, 492 - ), 493 - ) 494 - this.slices = slicesModels.concat( 495 - this.slices.filter(slice1 => 496 - slicesModels.find(slice2 => slice1.uri === slice2.uri), 497 - ), 498 - ) 499 - }) 500 - } 501 - } else { 502 - this.setHasNewLatest(false) 480 + this.setHasNewLatest(slices[0]?.uri !== this.slices[0]?.uri) 481 + } 482 + 483 + /** 484 + * Fetches the given post and adds it to the top 485 + * Used by the composer to add their new posts 486 + */ 487 + async addPostToTop(uri: string) { 488 + try { 489 + const res = await this.rootStore.agent.app.bsky.feed.getPosts({ 490 + uris: [uri], 491 + }) 492 + const toPrepend = new PostsFeedSliceModel( 493 + this.rootStore, 494 + uri, 495 + new FeedViewPostsSlice(res.data.posts.map(post => ({post}))), 496 + ) 497 + runInAction(() => { 498 + this.slices = [toPrepend].concat(this.slices) 499 + }) 500 + } catch (e) { 501 + this.rootStore.log.error('Failed to load post to prepend', {e}) 503 502 } 504 503 } 505 504
+5 -2
src/view/com/composer/Composer.tsx
··· 138 138 139 139 setIsProcessing(true) 140 140 141 + let createdPost 141 142 try { 142 - await apilib.post(store, { 143 + createdPost = await apilib.post(store, { 143 144 rawText: rt.text, 144 145 replyTo: replyTo?.uri, 145 146 images: gallery.images, ··· 163 164 setIsProcessing(false) 164 165 return 165 166 } 166 - store.me.mainFeed.checkForLatest({autoPrepend: true}) 167 + if (!replyTo) { 168 + store.me.mainFeed.addPostToTop(createdPost.uri) 169 + } 167 170 onPost?.() 168 171 hackfixOnClose() 169 172 Toast.show(`Your ${replyTo ? 'reply' : 'post'} has been published`)