mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
check if no message came from a privately stored contact in Simple Contacts
This commit is contained in:
@@ -144,8 +144,19 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun initMessenger() {
|
private fun initMessenger() {
|
||||||
storeStateVariables()
|
storeStateVariables()
|
||||||
|
val privateCursor = getMyContactsContentProviderCursorLoader().loadInBackground()
|
||||||
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val conversations = getConversations()
|
val conversations = getConversations()
|
||||||
|
|
||||||
|
// check if no message came from a privately stored contact in Simple Contacts
|
||||||
|
val privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||||
|
conversations.filter { it.title == it.phoneNumber }.forEach { conversation ->
|
||||||
|
privateContacts.firstOrNull { it.phoneNumber == conversation.phoneNumber }?.apply {
|
||||||
|
conversation.title = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
val hasConversations = conversations.isNotEmpty()
|
val hasConversations = conversations.isNotEmpty()
|
||||||
conversations_list.beVisibleIf(hasConversations)
|
conversations_list.beVisibleIf(hasConversations)
|
||||||
|
@@ -186,6 +186,7 @@ fun Context.getConversations(): ArrayList<Conversation> {
|
|||||||
val selection = "${Threads.MESSAGE_COUNT} > ?"
|
val selection = "${Threads.MESSAGE_COUNT} > ?"
|
||||||
val selectionArgs = arrayOf("0")
|
val selectionArgs = arrayOf("0")
|
||||||
val sortOrder = "${Threads.DATE} DESC"
|
val sortOrder = "${Threads.DATE} DESC"
|
||||||
|
|
||||||
val conversations = ArrayList<Conversation>()
|
val conversations = ArrayList<Conversation>()
|
||||||
queryCursor(uri, projection, selection, selectionArgs, sortOrder, true) { cursor ->
|
queryCursor(uri, projection, selection, selectionArgs, sortOrder, true) { cursor ->
|
||||||
val id = cursor.getIntValue(Threads._ID)
|
val id = cursor.getIntValue(Threads._ID)
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
package com.simplemobiletools.smsmessenger.models
|
package com.simplemobiletools.smsmessenger.models
|
||||||
|
|
||||||
data class Conversation(
|
data class Conversation(
|
||||||
val id: Int, val snippet: String, val date: Int, val read: Boolean, val title: String, val photoUri: String,
|
val id: Int, val snippet: String, val date: Int, val read: Boolean, var title: String, val photoUri: String,
|
||||||
val isGroupConversation: Boolean, val phoneNumber: String)
|
val isGroupConversation: Boolean, val phoneNumber: String)
|
||||||
|
Reference in New Issue
Block a user