forked from upstream-mirrors/quik
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:
@@ -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
|
||||
|
||||
}
|
||||
@@ -67,15 +67,15 @@ interface ConversationRepository {
|
||||
|
||||
fun getRecipient(recipientId: Long): Recipient?
|
||||
|
||||
fun getThreadId(recipient: String): Long?
|
||||
fun getConversation(recipient: String): Conversation?
|
||||
|
||||
fun getThreadId(recipients: Collection<String>): Long?
|
||||
fun getConversation(recipients: Collection<String>): Conversation?
|
||||
|
||||
fun getOrCreateConversation(threadId: Long): Conversation?
|
||||
|
||||
fun getOrCreateConversation(address: String): Conversation?
|
||||
|
||||
fun getOrCreateConversation(addresses: List<String>): Conversation?
|
||||
fun getOrCreateConversation(addresses: Collection<String>): Conversation?
|
||||
|
||||
fun saveDraft(threadId: Long, draft: String)
|
||||
|
||||
@@ -92,7 +92,7 @@ interface ConversationRepository {
|
||||
|
||||
fun markUnpinned(vararg threadIds: Long)
|
||||
|
||||
fun markBlocked(threadIds: List<Long>, blockingClient: Int, blockReason: String?)
|
||||
fun markBlocked(threadIds: Collection<Long>, blockingClient: Int, blockReason: String?)
|
||||
|
||||
fun markUnblocked(vararg threadIds: Long)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user