mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.6 KiB
Swift
40 lines
1.6 KiB
Swift
|
|
@objc(LKDisplayNameUtilities)
|
|
public final class DisplayNameUtilities : NSObject {
|
|
|
|
override private init() { }
|
|
|
|
private static var userHexEncodedPublicKey: String {
|
|
return OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
|
|
}
|
|
|
|
private static var userDisplayName: String? {
|
|
return OWSProfileManager.shared().localProfileName()
|
|
}
|
|
|
|
@objc public static func getPrivateChatDisplayName(for hexEncodedPublicKey: String) -> String? {
|
|
if hexEncodedPublicKey == userHexEncodedPublicKey {
|
|
return userDisplayName
|
|
} else {
|
|
return OWSProfileManager.shared().profileName(forRecipientId: hexEncodedPublicKey)
|
|
}
|
|
}
|
|
|
|
@objc public static func getGroupChatDisplayName(for hexEncodedPublicKey: String, in channel: UInt64, on server: String) -> String? {
|
|
var result: String?
|
|
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
|
|
result = getGroupChatDisplayName(for: hexEncodedPublicKey, in: channel, on: server, using: transaction)
|
|
}
|
|
return result
|
|
}
|
|
|
|
@objc public static func getGroupChatDisplayName(for hexEncodedPublicKey: String, in channel: UInt64, on server: String, using transaction: YapDatabaseReadTransaction) -> String? {
|
|
if hexEncodedPublicKey == userHexEncodedPublicKey {
|
|
return userDisplayName
|
|
} else {
|
|
let collection = "\(server).\(channel)"
|
|
return transaction.object(forKey: hexEncodedPublicKey, inCollection: collection) as! String?
|
|
}
|
|
}
|
|
}
|