From e5ec07b919df97b44294e9bd7954ad244ee149d4 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 17 Jan 2023 10:45:37 -0600 Subject: Remove duplicate posts caused by reposts --- src/state/models/feed-view.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/state/models/feed-view.ts b/src/state/models/feed-view.ts index c39daf874..5f8fc98fe 100644 --- a/src/state/models/feed-view.ts +++ b/src/state/models/feed-view.ts @@ -457,6 +457,7 @@ export class FeedModel { } else { this.feed = this.feed.concat(toAppend) } + dedupReposts(this.feed) dedupParents(this.feed) }) } @@ -595,9 +596,24 @@ function preprocessFeed(feed: FeedViewPost[]): FeedViewPostWithThreadMeta[] { return reorg } +// WARNING: mutates `feed` +function dedupReposts(feed: FeedItemModel[]) { + // remove duplicates caused by reposts + for (let i = 0; i < feed.length; i++) { + const item1 = feed[i] + for (let j = i + 1; j < feed.length; j++) { + const item2 = feed[j] + if (item1.post.uri === item2.post.uri) { + feed.splice(j, 1) + j-- + } + } + } +} + +// WARNING: mutates `feed` 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) { -- cgit 1.4.1