From b2439d48ee2eb06208381b9b41ebad8564bd891f Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Fri, 12 May 2023 11:26:00 +1000 Subject: [PATCH 1/3] refactor: let the user display name return "You" for local user --- .../main/java/org/thoughtcrime/securesms/contacts/UserView.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt index 88f485b3d5..8992756f90 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt @@ -48,7 +48,9 @@ class UserView : LinearLayout { // region Updating fun bind(user: Recipient, glide: GlideRequests, actionIndicator: ActionIndicator, isSelected: Boolean = false) { + val isLocalUser = user.isLocalNumber fun getUserDisplayName(publicKey: String): String { + if (isLocalUser) return context.getString(R.string.MessageRecord_you) val contact = DatabaseComponent.get(context).sessionContactDatabase().getContactWithSessionID(publicKey) return contact?.displayName(Contact.ContactContext.REGULAR) ?: publicKey } From da330273c8c6d293a56285c774dac526353aa822 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Fri, 12 May 2023 11:30:15 +1000 Subject: [PATCH 2/3] fix: prevent NTS self create thread on user view bind --- .../java/org/thoughtcrime/securesms/contacts/UserView.kt | 5 +++-- .../main/java/org/thoughtcrime/securesms/database/Storage.kt | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt index 8992756f90..35e257fe84 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt @@ -54,8 +54,9 @@ class UserView : LinearLayout { val contact = DatabaseComponent.get(context).sessionContactDatabase().getContactWithSessionID(publicKey) return contact?.displayName(Contact.ContactContext.REGULAR) ?: publicKey } - val threadID = MessagingModuleConfiguration.shared.storage.getOrCreateThreadIdFor(user.address) - MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded(threadID, context) // FIXME: This is a bad place to do this + MessagingModuleConfiguration.shared.storage.getThreadId(user.address)?.let { threadID -> + MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded(threadID, context) // FIXME: This is a bad place to do this + } val address = user.address.serialize() binding.profilePictureView.root.glide = glide binding.profilePictureView.root.update(user) 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 f9b450aaec..f26607a385 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -97,6 +97,9 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co // TODO: maybe add time here from formation / creation message override fun threadCreated(address: Address, threadId: Long) { if (!getRecipientApproved(address)) return // don't store unapproved / message requests + if (getUserPublicKey() == address.serialize()) { + Log.d("Loki-DBG", "NTS created, context:\n${Thread.currentThread().stackTrace.joinToString("\n")}") + } val volatile = configFactory.convoVolatile ?: return if (address.isGroup) { From 2b096019d671fca622ba5a29764807ca2f1e2fb5 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Fri, 12 May 2023 11:32:09 +1000 Subject: [PATCH 3/3] refactor: remove populate public key cache if needed call which seems unnecessary at that point, maybe UserView refs have changed since 2020 --- .../main/java/org/thoughtcrime/securesms/contacts/UserView.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt index 35e257fe84..72c9749f9b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt @@ -54,9 +54,6 @@ class UserView : LinearLayout { val contact = DatabaseComponent.get(context).sessionContactDatabase().getContactWithSessionID(publicKey) return contact?.displayName(Contact.ContactContext.REGULAR) ?: publicKey } - MessagingModuleConfiguration.shared.storage.getThreadId(user.address)?.let { threadID -> - MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded(threadID, context) // FIXME: This is a bad place to do this - } val address = user.address.serialize() binding.profilePictureView.root.glide = glide binding.profilePictureView.root.update(user)