diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-04-24 19:41:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-24 19:41:16 -0500 |
commit | 7a1076271600814629d52b8a1d6eb02b968c947f (patch) | |
tree | 6ffd44de89f5670cebdfdd16c78b57a3461d4584 /src | |
parent | df1791bde2dd2ddd22ad5050584cec94fe3a8ccb (diff) | |
download | voidsky-7a1076271600814629d52b8a1d6eb02b968c947f.tar.zst |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/state/models/feeds/posts.ts | 47 | ||||
-rw-r--r-- | src/view/com/composer/Composer.tsx | 7 |
2 files changed, 28 insertions, 26 deletions
diff --git a/src/state/models/feeds/posts.ts b/src/state/models/feeds/posts.ts index dd342775e..d33dce192 100644 --- a/src/state/models/feeds/posts.ts +++ b/src/state/models/feeds/posts.ts @@ -470,36 +470,35 @@ export class PostsFeedModel { /** * Check if new posts are available */ - async checkForLatest({autoPrepend}: {autoPrepend?: boolean} = {}) { + async checkForLatest() { if (this.hasNewLatest || this.feedType === 'suggested') { return } const res = await this._getFeed({limit: PAGE_SIZE}) const tuner = new FeedTuner() const slices = tuner.tune(res.data.feed, this.feedTuners) - if (slices[0]?.uri !== this.slices[0]?.uri) { - if (!autoPrepend) { - this.setHasNewLatest(true) - } else { - this.setHasNewLatest(false) - runInAction(() => { - const slicesModels = slices.map( - slice => - new PostsFeedSliceModel( - this.rootStore, - `item-${_idCounter++}`, - slice, - ), - ) - this.slices = slicesModels.concat( - this.slices.filter(slice1 => - slicesModels.find(slice2 => slice1.uri === slice2.uri), - ), - ) - }) - } - } else { - this.setHasNewLatest(false) + this.setHasNewLatest(slices[0]?.uri !== this.slices[0]?.uri) + } + + /** + * Fetches the given post and adds it to the top + * Used by the composer to add their new posts + */ + async addPostToTop(uri: string) { + try { + const res = await this.rootStore.agent.app.bsky.feed.getPosts({ + uris: [uri], + }) + const toPrepend = new PostsFeedSliceModel( + this.rootStore, + uri, + new FeedViewPostsSlice(res.data.posts.map(post => ({post}))), + ) + runInAction(() => { + this.slices = [toPrepend].concat(this.slices) + }) + } catch (e) { + this.rootStore.log.error('Failed to load post to prepend', {e}) } } diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 78c5fd6ea..a8be88980 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -138,8 +138,9 @@ export const ComposePost = observer(function ComposePost({ setIsProcessing(true) + let createdPost try { - await apilib.post(store, { + createdPost = await apilib.post(store, { rawText: rt.text, replyTo: replyTo?.uri, images: gallery.images, @@ -163,7 +164,9 @@ export const ComposePost = observer(function ComposePost({ setIsProcessing(false) return } - store.me.mainFeed.checkForLatest({autoPrepend: true}) + if (!replyTo) { + store.me.mainFeed.addPostToTop(createdPost.uri) + } onPost?.() hackfixOnClose() Toast.show(`Your ${replyTo ? 'reply' : 'post'} has been published`) |