From 1b5c34766702eab7ef26c9d898a3282aa6020a43 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 16 Jan 2023 14:49:58 -0600 Subject: [PATCH] Fix: remove duplicates in the TL caused by rendering reply parents --- src/state/models/feed-view.ts | 25 +++++++++++++++++++++++++ src/view/com/posts/FeedItem.tsx | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/state/models/feed-view.ts b/src/state/models/feed-view.ts index e5a6d73d..5f2b9721 100644 --- a/src/state/models/feed-view.ts +++ b/src/state/models/feed-view.ts @@ -30,6 +30,7 @@ export class FeedItemModel { _isThreadParent: boolean = false _isThreadChildElided: boolean = false _isThreadChild: boolean = false + _hideParent: boolean = true // used to avoid dup post rendering while showing some parents // data post: PostView @@ -463,6 +464,7 @@ export class FeedModel { } else { this.feed = this.feed.concat(toAppend) } + dedupParents(this.feed) }) } @@ -601,6 +603,29 @@ function preprocessFeed(feed: FeedViewPost[]): FeedViewPostWithThreadMeta[] { return reorg } +function dedupParents(feed: FeedItemModel[]) { + // only show parents that aren't already in the feed + // NOTE if a parent post arrives in a followup loadmore, it'll show when we otherwise wish it wouldnt -prf + for (let i = 0; i < feed.length; i++) { + const item1 = feed[i] + if (!item1.replyParent || item1._isThreadChild) { + continue + } + let hideParent = false + for (let j = 0; j < feed.length; j++) { + const item2 = feed[j] + if ( + item1.replyParent.post.uri === item2.post.uri || // the post itself is there + (j < i && item1.replyParent.post.uri === item2.replyParent?.post.uri) // another reply already showed it + ) { + hideParent = true + break + } + } + item1._hideParent = hideParent + } +} + function getSelfReplyUri(item: FeedViewPost): string | undefined { return item.reply?.parent.author.did === item.post.author.did ? item.reply?.parent.uri diff --git a/src/view/com/posts/FeedItem.tsx b/src/view/com/posts/FeedItem.tsx index 7a1aa5d2..f7db827b 100644 --- a/src/view/com/posts/FeedItem.tsx +++ b/src/view/com/posts/FeedItem.tsx @@ -96,7 +96,8 @@ export const FeedItem = observer(function ({ return } - const isChild = item._isThreadChild || (!item.reason && item.reply) + const isChild = + item._isThreadChild || (!item.reason && !item._hideParent && item.reply) const isSmallTop = isChild && item._isThreadChild const isNoTop = isChild && !item._isThreadChild const outerStyles = [