Reduce frequency of calls to find last sent message

pull/1484/head
Al Lansley 2 months ago committed by Andrew
parent 4bef09a3c1
commit c312c27dd3

@ -372,6 +372,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
private var currentLastVisibleRecyclerViewIndex: Int = RecyclerView.NO_POSITION
private var recyclerScrollState: Int = RecyclerView.SCROLL_STATE_IDLE
// region Settings
companion object {
// Extras
@ -387,6 +388,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
const val PICK_FROM_LIBRARY = 12
const val INVITE_CONTACTS = 124
var lastSentMessageId = -1L;
}
// endregion
@ -513,6 +515,9 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
viewModel.run {
binding?.toolbarContent?.update(recipient ?: return, openGroup, expirationConfiguration)
}
// Update our last sent message Id on startup / resume (resume is called after onCreate)
lastSentMessageId = mmsSmsDb.getLastOutgoingMessage(viewModel.threadId)
}
override fun onPause() {
@ -2221,6 +2226,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
// to the bottom of long messages as required by Jira SES-789 / GitHub 1364).
recyclerView.scrollToPosition(adapter.itemCount)
}
// Update our cached last sent message to ensure we have accurate details.
// Note: This `onChanged` method is not triggered when scrolling so should minimally
// affect performance.
lastSentMessageId = mmsSmsDb.getLastOutgoingMessage(viewModel.threadId)
}
}

@ -59,7 +59,8 @@ class ConversationAdapter(
private val contactCache = SparseArray<Contact>(100)
private val contactLoadedCache = SparseBooleanArray(100)
private val lastSeen = AtomicLong(originalLastSeen)
private var lastSentMessageId: Long = -1L
//private var lastSentMessageId: Long = -1L
init {
lifecycleCoroutineScope.launch(IO) {
@ -241,11 +242,6 @@ class ConversationAdapter(
toDeselect.iterator().forEach { (pos, record) ->
onDeselect(record, pos)
}
// This value gets updated here ONLY when the cursor changes, and the value is then passed
// through to `VisibleMessageView.bind` each time we bind via `onBindItemViewHolder`, above.
// If there are no messages then lastSentMessageId is assigned the value -1L.
if (cursor != null) { lastSentMessageId = getLastSentMessageId(cursor) }
}
fun findLastSeenItemPosition(lastSeenTimestamp: Long): Int? {

@ -302,7 +302,8 @@ class VisibleMessageView : LinearLayout {
// --- If we got here then we know the message is outgoing ---
val lastSentMessageId = mmsSmsDb.getLastOutgoingMessage(message.threadId)
//val lastSentMessageId = mmsSmsDb.getLastOutgoingMessage(message.threadId)
val lastSentMessageId = ConversationActivityV2.lastSentMessageId;
val isLastSentMessage = lastSentMessageId == message.id
// ----- Case ii.) Message is outgoing but NOT scheduled to disappear -----

Loading…
Cancel
Save