Skip to content

Commit

Permalink
Merge pull request #1784 from matrix-org/langleyd/7551_fix_threads_em…
Browse files Browse the repository at this point in the history
…pty_state

Fix threads empty state: Allow empty array for chunk in MXAggregationPaginatedResponse
  • Loading branch information
langleyd authored May 19, 2023
2 parents ddb0682 + 3287d5c commit 258bdb8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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.
// 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.

0 comments on commit 258bdb8

Please sign in to comment.