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.
29 lines
1.4 KiB
Swift
29 lines
1.4 KiB
Swift
|
|
@objc(LKDisplayNameUtilities2)
|
|
public final class DisplayNameUtilities2 : NSObject {
|
|
|
|
private override init() { }
|
|
|
|
@objc(getDisplayNameForPublicKey:threadID:transaction:)
|
|
public static func getDisplayName(for publicKey: String, inThreadWithID threadID: String, using transaction: YapDatabaseReadWriteTransaction) -> String {
|
|
// Case 1: The public key belongs to the user themselves
|
|
if publicKey == getUserHexEncodedPublicKey() { return SSKEnvironment.shared.profileManager.localProfileName() ?? publicKey }
|
|
// Case 2: The given thread is an open group
|
|
var openGroup: PublicChat? = nil
|
|
Storage.read { transaction in
|
|
openGroup = LokiDatabaseUtilities.getPublicChat(for: threadID, in: transaction)
|
|
}
|
|
if let openGroup = openGroup {
|
|
var displayName: String? = nil
|
|
Storage.read { transaction in
|
|
displayName = transaction.object(forKey: publicKey, inCollection: openGroup.id) as! String?
|
|
}
|
|
if let displayName = displayName { return displayName }
|
|
}
|
|
// Case 3: The given thread is a closed group or a one-to-one conversation
|
|
// FIXME: The line below opens a write transaction under certain circumstances. We should move away from this and towards passing
|
|
// a write transaction into this function.
|
|
return SSKEnvironment.shared.profileManager.profileNameForRecipient(withID: publicKey) ?? publicKey
|
|
}
|
|
}
|