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

@ -824,7 +824,7 @@ fun Context.updateLastConversationMessage(threadId: Long) {
try {
contentResolver.delete(uri, selection, selectionArgs)
val newConversation = getConversations(threadId)[0]
conversationsDB.insertOrUpdate(newConversation)
insertOrUpdateConversation(newConversation)
} catch (e: Exception) {
}
}
@ -878,6 +878,18 @@ fun Context.subscriptionManagerCompat(): SubscriptionManager {
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 {
val updatedConv = conversation.copy(title = newTitle, usesCustomTitle = true)
try {