forked from upstream-mirrors/quik
#1079 - Can't send or receive new messages on HTC and Huawei devices
This commit is contained in:
@@ -103,6 +103,23 @@ class ConversationRepositoryImpl @Inject constructor(
|
|||||||
.findFirst()
|
.findFirst()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getThreadId(recipient: String): Long? {
|
||||||
|
return getThreadId(listOf(recipient))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getThreadId(recipients: Collection<String>): Long? {
|
||||||
|
return Realm.getDefaultInstance().use { realm ->
|
||||||
|
realm.where(Conversation::class.java)
|
||||||
|
.findAll()
|
||||||
|
.firstOrNull { conversation ->
|
||||||
|
conversation.recipients.size == recipients.size && conversation.recipients.map { it.address }.all { address ->
|
||||||
|
recipients.any { recipient -> PhoneNumberUtils.compare(recipient, address) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getOrCreateConversation(threadId: Long): Conversation? {
|
override fun getOrCreateConversation(threadId: Long): Conversation? {
|
||||||
return getConversation(threadId) ?: getConversationFromCp(threadId)
|
return getConversation(threadId) ?: getConversationFromCp(threadId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ interface ConversationRepository {
|
|||||||
|
|
||||||
fun getConversation(threadId: Long): Conversation?
|
fun getConversation(threadId: Long): Conversation?
|
||||||
|
|
||||||
|
fun getThreadId(recipient: String): Long?
|
||||||
|
|
||||||
|
fun getThreadId(recipients: Collection<String>): Long?
|
||||||
|
|
||||||
fun getOrCreateConversation(threadId: Long): Conversation?
|
fun getOrCreateConversation(threadId: Long): Conversation?
|
||||||
|
|
||||||
fun getOrCreateConversation(address: String): Conversation?
|
fun getOrCreateConversation(address: String): Conversation?
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ import model.Contact
|
|||||||
import model.Conversation
|
import model.Conversation
|
||||||
import model.Message
|
import model.Message
|
||||||
import model.PhoneNumber
|
import model.PhoneNumber
|
||||||
import model.Recipient
|
|
||||||
import repository.ContactRepository
|
import repository.ContactRepository
|
||||||
import repository.ConversationRepository
|
import repository.ConversationRepository
|
||||||
import repository.MessageRepository
|
import repository.MessageRepository
|
||||||
@@ -101,6 +100,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
private val contacts: Observable<List<Contact>> by lazy { contactsRepo.getUnmanagedContacts().toObservable() }
|
private val contacts: Observable<List<Contact>> by lazy { contactsRepo.getUnmanagedContacts().toObservable() }
|
||||||
private val contactsReducer: Subject<(List<Contact>) -> List<Contact>> = PublishSubject.create()
|
private val contactsReducer: Subject<(List<Contact>) -> List<Contact>> = PublishSubject.create()
|
||||||
private val selectedContacts: Subject<List<Contact>> = BehaviorSubject.createDefault(listOf())
|
private val selectedContacts: Subject<List<Contact>> = BehaviorSubject.createDefault(listOf())
|
||||||
|
private val threadIdSubject: Subject<Long> = BehaviorSubject.create()
|
||||||
private val searchResults: Subject<List<Message>> = BehaviorSubject.create()
|
private val searchResults: Subject<List<Message>> = BehaviorSubject.create()
|
||||||
private val searchSelection: Subject<Long> = BehaviorSubject.createDefault(-1)
|
private val searchSelection: Subject<Long> = BehaviorSubject.createDefault(-1)
|
||||||
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
||||||
@@ -119,16 +119,14 @@ class ComposeViewModel @Inject constructor(
|
|||||||
.map { contacts -> contacts.map { it.numbers.firstOrNull()?.address ?: "" } }
|
.map { contacts -> contacts.map { it.numbers.firstOrNull()?.address ?: "" } }
|
||||||
.doOnNext { newState { copy(loading = true) } }
|
.doOnNext { newState { copy(loading = true) } }
|
||||||
.observeOn(Schedulers.computation())
|
.observeOn(Schedulers.computation())
|
||||||
.map { addresses -> Pair(TelephonyCompat.getOrCreateThreadId(context, addresses), addresses) }
|
.map { addresses -> conversationRepo.getThreadId(addresses) ?: 0 }
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.doOnNext { newState { copy(loading = false) } }
|
.doOnNext { newState { copy(loading = false) } }
|
||||||
.switchMap { (threadId, addresses) ->
|
.mergeWith(threadIdSubject)
|
||||||
val recipients = RealmList(*addresses.map { address -> Recipient(address = address) }.toTypedArray())
|
.switchMap { threadId ->
|
||||||
conversationRepo.getConversations().asObservable()
|
conversationRepo.getConversations().asObservable()
|
||||||
.map { conversations -> conversations.filter { it.id == threadId } }
|
.map { conversations -> conversations.filter { it.id == threadId } }
|
||||||
.map { conversations ->
|
.map { conversations -> conversations.firstOrNull() ?: Conversation(id = threadId) }
|
||||||
conversations.firstOrNull() ?: Conversation(id = threadId, recipients = recipients)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.mergeWith(initialConversation)
|
.mergeWith(initialConversation)
|
||||||
.filter { conversation -> conversation.isLoaded }
|
.filter { conversation -> conversation.isLoaded }
|
||||||
@@ -531,14 +529,18 @@ class ComposeViewModel @Inject constructor(
|
|||||||
|
|
||||||
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
||||||
view.sendIntent
|
view.sendIntent
|
||||||
.withLatestFrom(view.textChangedIntent, { _, body -> body })
|
.withLatestFrom(view.textChangedIntent) { _, body -> body }
|
||||||
.map { body -> body.toString() }
|
.map { body -> body.toString() }
|
||||||
.withLatestFrom(state, attachments, conversation, selectedContacts, { body, state, attachments, conversation, contacts ->
|
.withLatestFrom(state, attachments, conversation, selectedContacts, { body, state, attachments, conversation, contacts ->
|
||||||
val subId = state.subscription?.subscriptionId ?: -1
|
val subId = state.subscription?.subscriptionId ?: -1
|
||||||
|
|
||||||
if (state.sendAsGroup) {
|
if (state.sendAsGroup) {
|
||||||
val threadId = conversation.id
|
val addresses = when (conversation.recipients.isNotEmpty()) {
|
||||||
val addresses = conversation.recipients.map { it.address }
|
true -> conversation.recipients.map { it.address }
|
||||||
|
false -> contacts.mapNotNull { it.numbers.firstOrNull()?.address }
|
||||||
|
}
|
||||||
|
val threadId = conversation.id.takeIf { it > 0 }
|
||||||
|
?: TelephonyCompat.getOrCreateThreadId(context, addresses).also(threadIdSubject::onNext)
|
||||||
sendMessage.execute(SendMessage.Params(subId, threadId, addresses, body, attachments))
|
sendMessage.execute(SendMessage.Params(subId, threadId, addresses, body, attachments))
|
||||||
} else {
|
} else {
|
||||||
contacts
|
contacts
|
||||||
|
|||||||
Reference in New Issue
Block a user