Avoid resetting conversation name

This commit is contained in:
Naveen 2023-02-28 18:58:10 +05:30
parent 9dc5b30e80
commit 83cdf0f623
4 changed files with 17 additions and 7 deletions

View File

@ -307,10 +307,8 @@ class MainActivity : SimpleActivity() {
} }
if (conv != null) { if (conv != null) {
val lastModified = maxOf(cachedConv.date, conv.date) val lastModified = maxOf(cachedConv.date, conv.date)
val usesCustomTitle = cachedConv.usesCustomTitle val conversation = conv.copy(date = lastModified)
val title = if (usesCustomTitle) cachedConv.title else conv.title insertOrUpdateConversation(conversation)
val conversation = conv.copy(date = lastModified, title = title, usesCustomTitle = usesCustomTitle)
conversationsDB.insertOrUpdate(conversation)
} }
} }

View File

@ -824,7 +824,7 @@ fun Context.updateLastConversationMessage(threadId: Long) {
try { try {
contentResolver.delete(uri, selection, selectionArgs) contentResolver.delete(uri, selection, selectionArgs)
val newConversation = getConversations(threadId)[0] val newConversation = getConversations(threadId)[0]
conversationsDB.insertOrUpdate(newConversation) insertOrUpdateConversation(newConversation)
} catch (e: Exception) { } catch (e: Exception) {
} }
} }
@ -878,6 +878,18 @@ fun Context.subscriptionManagerCompat(): SubscriptionManager {
return getSystemService(SubscriptionManager::class.java) return getSystemService(SubscriptionManager::class.java)
} }
fun Context.insertOrUpdateConversation(conversation: Conversation) {
val cachedConv = conversationsDB.getConversationWithThreadId(conversation.threadId)
val updatedConv = if (cachedConv != null) {
val usesCustomTitle = cachedConv.usesCustomTitle
val title = if (usesCustomTitle) cachedConv.title else conversation.title
conversation.copy(title = title, usesCustomTitle = usesCustomTitle)
} else {
conversation
}
conversationsDB.insertOrUpdate(updatedConv)
}
fun Context.renameConversation(conversation: Conversation, newTitle: String): Conversation { fun Context.renameConversation(conversation: Conversation, newTitle: String): Conversation {
val updatedConv = conversation.copy(title = newTitle, usesCustomTitle = true) val updatedConv = conversation.copy(title = newTitle, usesCustomTitle = true)
try { try {

View File

@ -41,7 +41,7 @@ class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() {
context.showReceivedMessageNotification(address, mms.body, mms.threadId, glideBitmap) context.showReceivedMessageNotification(address, mms.body, mms.threadId, glideBitmap)
val conversation = context.getConversations(mms.threadId).firstOrNull() ?: return@post val conversation = context.getConversations(mms.threadId).firstOrNull() ?: return@post
ensureBackgroundThread { ensureBackgroundThread {
context.conversationsDB.insertOrUpdate(conversation) context.insertOrUpdateConversation(conversation)
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations()) context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
refreshMessages() refreshMessages()
} }

View File

@ -67,7 +67,7 @@ class SmsReceiver : BroadcastReceiver() {
val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread val conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread
try { try {
context.conversationsDB.insertOrUpdate(conversation) context.insertOrUpdateConversation(conversation)
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }