change compose sendintent (sending sms/mms) and sendmessage interactor to ensure convos congruency

change compose selectedconversation (chips -> convo monitoring) to take advantage of changes in conversationrepo
conversationrepo change getthreadid to getconversation to avoid duplicate db access
some cleanups and refactoring in conversationrepo
This commit is contained in:
gavine99
2025-04-07 14:52:04 +10:00
parent 27a836324e
commit 821b02ad58
6 changed files with 402 additions and 471 deletions
@@ -19,8 +19,6 @@
package dev.octoshrimpy.quik.interactor
import android.content.Context
import dev.octoshrimpy.quik.compat.TelephonyCompat
import dev.octoshrimpy.quik.extensions.mapNotNull
import dev.octoshrimpy.quik.model.Attachment
import dev.octoshrimpy.quik.repository.ConversationRepository
import dev.octoshrimpy.quik.repository.MessageRepository
@@ -44,29 +42,29 @@ class SendMessage @Inject constructor(
)
override fun buildObservable(params: Params): Flowable<*> = Flowable.just(Unit)
.filter { params.addresses.isNotEmpty() }
.doOnNext {
// If a threadId isn't provided, try to obtain one
val threadId = when (params.threadId) {
0L -> TelephonyCompat.getOrCreateThreadId(context, params.addresses.toSet())
else -> params.threadId
}
messageRepo.sendMessage(params.subId, threadId, params.addresses, params.body, params.attachments,
params.delay)
.filter { params.addresses.isNotEmpty() }
.doOnNext {
// If a threadId isn't provided, try to obtain one
val threadId = when (params.threadId) {
0L -> conversationRepo.getOrCreateConversation(params.addresses)?.id ?: 0
else -> params.threadId
}
// delete attachment local files, if any, because they're saved to mms db by now
params.attachments.forEach { it.removeCacheFile() }
// if unable to find or create a conversation (and/or underlying threadId), fail
if (threadId == 0L)
return@doOnNext
params.apply {
messageRepo.sendMessage(subId, threadId, addresses, body, attachments, delay)
}
.mapNotNull {
// If the threadId wasn't provided, then it's probably because it doesn't exist in Realm.
// Sync it now and get the id
when (params.threadId) {
0L -> conversationRepo.getOrCreateConversation(params.addresses)?.id
else -> params.threadId
}
}
.doOnNext { threadId -> conversationRepo.updateConversations(threadId) }
.doOnNext { threadId -> conversationRepo.markUnarchived(threadId) }
.flatMap { updateBadge.buildObservable(Unit) } // Update the widget
conversationRepo.updateConversations(threadId)
conversationRepo.markUnarchived(threadId)
// delete attachment local files, if any, because they're saved to mms db by now
params.attachments.forEach { it.removeCacheFile() }
}
.flatMap { updateBadge.buildObservable(Unit) } // Update the widget
}