Moving db calls out of the main thread

pull/1713/head
ThomasSession 1 month ago
parent 1dc88125c6
commit e404fb964f

@ -15,8 +15,8 @@ configurations.configureEach {
exclude module: "commons-logging" exclude module: "commons-logging"
} }
def canonicalVersionCode = 398 def canonicalVersionCode = 399
def canonicalVersionName = "1.21.2" def canonicalVersionName = "1.21.3"
def postFixSize = 10 def postFixSize = 10
def abiPostFix = ['armeabi-v7a' : 1, def abiPostFix = ['armeabi-v7a' : 1,

@ -641,7 +641,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
if (author != null && messageTimestamp >= 0) { if (author != null && messageTimestamp >= 0) {
jumpToMessage(author, messageTimestamp, firstLoad.get(), null) jumpToMessage(author, messageTimestamp, firstLoad.get(), null)
} else { } else {
if (firstLoad.getAndSet(false)) scrollToFirstUnreadMessageIfNeeded(true) if (firstLoad.getAndSet(false)) {
lifecycleScope.launch(Dispatchers.Main) {
scrollToFirstUnreadMessageIfNeeded(true)
}
}
handleRecyclerViewScrolled() handleRecyclerViewScrolled()
} }
} }
@ -972,9 +976,13 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
} }
} }
private fun scrollToFirstUnreadMessageIfNeeded(isFirstLoad: Boolean = false, shouldHighlight: Boolean = false): Int { private suspend fun scrollToFirstUnreadMessageIfNeeded(isFirstLoad: Boolean = false, shouldHighlight: Boolean = false): Int {
val lastSeenItemPosition = withContext(Dispatchers.Default) {
val lastSeenTimestamp = threadDb.getLastSeenAndHasSent(viewModel.threadId).first() val lastSeenTimestamp = threadDb.getLastSeenAndHasSent(viewModel.threadId).first()
val lastSeenItemPosition = adapter.findLastSeenItemPosition(lastSeenTimestamp) ?: return -1 adapter.findLastSeenItemPosition(lastSeenTimestamp)
}
if(lastSeenItemPosition == null) return -1
// If this is triggered when first opening a conversation then we want to position the top // If this is triggered when first opening a conversation then we want to position the top
// of the first unread message in the middle of the screen // of the first unread message in the middle of the screen

Loading…
Cancel
Save