From 77b78e81f2374b96f2b80531d1bec0dfdfafe633 Mon Sep 17 00:00:00 2001 From: David Langley Date: Thu, 18 May 2023 16:32:26 +0100 Subject: [PATCH 1/3] allow empty array for chunk in MXAggregationPaginatedResponse --- changelog.d/7551.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7551.bugfix diff --git a/changelog.d/7551.bugfix b/changelog.d/7551.bugfix new file mode 100644 index 0000000000..71dbd80c5b --- /dev/null +++ b/changelog.d/7551.bugfix @@ -0,0 +1 @@ +Fixes a bug where an unhelpful message is shown rather than the threads empty state. \ No newline at end of file From e1c9e5ac0780d627690c1914bb76e642bfb3bc04 Mon Sep 17 00:00:00 2001 From: David Langley Date: Thu, 18 May 2023 16:36:06 +0100 Subject: [PATCH 2/3] 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"]) From 3287d5cda65e692084940f5823597d120251b44c Mon Sep 17 00:00:00 2001 From: David Langley Date: Thu, 18 May 2023 16:46:18 +0100 Subject: [PATCH 3/3] this probably makes more sense --- .../Aggregations/MXAggregationPaginatedResponse.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m b/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m index ad57f26d04..576e5327d4 100644 --- a/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m +++ b/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m @@ -36,12 +36,14 @@ + (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary NSArray *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]) + if([chunkJson isKindOfClass:NSArray.class] && chunkJson.count == 0) { chunk = @[]; + } else { + MXJSONModelSetMXJSONModelArray(chunk, MXEvent.class, chunkJson) } if (chunk)