From 8760d85d2b0dead90098721cb9973f6a751a6924 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 18 May 2020 23:28:17 +0200 Subject: [PATCH] recognize private contacts at the thread screen too --- .../smsmessenger/activities/ThreadActivity.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index 4bbe932e..05752f48 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -30,10 +30,7 @@ import com.klinker.android.send_message.Settings import com.klinker.android.send_message.Transaction import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.PERMISSION_READ_PHONE_STATE -import com.simplemobiletools.commons.helpers.SimpleContactsHelper -import com.simplemobiletools.commons.helpers.ensureBackgroundThread -import com.simplemobiletools.commons.helpers.isNougatPlus +import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.adapters.AutoCompleteTextViewAdapter @@ -89,6 +86,7 @@ class ThreadActivity : SimpleActivity() { } private fun setupThread() { + val privateCursor = getMyContactsContentProviderCursorLoader().loadInBackground() ensureBackgroundThread { messages = getMessages(threadId) participants = if (messages.isEmpty()) { @@ -97,6 +95,14 @@ class ThreadActivity : SimpleActivity() { messages.first().participants } + // check if no participant came from a privately stored contact in Simple Contacts + val privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor) + participants.filter { it.name == it.phoneNumber }.forEach { participant -> + privateContacts.firstOrNull { it.phoneNumber == participant.phoneNumber }?.apply { + participant.name = name + } + } + if (participants.isEmpty()) { val name = intent.getStringExtra(THREAD_TITLE) ?: "" val number = intent.getStringExtra(THREAD_NUMBER)