diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt b/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt index a6739e207e..d9ebe449a4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt @@ -15,6 +15,7 @@ import org.session.libsession.avatars.ProfileContactPhoto import org.session.libsession.avatars.ResourceContactPhoto import org.session.libsession.messaging.contacts.Contact import org.session.libsession.utilities.Address +import org.session.libsession.utilities.AppTextSecurePreferences import org.session.libsession.utilities.GroupUtil import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.dependencies.DatabaseComponent @@ -26,6 +27,8 @@ class ProfilePictureView @JvmOverloads constructor( ) : RelativeLayout(context, attrs) { private val binding = ViewProfilePictureBinding.inflate(LayoutInflater.from(context), this) private val glide: GlideRequests = GlideApp.with(this) + private val prefs = AppTextSecurePreferences(context) + private val userPublicKey = prefs.getLocalNumber() var publicKey: String? = null var displayName: String? = null var additionalPublicKey: String? = null @@ -51,17 +54,15 @@ class ProfilePictureView @JvmOverloads constructor( isClosedGroupRecipient: Boolean = false, isOpenGroupInboxRecipient: Boolean = false ) { - fun getUserDisplayName(publicKey: String): String { - val contact = DatabaseComponent.get(context).sessionContactDatabase().getContactWithAccountID(publicKey) - return contact?.displayName(Contact.ContactContext.REGULAR) ?: publicKey - } + fun getUserDisplayName(publicKey: String): String = prefs.takeIf { userPublicKey == publicKey }?.getProfileName() + ?: DatabaseComponent.get(context).sessionContactDatabase().getContactWithAccountID(publicKey)?.displayName(Contact.ContactContext.REGULAR) + ?: publicKey if (isClosedGroupRecipient) { val members = DatabaseComponent.get(context).groupDatabase() - .getGroupMemberAddresses(address.toGroupString(), true) - .sorted() - .take(2) - .toMutableList() + .getGroupMemberAddresses(address.toGroupString(), true) + .sorted() + .take(2) if (members.size <= 1) { publicKey = "" displayName = ""