Fix open group display name handling

This commit is contained in:
Niels Andriesse 2020-11-30 15:44:07 +11:00
parent 21810a0c4c
commit 2d8933901d
5 changed files with 12 additions and 5 deletions

View File

@ -198,8 +198,8 @@ extension Storage {
return result
}
public func setOpenGroupDisplayName(to displayName: String, for publicKey: String, on channel: UInt64, server: String, using transaction: Any) {
let collection = "\(server).\(channel)" // FIXME: This should be a proper collection
public func setOpenGroupDisplayName(to displayName: String, for publicKey: String, inOpenGroupWithID openGroupID: String, using transaction: Any) {
let collection = openGroupID
(transaction as! YapDatabaseReadWriteTransaction).setObject(displayName, forKey: publicKey, inCollection: collection)
}

View File

@ -262,7 +262,7 @@ public final class OpenGroupAPI : DotNetAPI {
let endIndex = hexEncodedPublicKey.endIndex
let cutoffIndex = hexEncodedPublicKey.index(endIndex, offsetBy: -8)
let displayName = "\(rawDisplayName) (...\(hexEncodedPublicKey[cutoffIndex..<endIndex]))"
storage.setOpenGroupDisplayName(to: displayName, for: hexEncodedPublicKey, on: channel, server: server, using: transaction)
storage.setOpenGroupDisplayName(to: displayName, for: hexEncodedPublicKey, inOpenGroupWithID: "\(server).\(channel)", using: transaction)
}
}
}

View File

@ -157,6 +157,13 @@ extension MessageReceiver {
profileKey != oldProfile?.profileKey?.keyData {
profileManager.setProfileKeyData(profileKey, forRecipientId: message.sender!, avatarURL: profilePictureURL)
}
if let rawDisplayName = newProfile.displayName, let openGroupID = openGroupID {
let publicKey = message.sender!
let endIndex = publicKey.endIndex
let cutoffIndex = publicKey.index(endIndex, offsetBy: -8)
let displayName = "\(rawDisplayName) (...\(publicKey[cutoffIndex..<endIndex]))"
Storage.shared.setOpenGroupDisplayName(to: displayName, for: message.sender!, inOpenGroupWithID: openGroupID, using: transaction)
}
}
// Get or create thread
guard let threadID = storage.getOrCreateThread(for: message.sender!, groupPublicKey: message.groupPublicKey, openGroupID: openGroupID, using: transaction) else { throw Error.noThread }

View File

@ -192,7 +192,7 @@ public final class MessageSender : NSObject {
// Handle completion
let _ = promise.done(on: DispatchQueue.main) {
storage.withAsync({ transaction in
MessageSender.handleSuccessfulMessageSend(message, to: destination,X using: transaction)
MessageSender.handleSuccessfulMessageSend(message, to: destination, using: transaction)
}, completion: { })
if case .contact(_) = destination, message is VisibleMessage, !isSelfSend {
NotificationCenter.default.post(name: .messageSent, object: NSNumber(value: message.sentTimestamp!))

View File

@ -67,7 +67,7 @@ public protocol SessionMessagingKitStorageProtocol {
func setUserCount(to newValue: Int, forOpenGroupWithID openGroupID: String, using transaction: Any)
func getIDForMessage(withServerID serverID: UInt64) -> UInt64?
func setOpenGroupDisplayName(to displayName: String, for publicKey: String, on channel: UInt64, server: String, using transaction: Any)
func setOpenGroupDisplayName(to displayName: String, for publicKey: String, inOpenGroupWithID openGroupID: String, using transaction: Any)
func setLastProfilePictureUploadDate(_ date: Date) // Stored in user defaults so no transaction is needed
// MARK: - Message Handling