refactor: move reply_desc to ReplyDescription
This commit is contained in:
@@ -80,8 +80,6 @@ struct EventView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TextEvent(_ event: NostrEvent, pubkey: String, booster_pubkey: String? = nil) -> some View {
|
func TextEvent(_ event: NostrEvent, pubkey: String, booster_pubkey: String? = nil) -> some View {
|
||||||
let content = event.get_content(damus.keypair.privkey)
|
|
||||||
|
|
||||||
return HStack(alignment: .top) {
|
return HStack(alignment: .top) {
|
||||||
let profile = damus.profiles.lookup(id: pubkey)
|
let profile = damus.profiles.lookup(id: pubkey)
|
||||||
|
|
||||||
@@ -221,33 +219,6 @@ func format_date(_ created_at: Int64) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func reply_desc(profiles: Profiles, event: NostrEvent) -> String {
|
|
||||||
let desc = make_reply_description(event.tags)
|
|
||||||
let pubkeys = desc.pubkeys
|
|
||||||
let n = desc.others
|
|
||||||
|
|
||||||
if desc.pubkeys.count == 0 {
|
|
||||||
return NSLocalizedString("Reply to self", comment: "Label to indicate that the user is replying to themself.")
|
|
||||||
}
|
|
||||||
|
|
||||||
let names: [String] = pubkeys.map {
|
|
||||||
let prof = profiles.lookup(id: $0)
|
|
||||||
return Profile.displayName(profile: prof, pubkey: $0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if names.count == 2 {
|
|
||||||
if n > 2 {
|
|
||||||
let othersCount = n - pubkeys.count
|
|
||||||
return String(format: NSLocalizedString("replying_to_two_and_others", comment: "Label to indicate that the user is replying to 2 users and others."), names[0], names[1], othersCount)
|
|
||||||
}
|
|
||||||
return String(format: NSLocalizedString("Replying to %@ & %@", comment: "Label to indicate that the user is replying to 2 users."), names[0], names[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
let othersCount = n - pubkeys.count
|
|
||||||
return String(format: NSLocalizedString("replying_to_one_and_others", comment: "Label to indicate that the user is replying to 1 user and others."), names[0], othersCount)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func make_actionbar_model(ev: NostrEvent, damus: DamusState) -> ActionBarModel {
|
func make_actionbar_model(ev: NostrEvent, damus: DamusState) -> ActionBarModel {
|
||||||
let likes = damus.likes.counts[ev.id]
|
let likes = damus.likes.counts[ev.id]
|
||||||
|
|||||||
@@ -25,3 +25,31 @@ struct ReplyDescription_Previews: PreviewProvider {
|
|||||||
ReplyDescription(event: test_event, profiles: test_damus_state().profiles)
|
ReplyDescription(event: test_event, profiles: test_damus_state().profiles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reply_desc(profiles: Profiles, event: NostrEvent) -> String {
|
||||||
|
let desc = make_reply_description(event.tags)
|
||||||
|
let pubkeys = desc.pubkeys
|
||||||
|
let n = desc.others
|
||||||
|
|
||||||
|
if desc.pubkeys.count == 0 {
|
||||||
|
return NSLocalizedString("Reply to self", comment: "Label to indicate that the user is replying to themself.")
|
||||||
|
}
|
||||||
|
|
||||||
|
let names: [String] = pubkeys.map {
|
||||||
|
let prof = profiles.lookup(id: $0)
|
||||||
|
return Profile.displayName(profile: prof, pubkey: $0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if names.count == 2 {
|
||||||
|
if n > 2 {
|
||||||
|
let othersCount = n - pubkeys.count
|
||||||
|
return String(format: NSLocalizedString("replying_to_two_and_others", comment: "Label to indicate that the user is replying to 2 users and others."), names[0], names[1], othersCount)
|
||||||
|
}
|
||||||
|
return String(format: NSLocalizedString("Replying to %@ & %@", comment: "Label to indicate that the user is replying to 2 users."), names[0], names[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
let othersCount = n - pubkeys.count
|
||||||
|
return String(format: NSLocalizedString("replying_to_one_and_others", comment: "Label to indicate that the user is replying to 1 user and others."), names[0], othersCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user