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
zio/stable
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
*/
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})
}
}

View File

@ -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`)