diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index 854d5b4d3c..ab19938d41 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -82,17 +82,6 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, ApplicationContext.getInstance(context).jobManager.add(RetrieveProfileAvatarJob(ourRecipient, newProfilePicture)) } - override fun getProfileKeyForRecipient(recipientPublicKey: String): ByteArray? { - val address = Address.fromSerialized(recipientPublicKey) - val recipient = Recipient.from(context, address, false) - return recipient.profileKey - } - - override fun getDisplayNameForRecipient(recipientPublicKey: String): String? { - val database = DatabaseFactory.getLokiUserDatabase(context) - return database.getDisplayName(recipientPublicKey) - } - override fun getOrGenerateRegistrationID(): Int { var registrationID = TextSecurePreferences.getLocalRegistrationId(context) if (registrationID == 0) { @@ -623,6 +612,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, } override fun getDisplayName(publicKey: String): String? { + val contact = DatabaseFactory.getSessionContactDatabase(context).getContactWithSessionID(publicKey) + contact?.let { + val contactContext = Contact.contextForRecipient(Recipient.from(context, fromSerialized(publicKey), false)) + return it.displayName(contactContext) + } return DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey) } diff --git a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt index 4b08a78f5a..ed878a730e 100644 --- a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt +++ b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt @@ -35,9 +35,6 @@ interface StorageProtocol { fun getUserProfilePictureURL(): String? fun setUserProfilePictureUrl(newProfilePicture: String) - fun getProfileKeyForRecipient(recipientPublicKey: String): ByteArray? - fun getDisplayNameForRecipient(recipientPublicKey: String): String? - // Signal Protocol fun getOrGenerateRegistrationID(): Int diff --git a/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt b/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt index 04484f9cc8..dbf0865bc9 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/utilities/UpdateMessageBuilder.kt @@ -13,7 +13,7 @@ object UpdateMessageBuilder { val updateData = updateMessageData.kind ?: return message if (!isOutgoing && sender == null) return message val senderName: String = if (!isOutgoing) { - MessagingModuleConfiguration.shared.storage.getDisplayNameForRecipient(sender!!) ?: sender + MessagingModuleConfiguration.shared.storage.getDisplayName(sender!!) ?: sender } else { context.getString(R.string.MessageRecord_you) } when (updateData) { @@ -33,7 +33,7 @@ object UpdateMessageBuilder { } is UpdateMessageData.Kind.GroupMemberAdded -> { val members = updateData.updatedMembers.joinToString(", ") { - MessagingModuleConfiguration.shared.storage.getDisplayNameForRecipient(it) ?: it + MessagingModuleConfiguration.shared.storage.getDisplayName(it) ?: it } message = if (isOutgoing) { context.getString(R.string.MessageRecord_you_added_s_to_the_group, members) @@ -54,7 +54,7 @@ object UpdateMessageBuilder { } else { // 2nd case: you are not part of the removed members val members = updateData.updatedMembers.joinToString(", ") { - storage.getDisplayNameForRecipient(it) ?: it + storage.getDisplayName(it) ?: it } if (isOutgoing) { context.getString(R.string.MessageRecord_you_removed_s_from_the_group, members) @@ -77,7 +77,7 @@ object UpdateMessageBuilder { fun buildExpirationTimerMessage(context: Context, duration: Long, sender: String? = null, isOutgoing: Boolean = false): String { if (!isOutgoing && sender == null) return "" val senderName: String? = if (!isOutgoing) { - MessagingModuleConfiguration.shared.storage.getDisplayNameForRecipient(sender!!) ?: sender + MessagingModuleConfiguration.shared.storage.getDisplayName(sender!!) ?: sender } else { context.getString(R.string.MessageRecord_you) } return if (duration <= 0) { if (isOutgoing) context.getString(R.string.MessageRecord_you_disabled_disappearing_messages) @@ -90,7 +90,7 @@ object UpdateMessageBuilder { } fun buildDataExtractionMessage(context: Context, kind: DataExtractionNotificationInfoMessage.Kind, sender: String? = null): String { - val senderName = MessagingModuleConfiguration.shared.storage.getDisplayNameForRecipient(sender!!) ?: sender + val senderName = MessagingModuleConfiguration.shared.storage.getDisplayName(sender!!) ?: sender return when (kind) { DataExtractionNotificationInfoMessage.Kind.SCREENSHOT -> context.getString(R.string.MessageRecord_s_took_a_screenshot, senderName)