Skip to content

Commit

Permalink
allow empty array for chunk in MXAggregationPaginatedResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
langleyd committed May 18, 2023
1 parent 77b78e8 commit e1c9e5a
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ + (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary
MXAggregationPaginatedResponse *paginatedResponse;

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

NSArray *chunkJson = JSONDictionary[@"chunk"];
MXJSONModelSetMXJSONModelArray(chunk, MXEvent.class, chunkJson)
// 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(!chunk && [chunkJson isKindOfClass:NSArray.class])
{
chunk = @[];
}

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

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

Expand Down

0 comments on commit e1c9e5a

Please sign in to comment.