-
Notifications
You must be signed in to change notification settings - Fork 26
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: reusing PagingData crash [WPB-15055][WPB-15079][WPB-15064] #3758
base: release/candidate
Are you sure you want to change the base?
Conversation
Quality Gate passedIssues Measures |
Built wire-android-staging-compat-pr-3758.apk is available for download |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good and very nice catch! Just a small suggestion
private fun observeSelfUserLegalHoldState() { | ||
viewModelScope.launch { | ||
observeLegalHoldStateForSelfUser() | ||
.map { it is LegalHoldStateForSelfUser.Enabled } | ||
.flowOn(dispatcher.io()) | ||
.collect { isSelfUserUnderLegalHoldFlow.emit(it) } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having a separate fun
with collect you can have:
val isSelfUserUnderLegalHoldFlow = observeLegalHoldStateForSelfUser()
.map { it is LegalHoldStateForSelfUser.Enabled }
.flowOn(dispatcher.io())
.shareIn(viewModelScope, SharingStarted.WhileSubscribed(), 1)
isSearchActive = it[0], | ||
searchQueryTextState = searchQueryTextState | ||
isSearchActive = it[0] as Boolean, | ||
searchQueryTextState = it[1]?.let { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Are there chances of getting an IndexOutOfBounds
here ? Asking just in case we can make it safer (for example using a Pair instead of a List?), otherwise it looks good to me.
PR Submission Checklist for internal contributors
The PR Title
SQPIT-764
The PR Description
What's new in this PR?
Issues
There are crashes related to reusing
PagingData
flow when doing some actions on paginated conversation list screen, like accepting legal hold request, answering 1:1 call or opening pending connection request which can fetch user data.Causes (Optional)
Each action that modifies (or even puts the same exact data but just requires executing insert, update or delete query) a table that then affects paginated conversation list query, makes this query dirty and executes it again, which reloads the list.
When using
combine
, it creates a new instance of flow, so if thecombine
is used afterPagingData
is created then if the data is changed and emitted by the flow that's combined, it will re-use the samePagingData
and put it into a new flow, socachedIn
won't cache the flow properly and it will crash becausePagingData
cannot be used twice.Solutions
Move
combine
"above" thePagingData
flow so that each time a new value is emitted, it will always create a newPagingData
for the new flow and alsocachedIn
will be used correctly.Make use of changes in kalium that doesn't execute upsert queries for User and Client if actually there's no new data so that it doesn't notify other queries - in this case paginated conversation list query thus the query doesn't get dirty and doesn't need to be executed again.
Simplify
showLoading
parameter to be a simple logical equation rather than a state. Make use of mockedpreviewConversationFoldersFlow
with properLoadStates
to represent loaded data instead of using specificinitiallyLoaded
parameter.Fix
rememberSearchbarState
so that it actually saves thesearchQueryTextState
.Dependencies (Optional)
Needs releases with:
Testing
Test Coverage (Optional)
How to Test
The crash was happening when opening pending connection request (most frequently), answering 1:1 call or accepting legal hold request, so these actions shouldn't crash the app. Also, after opening connection request or 1:1 conversation, if your or that user's data hasn't changed since the last fetch, then it shouldn't refresh the conversation list when navigating back.
Attachments (Optional)
refreshing_when_going_back.mp4
no_refreshing_when_going_back.mp4
pagination_crash.mp4
PR Post Submission Checklist for internal contributors (Optional)
PR Post Merge Checklist for internal contributors
References
feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764
.