commit bed4e00b538d4597e2c976ea590f08626136afc4
parent bf14d7138ac37e6ea3f90a4260f9c6a560b49040
Author: William Casarin <jb55@jb55.com>
Date: Wed, 12 Feb 2025 12:16:06 -0800
home: dont show reposts for the same note more than once
Fixes: https://github.com/damus-io/damus/issues/859
Changelog-Changed: Don't show reposts for the same note more than once in your home feed
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
4 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/damus/Components/Reposted.swift b/damus/Components/Reposted.swift
@@ -10,6 +10,7 @@ import SwiftUI
struct Reposted: View {
let damus: DamusState
let pubkey: Pubkey
+ let target: NoteId
var body: some View {
HStack(alignment: .center) {
@@ -17,8 +18,14 @@ struct Reposted: View {
.foregroundColor(Color.gray)
ProfileName(pubkey: pubkey, damus: damus, show_nip5_domain: false)
.foregroundColor(Color.gray)
- Text("Reposted", comment: "Text indicating that the note was reposted (i.e. re-shared).")
- .foregroundColor(Color.gray)
+ let other_reposts = (damus.boosts.counts[target] ?? 0) - 1
+ if other_reposts > 0 {
+ Text(" and \(other_reposts) others reposted", comment: "Text indicating that the note was reposted (i.e. re-shared) by multiple people")
+ .foregroundColor(Color.gray)
+ } else {
+ Text("reposted", comment: "Text indicating that the note was reposted (i.e. re-shared).")
+ .foregroundColor(Color.gray)
+ }
}
}
}
@@ -26,6 +33,6 @@ struct Reposted: View {
struct Reposted_Previews: PreviewProvider {
static var previews: some View {
let test_state = test_damus_state
- Reposted(damus: test_state, pubkey: test_state.pubkey)
+ Reposted(damus: test_state, pubkey: test_state.pubkey, target: test_note.id)
}
}
diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift
@@ -79,6 +79,7 @@ class HomeModel: ContactsDelegate {
var notifications = NotificationsModel()
var notification_status = NotificationStatusModel()
var events: EventHolder = EventHolder()
+ var already_reposted: Set<NoteId> = Set()
var zap_button: ZapButtonModel = ZapButtonModel()
init() {
@@ -734,6 +735,16 @@ class HomeModel: ContactsDelegate {
handle_quote_repost_event(ev, target: quoted_event.note_id)
}
+ // don't add duplicate reposts to home
+ if ev.known_kind == .boost, let target = ev.get_inner_event()?.id {
+ if already_reposted.contains(target) {
+ Log.info("Skipping duplicate repost for event %s", for: .timeline, target.hex())
+ return
+ } else {
+ already_reposted.insert(target)
+ }
+ }
+
if sub_id == home_subid {
insert_home_event(ev)
} else if sub_id == notifications_subid {
diff --git a/damus/Util/Log.swift b/damus/Util/Log.swift
@@ -14,6 +14,7 @@ enum LogCategory: String {
case render
case storage
case networking
+ case timeline
case push_notifications
case damus_purple
case image_uploading
diff --git a/damus/Views/Reposts/RepostedEvent.swift b/damus/Views/Reposts/RepostedEvent.swift
@@ -16,7 +16,7 @@ struct RepostedEvent: View {
var body: some View {
VStack(alignment: .leading) {
NavigationLink(value: Route.ProfileByKey(pubkey: event.pubkey)) {
- Reposted(damus: damus, pubkey: event.pubkey)
+ Reposted(damus: damus, pubkey: event.pubkey, target: inner_ev.id)
.padding(.horizontal)
}
.buttonStyle(PlainButtonStyle())