Communication notifications
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import Foundation
|
||||
class Constants {
|
||||
//static let EXAMPLE_DEMOS: DamusState = .empty
|
||||
static let DAMUS_APP_GROUP_IDENTIFIER: String = "group.com.damus"
|
||||
static let IMAGE_CACHE_DIRNAME: String = "ImageCache"
|
||||
static let MAIN_APP_BUNDLE_IDENTIFIER: String = "com.jb55.damus2"
|
||||
static let NOTIFICATION_EXTENSION_BUNDLE_IDENTIFIER: String = "com.jb55.damus2.DamusNotificationService"
|
||||
|
||||
|
||||
@@ -10,7 +10,15 @@ import Foundation
|
||||
enum DisplayName: Equatable {
|
||||
case both(username: String, displayName: String)
|
||||
case one(String)
|
||||
|
||||
|
||||
init (profile: Profile?, pubkey: Pubkey) {
|
||||
self = parse_display_name(name: profile?.name, display_name: profile?.display_name, pubkey: pubkey)
|
||||
}
|
||||
|
||||
init (name: String?, display_name: String?, pubkey: Pubkey) {
|
||||
self = parse_display_name(name: name, display_name: display_name, pubkey: pubkey)
|
||||
}
|
||||
|
||||
var displayName: String {
|
||||
switch self {
|
||||
case .one(let one):
|
||||
@@ -28,20 +36,37 @@ enum DisplayName: Equatable {
|
||||
return username
|
||||
}
|
||||
}
|
||||
|
||||
func nameComponents() -> PersonNameComponents {
|
||||
var components = PersonNameComponents()
|
||||
switch self {
|
||||
case .one(let one):
|
||||
components.nickname = one
|
||||
return components
|
||||
case .both(username: let username, displayName: let displayName):
|
||||
components.nickname = username
|
||||
let names = displayName.split(separator: " ")
|
||||
if let name = names.first {
|
||||
components.givenName = String(name)
|
||||
components.familyName = names.dropFirst().joined(separator: " ")
|
||||
}
|
||||
return components
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func parse_display_name(profile: Profile?, pubkey: Pubkey) -> DisplayName {
|
||||
func parse_display_name(name: String?, display_name: String?, pubkey: Pubkey) -> DisplayName {
|
||||
if pubkey == ANON_PUBKEY {
|
||||
return .one(NSLocalizedString("Anonymous", comment: "Placeholder display name of anonymous user."))
|
||||
}
|
||||
|
||||
guard let profile else {
|
||||
|
||||
if name == nil && display_name == nil {
|
||||
return .one(abbrev_bech32_pubkey(pubkey: pubkey))
|
||||
}
|
||||
|
||||
let name = profile.name?.isEmpty == false ? profile.name : nil
|
||||
let disp_name = profile.display_name?.isEmpty == false ? profile.display_name : nil
|
||||
|
||||
let name = name?.isEmpty == false ? name : nil
|
||||
let disp_name = display_name?.isEmpty == false ? display_name : nil
|
||||
|
||||
if let name, let disp_name, name != disp_name {
|
||||
return .both(username: name, displayName: disp_name)
|
||||
|
||||
Reference in New Issue
Block a user