From 6e039fa9df227b336ebf8823df3de2d24c008b9c Mon Sep 17 00:00:00 2001 From: manuroe Date: Wed, 10 Jul 2019 08:18:45 +0200 Subject: [PATCH] Edits history: Expose the new original event field https://github.com/vector-im/riot-ios/issues/2559 --- .../Aggregations/MXAggregationPaginatedResponse.h | 3 +++ .../Aggregations/MXAggregationPaginatedResponse.m | 2 ++ MatrixSDKTests/MXAggregatedEditsTests.m | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.h b/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.h index c45a3d83ae..3fadd3a110 100644 --- a/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.h +++ b/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.h @@ -26,6 +26,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSArray *chunk; @property (nonatomic, readonly, nullable) NSString *nextBatch; +// TODO: Make it non null when homeservers support it +@property (nonatomic, readonly, nullable) MXEvent *originalEvent; + @end NS_ASSUME_NONNULL_END diff --git a/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m b/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m index 38904d6631..9fad1f7182 100644 --- a/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m +++ b/MatrixSDK/JSONModels/Aggregations/MXAggregationPaginatedResponse.m @@ -31,6 +31,8 @@ + (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary paginatedResponse->_chunk = chunk; MXJSONModelSetString(paginatedResponse->_nextBatch, JSONDictionary[@"next_batch"]) + + MXJSONModelSetMXJSONModel(paginatedResponse->_originalEvent, MXEvent.class, JSONDictionary[@"original_event"]) } return paginatedResponse; diff --git a/MatrixSDKTests/MXAggregatedEditsTests.m b/MatrixSDKTests/MXAggregatedEditsTests.m index 3c5687cc77..07573b2ebf 100644 --- a/MatrixSDKTests/MXAggregatedEditsTests.m +++ b/MatrixSDKTests/MXAggregatedEditsTests.m @@ -895,8 +895,10 @@ - (void)addEdits:(NSUInteger)editsCount toEvent:(NSString*)eventId inRoom:(MXRoo // - Edit the message 10 more times // - Paginate one edit // -> We must get an edit event and a nextBatch +// -> We must get the original event // - Paginate more // -> We must get all other edit events and no more nextBatch +// -> We must get the original event - (void)testEditsHistory { // - Run the initial condition scenario @@ -913,6 +915,11 @@ - (void)testEditsHistory XCTAssertTrue(paginatedResponse.chunk.firstObject.isEditEvent); XCTAssertNotNil(paginatedResponse.nextBatch); + // -> We must get the original event + XCTAssertNotNil(paginatedResponse.originalEvent); + XCTAssertEqualObjects(paginatedResponse.originalEvent.eventId, eventId); + XCTAssertEqualObjects(paginatedResponse.originalEvent.content[@"body"], kOriginalMessageText); + // - Paginate more [mxSession.aggregations replaceEventsForEvent:eventId isEncrypted:NO inRoom:room.roomId from:paginatedResponse.nextBatch limit:20 success:^(MXAggregationPaginatedResponse *paginatedResponse) { @@ -926,6 +933,11 @@ - (void)testEditsHistory XCTAssertTrue(event.isEditEvent); } + // -> We must get the original event + XCTAssertNotNil(paginatedResponse.originalEvent); + XCTAssertEqualObjects(paginatedResponse.originalEvent.eventId, eventId); + XCTAssertEqualObjects(paginatedResponse.originalEvent.content[@"body"], kOriginalMessageText); + [expectation fulfill]; } failure:^(NSError *error) {