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 threads empty state: Allow empty array for chunk in MXAggregationPaginatedResponse #1784

Merged
merged 3 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ + (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary
MXAggregationPaginatedResponse *paginatedResponse;

NSArray<MXEvent*> *chunk;
MXJSONModelSetMXJSONModelArray(chunk, MXEvent.class, JSONDictionary[@"chunk"])

NSArray *chunkJson = JSONDictionary[@"chunk"];

// For some reason modelsFromJSON returns nil if you pass it an empty array.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really a more sensible behaviour for modelsFromJSON would be to return an empty array if you pass it an empty array. But probably too risky a change, considering this repo is mostly deprecated, so just special-cased it here.

// In this case we want an empty array or we get an error.
if([chunkJson isKindOfClass:NSArray.class] && chunkJson.count == 0)
{
chunk = @[];
} else {
MXJSONModelSetMXJSONModelArray(chunk, MXEvent.class, chunkJson)
}

if (chunk)
{
paginatedResponse = [MXAggregationPaginatedResponse new];

paginatedResponse->_chunk = chunk;
MXJSONModelSetString(paginatedResponse->_nextBatch, JSONDictionary[@"next_batch"])

Expand Down
1 change: 1 addition & 0 deletions changelog.d/7551.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes a bug where an unhelpful message is shown rather than the threads empty state.