mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Don't accept invaild conversations, access conversation on main thread
This commit is contained in:
@@ -19,6 +19,7 @@ import com.moez.QKSMS.data.model.InboxItem
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.functions.BiFunction
|
||||
import io.reactivex.rxkotlin.toFlowable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
@@ -77,7 +78,6 @@ class MessageRepository @Inject constructor(
|
||||
|
||||
fun getOrCreateConversation(addresses: List<String>): Maybe<Conversation> {
|
||||
return Maybe.just(addresses)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.map { recipients ->
|
||||
recipients.map { address ->
|
||||
when (MessageUtils.isEmailAddress(address)) {
|
||||
@@ -103,6 +103,8 @@ class MessageRepository @Inject constructor(
|
||||
conversation ?: getConversationFromCp(threadId)?.apply { insertOrUpdate() } ?: Conversation()
|
||||
}
|
||||
.onErrorReturn { Conversation() }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
fun getMessages(threadId: Long): RealmResults<Message> {
|
||||
|
||||
@@ -59,7 +59,6 @@ class ComposeViewModel(threadId: Long, body: String)
|
||||
|
||||
// Map the selected contacts to a conversation so that we can display the message history
|
||||
val selectedConversation = selectedContacts
|
||||
.observeOn(Schedulers.computation())
|
||||
.map { contacts -> contacts.map { it.numbers.firstOrNull()?.address ?: "" } }
|
||||
.flatMapMaybe { addresses -> messageRepo.getOrCreateConversation(addresses) }
|
||||
|
||||
@@ -72,9 +71,9 @@ class ComposeViewModel(threadId: Long, body: String)
|
||||
newState { it.copy(hasError = true) }
|
||||
}
|
||||
}
|
||||
.filter { conversation -> conversation.isValid }
|
||||
.take(1)
|
||||
.mergeWith(selectedConversation)
|
||||
.filter { conversation -> conversation.isValid }
|
||||
.filter { conversation -> conversation.id != 0L }
|
||||
.distinctUntilChanged()
|
||||
.doOnNext { conversation ->
|
||||
newState { it.copy(title = conversation.getTitle(), archived = conversation.archived) }
|
||||
|
||||
Reference in New Issue
Block a user