Fixing ANRs

release/1.20.1
ThomasSession 7 months ago
parent 3d42a04823
commit b237faa21d

@ -58,6 +58,7 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -1737,10 +1738,19 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
binding.inputBar.text = "" binding.inputBar.text = ""
binding.inputBar.cancelQuoteDraft() binding.inputBar.cancelQuoteDraft()
binding.inputBar.cancelLinkPreviewDraft() binding.inputBar.cancelLinkPreviewDraft()
lifecycleScope.launch(Dispatchers.Default) {
// Put the message in the database // Put the message in the database
message.id = smsDb.insertMessageOutbox(viewModel.threadId, outgoingTextMessage, false, message.sentTimestamp!!, null, true) message.id = smsDb.insertMessageOutbox(
viewModel.threadId,
outgoingTextMessage,
false,
message.sentTimestamp!!,
null,
true
)
// Send it // Send it
MessageSender.send(message, recipient.address) MessageSender.send(message, recipient.address)
}
// Send a typing stopped message // Send a typing stopped message
ApplicationContext.getInstance(this).typingStatusSender.onTypingStopped(viewModel.threadId) ApplicationContext.getInstance(this).typingStatusSender.onTypingStopped(viewModel.threadId)
return Pair(recipient.address, sentTimestamp) return Pair(recipient.address, sentTimestamp)

@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.home.search
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.BufferOverflow
@ -13,11 +14,13 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.buffer import kotlinx.coroutines.flow.buffer
import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.plus import kotlinx.coroutines.plus
import kotlinx.coroutines.withContext
import org.thoughtcrime.securesms.search.SearchRepository import org.thoughtcrime.securesms.search.SearchRepository
import org.thoughtcrime.securesms.search.model.SearchResult import org.thoughtcrime.securesms.search.model.SearchResult
import javax.inject.Inject import javax.inject.Inject
@ -38,9 +41,14 @@ class GlobalSearchViewModel @Inject constructor(
.buffer(onBufferOverflow = BufferOverflow.DROP_OLDEST) .buffer(onBufferOverflow = BufferOverflow.DROP_OLDEST)
.mapLatest { query -> .mapLatest { query ->
if (query.trim().isEmpty()) { if (query.trim().isEmpty()) {
withContext(Dispatchers.Default) {
// searching for 05 as contactDb#getAllContacts was not returning contacts // searching for 05 as contactDb#getAllContacts was not returning contacts
// without a nickname/name who haven't approved us. // without a nickname/name who haven't approved us.
GlobalSearchResult(query.toString(), searchRepository.queryContacts("05").first.toList()) GlobalSearchResult(
query.toString(),
searchRepository.queryContacts("05").first.toList()
)
}
} else { } else {
// User input delay in case we get a new query within a few hundred ms this // User input delay in case we get a new query within a few hundred ms this
// coroutine will be cancelled and the expensive query will not be run. // coroutine will be cancelled and the expensive query will not be run.

Loading…
Cancel
Save