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>
This commit is contained in:
William Casarin
2025-02-12 12:16:06 -08:00
parent bf14d7138a
commit bed4e00b53
4 changed files with 23 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ import SwiftUI
struct Reposted: View { struct Reposted: View {
let damus: DamusState let damus: DamusState
let pubkey: Pubkey let pubkey: Pubkey
let target: NoteId
var body: some View { var body: some View {
HStack(alignment: .center) { HStack(alignment: .center) {
@@ -17,8 +18,14 @@ struct Reposted: View {
.foregroundColor(Color.gray) .foregroundColor(Color.gray)
ProfileName(pubkey: pubkey, damus: damus, show_nip5_domain: false) ProfileName(pubkey: pubkey, damus: damus, show_nip5_domain: false)
.foregroundColor(Color.gray) .foregroundColor(Color.gray)
Text("Reposted", comment: "Text indicating that the note was reposted (i.e. re-shared).") let other_reposts = (damus.boosts.counts[target] ?? 0) - 1
.foregroundColor(Color.gray) 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 { struct Reposted_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
let test_state = test_damus_state 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)
} }
} }

View File

@@ -79,6 +79,7 @@ class HomeModel: ContactsDelegate {
var notifications = NotificationsModel() var notifications = NotificationsModel()
var notification_status = NotificationStatusModel() var notification_status = NotificationStatusModel()
var events: EventHolder = EventHolder() var events: EventHolder = EventHolder()
var already_reposted: Set<NoteId> = Set()
var zap_button: ZapButtonModel = ZapButtonModel() var zap_button: ZapButtonModel = ZapButtonModel()
init() { init() {
@@ -734,6 +735,16 @@ class HomeModel: ContactsDelegate {
handle_quote_repost_event(ev, target: quoted_event.note_id) 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 { if sub_id == home_subid {
insert_home_event(ev) insert_home_event(ev)
} else if sub_id == notifications_subid { } else if sub_id == notifications_subid {

View File

@@ -14,6 +14,7 @@ enum LogCategory: String {
case render case render
case storage case storage
case networking case networking
case timeline
case push_notifications case push_notifications
case damus_purple case damus_purple
case image_uploading case image_uploading

View File

@@ -16,7 +16,7 @@ struct RepostedEvent: View {
var body: some View { var body: some View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
NavigationLink(value: Route.ProfileByKey(pubkey: event.pubkey)) { 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) .padding(.horizontal)
} }
.buttonStyle(PlainButtonStyle()) .buttonStyle(PlainButtonStyle())