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

fix: messages list IndexOutOfBoundsException [WPB-5612] #2457

Merged
merged 2 commits into from
Nov 23, 2023

Conversation

saleniuk
Copy link
Contributor

@saleniuk saleniuk commented Nov 23, 2023

BugWPB-5612 java.lang.IndexOutOfBoundsException:


PR Submission Checklist for internal contributors

  • The PR Title

    • conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    • contains a reference JIRA issue number like SQPIT-764
    • answers the question: If merged, this PR will: ... ³
  • The PR Description

    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

What's new in this PR?

Issues

We were getting IndexOutOfBoundsException when opening conversation screen.

Causes (Optional)

shouldHaveSmallBottomPadding didn't have any limit, only index > 0, but index could be higher than the items count and that's what was happening, because lazyPagingMessages.itemSnapshotList.items is a list of only presented data, excluding placeholders. It was working fine when the app was always fetching messages starting from the most recent one, but in case the user has multiple unread messages or opens the conversation from the message search, the app may fetch not the last page but can start from the middle and then indexes don't match.

For instance, if we have 100 total messages, page size is 20 and we have 30 unread messages, then the initially loaded batch should have first unread message, so it should contain for instance messages 20 to 39. ItemSnapshotList will have size of 100 (all available messages) and these fetched already elements will be at their proper indexes 20 to 39, all other elements are placeholders and they will be null, but ItemSnapshotList.items only contains these 20 non-null elements with indexes starting from 0 to 19, because it's just a sublist, and we can easily have IndexOutOfBounds when we want to get item with index 30 from that sublist, and items don't match - itemSnapshotList.items[10] is not the same item as itemSnapshotList[10] so the list could look wrong.

Solutions

Get elements using their indexes from the itemSnapshotList instead of itemSnapshotList.items, use derivedStateOf to reduce number of recompositions and remember with keys to update value of shouldHaveSmallBottomPadding or shouldShowHeader when a neighbouring element is no longer a placeholder.
The whole list was also recomposing when scrolling, so it could be reduced as well by creating dedicated states for isScrollInProgress and mostRecentMessage using derivedStateOf.

Testing

Test Coverage (Optional)

  • I have added automated test to this contribution

How to Test

Have a lot of unread messages, like more than 50, and open conversation - it shouldn't crash and each message should look properly (without avatar, header and with small paddings in between if they are grouped messages from the same user).


PR Post Submission Checklist for internal contributors (Optional)

  • Wire's Github Workflow has automatically linked the PR to a JIRA issue

PR Post Merge Checklist for internal contributors

  • If any soft of configuration variable was introduced by this PR, it has been added to the relevant documents and the CI jobs have been updated.

References
  1. https://sparkbox.com/foundry/semantic_commit_messages
  2. https://github.com/wireapp/.github#usage
  3. E.g. feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764.

Copy link
Contributor

github-actions bot commented Nov 23, 2023

Test Results

691 tests   691 ✔️  9m 37s ⏱️
  98 suites      0 💤
  98 files        0

Results for commit d3a5a91.

♻️ This comment has been updated with latest results.

Copy link
Contributor

APKs built during tests are available here. Scroll down to Artifacts!

@saleniuk saleniuk requested review from Garzas, a team, typfel, borichellow, MohamadJaara and mchenani and removed request for a team November 23, 2023 11:01
@AndroidBob
Copy link
Collaborator

Build 1952 succeeded.

The build produced the following APK's:

Copy link
Contributor

@yamilmedina yamilmedina left a comment

Choose a reason for hiding this comment

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

Awesome test coverage ! 👏

@saleniuk saleniuk merged commit 52fbaac into release/candidate Nov 23, 2023
14 checks passed
@saleniuk saleniuk deleted the fix/messages_indexoutofboundsexception branch November 23, 2023 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants