Huge refactor to add better structure to the project. Separating features with their associated view and model structure. This should be better organization and will allow us to improve the overall architecture in the future. I forsee many more improvements that can follow this change. e.g. MVVM Arch As well as cleaning up duplicate, unused, functionality. Many files have global functions that can also be moved or be renamed. damus/ ├── Features/ │ ├── <Feature>/ │ │ ├── Views/ │ │ └── Models/ ├── Shared/ │ ├── Components/ │ ├── Media/ │ ├── Buttons/ │ ├── Extensions/ │ ├── Empty Views/ │ ├── ErrorHandling/ │ ├── Modifiers/ │ └── Utilities/ ├── Core/ │ ├── Nostr/ │ ├── NIPs/ │ ├── DIPs/ │ ├── Types/ │ ├── Networking/ │ └── Storage/ Signed-off-by: ericholguin <ericholguin@apache.org>
66 lines
2.2 KiB
Swift
66 lines
2.2 KiB
Swift
//
|
|
// ReplyDescription.swift
|
|
// damus
|
|
//
|
|
// Created by William Casarin on 2023-01-23.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
// jb55 - TODO: this could be a lot better
|
|
struct ReplyDescription: View {
|
|
let event: NostrEvent
|
|
let replying_to: NostrEvent?
|
|
let ndb: Ndb
|
|
|
|
var body: some View {
|
|
Text(verbatim: "\(reply_desc(ndb: ndb, event: event, replying_to: replying_to))")
|
|
.font(.footnote)
|
|
.foregroundColor(.gray)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
}
|
|
|
|
struct ReplyDescription_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ReplyDescription(event: test_note, replying_to: test_note, ndb: test_damus_state.ndb)
|
|
}
|
|
}
|
|
|
|
func reply_desc(ndb: Ndb, event: NostrEvent, replying_to: NostrEvent?, locale: Locale = Locale.current) -> String {
|
|
let desc = make_reply_description(event, replying_to: replying_to)
|
|
let pubkeys = desc.pubkeys
|
|
let n = desc.others
|
|
|
|
let bundle = bundleForLocale(locale: locale)
|
|
|
|
if desc.pubkeys.count == 0 {
|
|
return NSLocalizedString("Replying to self", bundle: bundle, comment: "Label to indicate that the user is replying to themself.")
|
|
}
|
|
|
|
guard let profile_txn = NdbTxn(ndb: ndb) else {
|
|
return ""
|
|
}
|
|
|
|
let names: [String] = pubkeys.map { pk in
|
|
let prof = ndb.lookup_profile_with_txn(pk, txn: profile_txn)
|
|
|
|
return Profile.displayName(profile: prof?.profile, pubkey: pk).username.truncate(maxLength: 50)
|
|
}
|
|
|
|
let uniqueNames = NSOrderedSet(array: names).array as! [String]
|
|
|
|
if uniqueNames.count > 1 {
|
|
let othersCount = n - pubkeys.count
|
|
if othersCount <= 0 {
|
|
return String(format: NSLocalizedString("Replying to %@ & %@", bundle: bundle, comment: "Label to indicate that the user is replying to 2 users."), locale: locale, uniqueNames[0], uniqueNames[1])
|
|
} else {
|
|
return String(format: localizedStringFormat(key: "replying_to_two_and_others", locale: locale), locale: locale, othersCount, uniqueNames[0], uniqueNames[1])
|
|
}
|
|
}
|
|
|
|
return String(format: NSLocalizedString("Replying to %@", bundle: bundle, comment: "Label to indicate that the user is replying to 1 user."), locale: locale, uniqueNames[0])
|
|
}
|
|
|
|
|