From d0d7626db4fdffc53e7cb04dbcfe79f5ce23610f Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Mon, 16 Sep 2024 14:47:58 +1000 Subject: [PATCH] Moving the heavy lifting code in a coroutine to help with ANRs --- .../conversation/v2/ConversationActivityV2.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index c7d1304266..aa4f7167e7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -1785,10 +1785,21 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe attachmentManager.clear() // Reset attachments button if needed if (isShowingAttachmentOptions) { toggleAttachmentOptions() } - // Put the message in the database - message.id = mmsDb.insertMessageOutbox(outgoingTextMessage, viewModel.threadId, false, null, runThreadUpdate = true) - // Send it - MessageSender.send(message, recipient.address, attachments, quote, linkPreview) + + // do the heavy work in the bg + lifecycleScope.launch(Dispatchers.IO) { + // Put the message in the database + message.id = mmsDb.insertMessageOutbox( + outgoingTextMessage, + viewModel.threadId, + false, + null, + runThreadUpdate = true + ) + // Send it + MessageSender.send(message, recipient.address, attachments, quote, linkPreview) + } + // Send a typing stopped message ApplicationContext.getInstance(this).typingStatusSender.onTypingStopped(viewModel.threadId) return Pair(recipient.address, sentTimestamp)