From e1c9e5ac0780d627690c1914bb76e642bfb3bc04 Mon Sep 17 00:00:00 2001 From: David Langley Date: Thu, 18 May 2023 16:36:06 +0100 Subject: [PATCH] allow empty array for chunk in MXAggregationPaginatedResponse --- .../Aggregations/MXAggregationPaginatedResponse.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m b/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m index 19625d7d65..ad57f26d04 100644 --- a/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m +++ b/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m @@ -35,12 +35,18 @@ + (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary MXAggregationPaginatedResponse *paginatedResponse; NSArray *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"])