commit fdbf271432398da4a76415a01a6c253a9980d5d9
parent b26eedc633a8ae02e105d0493d8ecbe7a9ff304f
Author: Terry Yiu <git@tyiu.xyz>
Date: Sat, 19 Jul 2025 09:08:17 -0400
Add relay count and relay view to events
Changelog-Added: Added relay count and relay view to events
Closes: https://github.com/damus-io/damus/issues/1029
Signed-off-by: Terry Yiu <git@tyiu.xyz>
Diffstat:
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/damus/Models/ActionBarModel.swift b/damus/Models/ActionBarModel.swift
@@ -25,12 +25,13 @@ class ActionBarModel: ObservableObject {
@Published private(set) var zaps: Int
@Published var zap_total: Int64
@Published var replies: Int
-
+ @Published var relays: Int
+
static func empty() -> ActionBarModel {
return ActionBarModel(likes: 0, boosts: 0, zaps: 0, zap_total: 0, replies: 0, our_like: nil, our_boost: nil, our_zap: nil, our_reply: nil)
}
- init(likes: Int = 0, boosts: Int = 0, zaps: Int = 0, zap_total: Int64 = 0, replies: Int = 0, our_like: NostrEvent? = nil, our_boost: NostrEvent? = nil, our_zap: Zapping? = nil, our_reply: NostrEvent? = nil, our_quote_repost: NostrEvent? = nil, quote_reposts: Int = 0) {
+ init(likes: Int = 0, boosts: Int = 0, zaps: Int = 0, zap_total: Int64 = 0, replies: Int = 0, our_like: NostrEvent? = nil, our_boost: NostrEvent? = nil, our_zap: Zapping? = nil, our_reply: NostrEvent? = nil, our_quote_repost: NostrEvent? = nil, quote_reposts: Int = 0, relays: Int = 0) {
self.likes = likes
self.boosts = boosts
self.zaps = zaps
@@ -42,6 +43,7 @@ class ActionBarModel: ObservableObject {
self.our_reply = our_reply
self.our_quote_repost = our_quote_repost
self.quote_reposts = quote_reposts
+ self.relays = relays
}
func update(damus: DamusState, evid: NoteId) {
@@ -56,11 +58,12 @@ class ActionBarModel: ObservableObject {
self.our_zap = damus.zaps.our_zaps[evid]?.first
self.our_reply = damus.replies.our_reply(evid)
self.our_quote_repost = damus.quote_reposts.our_events[evid]
+ self.relays = (damus.nostrNetwork.pool.seen[evid] ?? []).count
self.objectWillChange.send()
}
var is_empty: Bool {
- return likes == 0 && boosts == 0 && zaps == 0
+ return likes == 0 && boosts == 0 && zaps == 0 && quote_reposts == 0 && relays == 0
}
var liked: Bool {
diff --git a/damus/Nostr/RelayPool.swift b/damus/Nostr/RelayPool.swift
@@ -357,6 +357,7 @@ class RelayPool {
}
seen[nev.id, default: Set()].insert(relay_id)
counts[relay_id, default: 0] += 1
+ notify(.update_stats(note_id: nev.id))
}
}
}
diff --git a/damus/Views/ActionBar/EventDetailBar.swift b/damus/Views/ActionBar/EventDetailBar.swift
@@ -59,6 +59,16 @@ struct EventDetailBar: View {
}
.buttonStyle(PlainButtonStyle())
}
+
+ if bar.relays > 0 {
+ let relays = Array(state.nostrNetwork.pool.seen[target] ?? [])
+ NavigationLink(value: Route.UserRelays(relays: relays)) {
+ let nounString = pluralizedString(key: "relays_count", count: bar.relays)
+ let noun = Text(nounString).foregroundColor(.gray)
+ Text("\(Text(verbatim: bar.relays.formatted()).font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many relays a note was found on. In source English, the first variable is the number of relays, and the second variable is 'Relay' or 'Relays'.")
+ }
+ .buttonStyle(PlainButtonStyle())
+ }
}
}
}