Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When expanding a long Thread, display Messages by batches so it doesn't freeze the UI anymore #2044

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

KevinBoulongne
Copy link
Contributor

@KevinBoulongne KevinBoulongne commented Sep 12, 2024

In the situation of a Thread long enough so we display the SuperCollapsedBlock :

  • When clicking on the SCB, we have to display all remaining Messages.
  • Instead of displaying all of them in one go, we loop them and send them 1 by 1 every few milliseconds.

@@ -73,6 +73,7 @@ class ThreadViewModel @Inject constructor(

val threadLive = MutableLiveData<Thread?>()
val messagesLive = MutableLiveData<Pair<ThreadAdapterItems, MessagesWithoutHeavyData>>()
val batchedMessages = SingleLiveEvent<List<Any>>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having to rely in SingleLiveEvent can't we have a live data that represents the list of all loaded messages? This way we can listen in a straight forward manner to the list of messages, when the list updates, we submit the new list. The logic to delay the loading can then be handle on its own independently and the logic is not split depending on if we have more or less messages than ThreadViewModel.SUPER_COLLAPSED_BLOCK_MINIMUM_MESSAGES_LIMIT

Comment on lines 417 to 421
if (items.count() > ThreadViewModel.SUPER_COLLAPSED_BLOCK_MINIMUM_MESSAGES_LIMIT) {
displayBatchedMessages(items)
} else {
threadAdapter.submitList(items)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can displayBatchedMessages() handle both cases inside by having the method automatically do less than SUPER_COLLAPSED_BLOCK_MINIMUM_MESSAGES_LIMIT if there's not enough items left?

Copy link

sonarcloud bot commented Sep 20, 2024

@LunarX
Copy link
Contributor

LunarX commented Sep 20, 2024

Why do we do all of this again though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants