fix nickname usage & clean

This commit is contained in:
Ryan ZHAO 2021-05-20 14:06:42 +10:00
parent ca723a3796
commit 563a13d208
3 changed files with 10 additions and 19 deletions

View File

@ -82,17 +82,6 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
ApplicationContext.getInstance(context).jobManager.add(RetrieveProfileAvatarJob(ourRecipient, newProfilePicture)) 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 { override fun getOrGenerateRegistrationID(): Int {
var registrationID = TextSecurePreferences.getLocalRegistrationId(context) var registrationID = TextSecurePreferences.getLocalRegistrationId(context)
if (registrationID == 0) { if (registrationID == 0) {
@ -623,6 +612,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
} }
override fun getDisplayName(publicKey: String): String? { 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) return DatabaseFactory.getLokiUserDatabase(context).getDisplayName(publicKey)
} }

View File

@ -35,9 +35,6 @@ interface StorageProtocol {
fun getUserProfilePictureURL(): String? fun getUserProfilePictureURL(): String?
fun setUserProfilePictureUrl(newProfilePicture: String) fun setUserProfilePictureUrl(newProfilePicture: String)
fun getProfileKeyForRecipient(recipientPublicKey: String): ByteArray?
fun getDisplayNameForRecipient(recipientPublicKey: String): String?
// Signal Protocol // Signal Protocol
fun getOrGenerateRegistrationID(): Int fun getOrGenerateRegistrationID(): Int

View File

@ -13,7 +13,7 @@ object UpdateMessageBuilder {
val updateData = updateMessageData.kind ?: return message val updateData = updateMessageData.kind ?: return message
if (!isOutgoing && sender == null) return message if (!isOutgoing && sender == null) return message
val senderName: String = if (!isOutgoing) { val senderName: String = if (!isOutgoing) {
MessagingModuleConfiguration.shared.storage.getDisplayNameForRecipient(sender!!) ?: sender MessagingModuleConfiguration.shared.storage.getDisplayName(sender!!) ?: sender
} else { context.getString(R.string.MessageRecord_you) } } else { context.getString(R.string.MessageRecord_you) }
when (updateData) { when (updateData) {
@ -33,7 +33,7 @@ object UpdateMessageBuilder {
} }
is UpdateMessageData.Kind.GroupMemberAdded -> { is UpdateMessageData.Kind.GroupMemberAdded -> {
val members = updateData.updatedMembers.joinToString(", ") { val members = updateData.updatedMembers.joinToString(", ") {
MessagingModuleConfiguration.shared.storage.getDisplayNameForRecipient(it) ?: it MessagingModuleConfiguration.shared.storage.getDisplayName(it) ?: it
} }
message = if (isOutgoing) { message = if (isOutgoing) {
context.getString(R.string.MessageRecord_you_added_s_to_the_group, members) context.getString(R.string.MessageRecord_you_added_s_to_the_group, members)
@ -54,7 +54,7 @@ object UpdateMessageBuilder {
} else { } else {
// 2nd case: you are not part of the removed members // 2nd case: you are not part of the removed members
val members = updateData.updatedMembers.joinToString(", ") { val members = updateData.updatedMembers.joinToString(", ") {
storage.getDisplayNameForRecipient(it) ?: it storage.getDisplayName(it) ?: it
} }
if (isOutgoing) { if (isOutgoing) {
context.getString(R.string.MessageRecord_you_removed_s_from_the_group, members) 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 { fun buildExpirationTimerMessage(context: Context, duration: Long, sender: String? = null, isOutgoing: Boolean = false): String {
if (!isOutgoing && sender == null) return "" if (!isOutgoing && sender == null) return ""
val senderName: String? = if (!isOutgoing) { val senderName: String? = if (!isOutgoing) {
MessagingModuleConfiguration.shared.storage.getDisplayNameForRecipient(sender!!) ?: sender MessagingModuleConfiguration.shared.storage.getDisplayName(sender!!) ?: sender
} else { context.getString(R.string.MessageRecord_you) } } else { context.getString(R.string.MessageRecord_you) }
return if (duration <= 0) { return if (duration <= 0) {
if (isOutgoing) context.getString(R.string.MessageRecord_you_disabled_disappearing_messages) 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 { 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) { return when (kind) {
DataExtractionNotificationInfoMessage.Kind.SCREENSHOT -> DataExtractionNotificationInfoMessage.Kind.SCREENSHOT ->
context.getString(R.string.MessageRecord_s_took_a_screenshot, senderName) context.getString(R.string.MessageRecord_s_took_a_screenshot, senderName)