Observe display name changes

This commit is contained in:
Niels Andriesse 2019-07-19 15:23:45 +10:00
parent 956f20fc0e
commit c0a9500706
3 changed files with 7 additions and 3 deletions

View File

@ -87,6 +87,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
private fun updateUI() { private fun updateUI() {
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context) val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
val contactID = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(message!!.threadId)!!.address.toString() val contactID = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(message!!.threadId)!!.address.toString()
val contactDisplayName = DatabaseFactory.getLokiUserDisplayNameDatabase(context).getDisplayName(contactID) ?: contactID
if (!message!!.isOutgoing) { if (!message!!.isOutgoing) {
val friendRequestStatus = database.getFriendRequestStatus(message!!.id) val friendRequestStatus = database.getFriendRequestStatus(message!!.id)
visibility = if (friendRequestStatus == LokiMessageFriendRequestStatus.NONE) View.GONE else View.VISIBLE visibility = if (friendRequestStatus == LokiMessageFriendRequestStatus.NONE) View.GONE else View.VISIBLE
@ -98,7 +99,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
LokiMessageFriendRequestStatus.REQUEST_REJECTED -> R.string.view_friend_request_incoming_declined_message LokiMessageFriendRequestStatus.REQUEST_REJECTED -> R.string.view_friend_request_incoming_declined_message
LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_incoming_expired_message LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_incoming_expired_message
} }
label.text = resources.getString(formatID, contactID) label.text = resources.getString(formatID, contactDisplayName)
} else { } else {
val friendRequestStatus = database.getFriendRequestStatus(message!!.id) val friendRequestStatus = database.getFriendRequestStatus(message!!.id)
visibility = if (friendRequestStatus == LokiMessageFriendRequestStatus.NONE) View.GONE else View.VISIBLE visibility = if (friendRequestStatus == LokiMessageFriendRequestStatus.NONE) View.GONE else View.VISIBLE
@ -111,7 +112,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_outgoing_expired_message LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_outgoing_expired_message
} }
if (formatID != null) { if (formatID != null) {
label.text = resources.getString(formatID, contactID) label.text = resources.getString(formatID, contactDisplayName)
} }
label.visibility = if (formatID != null) View.VISIBLE else View.GONE label.visibility = if (formatID != null) View.VISIBLE else View.GONE
topSpacer.visibility = label.visibility topSpacer.visibility = label.visibility

View File

@ -2,8 +2,10 @@ package org.thoughtcrime.securesms.loki
import android.content.ContentValues import android.content.ContentValues
import android.content.Context import android.content.Context
import org.thoughtcrime.securesms.database.Address
import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.Database
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
import org.thoughtcrime.securesms.recipients.Recipient
class LokiUserDisplayNameDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) { class LokiUserDisplayNameDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
@ -27,5 +29,6 @@ class LokiUserDisplayNameDatabase(context: Context, helper: SQLCipherOpenHelper)
row.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey) row.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey)
row.put(Companion.displayName, displayName) row.put(Companion.displayName, displayName)
database.insertOrUpdate(tableName, row, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) database.insertOrUpdate(tableName, row, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey ))
Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false).notifyListeners()
} }
} }

View File

@ -697,7 +697,7 @@ public class Recipient implements RecipientModifiedListener {
return this.address.hashCode(); return this.address.hashCode();
} }
private void notifyListeners() { public void notifyListeners() {
Set<RecipientModifiedListener> localListeners; Set<RecipientModifiedListener> localListeners;
synchronized (this) { synchronized (this) {