Avoid resetting conversation name in tmp threads
This commit is contained in:
parent
83cdf0f623
commit
c94b8852cd
3 changed files with 21 additions and 8 deletions
|
|
@ -878,11 +878,17 @@ fun Context.subscriptionManagerCompat(): SubscriptionManager {
|
|||
return getSystemService(SubscriptionManager::class.java)
|
||||
}
|
||||
|
||||
fun Context.insertOrUpdateConversation(conversation: Conversation) {
|
||||
val cachedConv = conversationsDB.getConversationWithThreadId(conversation.threadId)
|
||||
fun Context.insertOrUpdateConversation(
|
||||
conversation: Conversation,
|
||||
cachedConv: Conversation? = conversationsDB.getConversationWithThreadId(conversation.threadId)
|
||||
) {
|
||||
val updatedConv = if (cachedConv != null) {
|
||||
val usesCustomTitle = cachedConv.usesCustomTitle
|
||||
val title = if (usesCustomTitle) cachedConv.title else conversation.title
|
||||
val title = if (usesCustomTitle) {
|
||||
cachedConv.title
|
||||
} else {
|
||||
conversation.title
|
||||
}
|
||||
conversation.copy(title = title, usesCustomTitle = usesCustomTitle)
|
||||
} else {
|
||||
conversation
|
||||
|
|
@ -900,21 +906,27 @@ fun Context.renameConversation(conversation: Conversation, newTitle: String): Co
|
|||
return updatedConv
|
||||
}
|
||||
|
||||
fun Context.createTemporaryThread(message: Message, threadId: Long = generateRandomId()) {
|
||||
fun Context.createTemporaryThread(message: Message, threadId: Long = generateRandomId(), cachedConv: Conversation?) {
|
||||
val simpleContactHelper = SimpleContactsHelper(this)
|
||||
val addresses = message.participants.getAddresses()
|
||||
val photoUri = if (addresses.size == 1) simpleContactHelper.getPhotoUriFromPhoneNumber(addresses.first()) else ""
|
||||
val title = if (cachedConv != null && cachedConv.usesCustomTitle) {
|
||||
cachedConv.title
|
||||
} else {
|
||||
message.participants.getThreadTitle()
|
||||
}
|
||||
|
||||
val conversation = Conversation(
|
||||
threadId = threadId,
|
||||
snippet = message.body,
|
||||
date = message.date,
|
||||
read = true,
|
||||
title = message.participants.getThreadTitle(),
|
||||
title = title,
|
||||
photoUri = photoUri,
|
||||
isGroupConversation = addresses.size > 1,
|
||||
phoneNumber = addresses.first(),
|
||||
isScheduled = true
|
||||
isScheduled = true,
|
||||
usesCustomTitle = cachedConv?.usesCustomTitle == true
|
||||
)
|
||||
try {
|
||||
conversationsDB.insertOrUpdate(conversation)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue