minor refactor on storing display names

This commit is contained in:
Ryan ZHAO
2021-04-22 10:48:19 +10:00
parent 9f26436041
commit d78dc83307
6 changed files with 21 additions and 23 deletions

View File

@@ -36,7 +36,6 @@ interface StorageProtocol {
fun getProfileKeyForRecipient(recipientPublicKey: String): ByteArray?
fun getDisplayNameForRecipient(recipientPublicKey: String): String?
fun setProfileKeyForRecipient(recipientPublicKey: String, profileKey: ByteArray)
// Signal Protocol
@@ -145,8 +144,6 @@ interface StorageProtocol {
// Loki User
fun getDisplayName(publicKey: String): String?
fun setDisplayName(publicKey: String, newName: String)
fun getServerDisplayName(serverID: String, publicKey: String): String?
fun getProfilePictureURL(publicKey: String): String?
// Recipient

View File

@@ -129,14 +129,16 @@ private fun MessageReceiver.handleConfigurationMessage(message: ConfigurationMes
if (allOpenGroups.contains(openGroup)) continue
storage.addOpenGroup(openGroup, 1)
}
val profileManager = SSKEnvironment.shared.profileManager
val recipient = Recipient.from(context, Address.fromSerialized(userPublicKey), false)
if (message.displayName.isNotEmpty()) {
TextSecurePreferences.setProfileName(context, message.displayName)
storage.setDisplayName(userPublicKey, message.displayName)
profileManager.setProfileName(context, recipient, message.displayName)
}
if (message.profileKey.isNotEmpty()) {
val profileKey = Base64.encodeBytes(message.profileKey)
ProfileKeyUtil.setEncodedProfileKey(context, profileKey)
storage.setProfileKeyForRecipient(userPublicKey, message.profileKey)
profileManager.setProfileKey(context, recipient, message.profileKey)
// handle profile photo
if (!message.profilePicture.isNullOrEmpty() && TextSecurePreferences.getProfilePictureURL(context) != message.profilePicture) {
storage.setUserProfilePictureUrl(message.profilePicture!!)
@@ -160,7 +162,7 @@ fun MessageReceiver.handleVisibleMessage(message: VisibleMessage, proto: SignalS
// Update the user's local name if the message came from their master device
TextSecurePreferences.setProfileName(context, displayName)
}
profileManager.setDisplayName(context, recipient, displayName)
profileManager.setProfileName(context, recipient, displayName)
}
if (recipient.profileKey == null || !MessageDigest.isEqual(recipient.profileKey, newProfile.profileKey)) {
profileManager.setProfileKey(context, recipient, newProfile.profileKey!!)

View File

@@ -289,6 +289,8 @@ public class Recipient implements RecipientModifiedListener {
String displayName = MessagingConfiguration.shared.getStorage().getDisplayName(this.address.toString());
if (displayName != null) { return displayName; }
if (this.profileName != null) { return this.profileName; }
if (this.name == null && isMmsGroupRecipient()) {
List<String> names = new LinkedList<>();

View File

@@ -29,7 +29,8 @@ class SSKEnvironment(
const val NAME_PADDED_LENGTH = 26
}
fun setDisplayName(context: Context, recipient: Recipient, displayName: String)
fun setDisplayName(context: Context, recipient: Recipient, displayName: String) // Client-side Nickname
fun setProfileName(context: Context, recipient: Recipient, profileName: String)
fun setProfilePictureURL(context: Context, recipient: Recipient, profilePictureURL: String)
fun setProfileKey(context: Context, recipient: Recipient, profileKey: ByteArray)
fun setUnidentifiedAccessMode(context: Context, recipient: Recipient, unidentifiedAccessMode: Recipient.UnidentifiedAccessMode)