diff options
Diffstat (limited to 'src/lib/api/feed-manip.ts')
-rw-r--r-- | src/lib/api/feed-manip.ts | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/lib/api/feed-manip.ts b/src/lib/api/feed-manip.ts index 67ca8f952..f6b54a175 100644 --- a/src/lib/api/feed-manip.ts +++ b/src/lib/api/feed-manip.ts @@ -28,6 +28,7 @@ export class FeedViewPostsSlice { get isThread() { return ( this.items.length > 1 && + !this.items[0].reply && this.items.every( item => item.post.author.did === this.items[0].post.author.did, ) @@ -35,7 +36,7 @@ export class FeedViewPostsSlice { } get isReply() { - return this.items.length === 2 && !this.isThread + return this.items.length > 1 && !this.isThread } get rootItem() { @@ -49,6 +50,10 @@ export class FeedViewPostsSlice { return !!this.items.find(item => item.post.uri === uri) } + isNextInThread(uri: string) { + return this.items[this.items.length - 1].post.uri === uri + } + insert(item: FeedViewPost) { const selfReplyUri = getSelfReplyUri(item) const i = this.items.findIndex(item2 => item2.post.uri === selfReplyUri) @@ -102,7 +107,7 @@ export class FeedTuner { const selfReplyUri = getSelfReplyUri(item) if (selfReplyUri) { - const parent = slices.find(item2 => item2.containsUri(selfReplyUri)) + const parent = slices.find(item2 => item2.isNextInThread(selfReplyUri)) if (parent) { parent.insert(item) continue @@ -112,9 +117,14 @@ export class FeedTuner { } // remove any items already "seen" + const soonToBeSeenUris: Set<string> = new Set() for (let i = slices.length - 1; i >= 0; i--) { if (this.seenUris.has(slices[i].uri)) { slices.splice(i, 1) + } else { + for (const item of slices[i].items) { + soonToBeSeenUris.add(item.post.uri) + } } } @@ -124,9 +134,12 @@ export class FeedTuner { !slice.isThread && !slice.items[0].reason && slice.items[0].reply?.parent && - !this.seenUris.has(slice.items[0].reply?.parent.uri) + !this.seenUris.has(slice.items[0].reply?.parent.uri) && + !soonToBeSeenUris.has(slice.items[0].reply?.parent.uri) ) { + const uri = slice.items[0].reply?.parent.uri slice.flattenReplyParent() + soonToBeSeenUris.add(uri) } } @@ -168,14 +181,14 @@ export class FeedTuner { } static likedRepliesOnly(tuner: FeedTuner, slices: FeedViewPostsSlice[]) { - // remove any replies without any likes + // remove any replies without at least 2 likes for (let i = slices.length - 1; i >= 0; i--) { if (slices[i].isThread) { continue } const item = slices[i].rootItem const isRepost = Boolean(item.reason) - if (item.reply && !isRepost && item.post.upvoteCount === 0) { + if (item.reply && !isRepost && item.post.upvoteCount < 2) { slices.splice(i, 1) } } |