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
This commit is contained in:
Paul Frazee 2023-04-24 19:41:16 -05:00 committed by GitHub
parent df1791bde2
commit 7a10762716
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 26 deletions

View file

@ -470,36 +470,35 @@ export class PostsFeedModel {
/** /**
* Check if new posts are available * Check if new posts are available
*/ */
async checkForLatest({autoPrepend}: {autoPrepend?: boolean} = {}) { async checkForLatest() {
if (this.hasNewLatest || this.feedType === 'suggested') { if (this.hasNewLatest || this.feedType === 'suggested') {
return return
} }
const res = await this._getFeed({limit: PAGE_SIZE}) const res = await this._getFeed({limit: PAGE_SIZE})
const tuner = new FeedTuner() const tuner = new FeedTuner()
const slices = tuner.tune(res.data.feed, this.feedTuners) const slices = tuner.tune(res.data.feed, this.feedTuners)
if (slices[0]?.uri !== this.slices[0]?.uri) { this.setHasNewLatest(slices[0]?.uri !== this.slices[0]?.uri)
if (!autoPrepend) { }
this.setHasNewLatest(true)
} else { /**
this.setHasNewLatest(false) * Fetches the given post and adds it to the top
runInAction(() => { * Used by the composer to add their new posts
const slicesModels = slices.map( */
slice => async addPostToTop(uri: string) {
new PostsFeedSliceModel( try {
this.rootStore, const res = await this.rootStore.agent.app.bsky.feed.getPosts({
`item-${_idCounter++}`, uris: [uri],
slice, })
), const toPrepend = new PostsFeedSliceModel(
) this.rootStore,
this.slices = slicesModels.concat( uri,
this.slices.filter(slice1 => new FeedViewPostsSlice(res.data.posts.map(post => ({post}))),
slicesModels.find(slice2 => slice1.uri === slice2.uri), )
), runInAction(() => {
) this.slices = [toPrepend].concat(this.slices)
}) })
} } catch (e) {
} else { this.rootStore.log.error('Failed to load post to prepend', {e})
this.setHasNewLatest(false)
} }
} }

View file

@ -138,8 +138,9 @@ export const ComposePost = observer(function ComposePost({
setIsProcessing(true) setIsProcessing(true)
let createdPost
try { try {
await apilib.post(store, { createdPost = await apilib.post(store, {
rawText: rt.text, rawText: rt.text,
replyTo: replyTo?.uri, replyTo: replyTo?.uri,
images: gallery.images, images: gallery.images,
@ -163,7 +164,9 @@ export const ComposePost = observer(function ComposePost({
setIsProcessing(false) setIsProcessing(false)
return return
} }
store.me.mainFeed.checkForLatest({autoPrepend: true}) if (!replyTo) {
store.me.mainFeed.addPostToTop(createdPost.uri)
}
onPost?.() onPost?.()
hackfixOnClose() hackfixOnClose()
Toast.show(`Your ${replyTo ? 'reply' : 'post'} has been published`) Toast.show(`Your ${replyTo ? 'reply' : 'post'} has been published`)