Skip to content

Commit

Permalink
MXEventTimeline: The roomEventFilter property is now writable
Browse files Browse the repository at this point in the history
  • Loading branch information
manuroe committed Aug 26, 2019
1 parent 2cf678c commit 412ead7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Improvements:
* MXServiceTerms: A class to support MSC2140 (Terms of Service API) (vector-im/riot-ios#2600).
* MXRestClient: Remove Identity Server URL fallback to homeserver one's when there is no Identity Server configured.
* MXHTTPClient: Improve M_LIMIT_EXCEEDED error handling: Do not wait to try again if the mentioned delay is too long.
* MXEventTimeline: The roomEventFilter property is now writable (vector-im/riot-ios#2615).

Changes in Matrix iOS SDK in 0.13.1 (2019-08-08)
===============================================
Expand Down
3 changes: 2 additions & 1 deletion MatrixSDK/Data/Filters/MXRoomEventFilter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2016 OpenMarket Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -22,7 +23,7 @@
/**
`MXRoomEventFilter` defines a room event filter which may be used during Matrix requests.
*/
@interface MXRoomEventFilter : MXFilterObject;
@interface MXRoomEventFilter : MXFilterObject <NSCopying>

/**
If YES, includes only events with a url key in their content. If NO, excludes those events.
Expand Down
9 changes: 9 additions & 0 deletions MatrixSDK/Data/Filters/MXRoomEventFilter.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2016 OpenMarket Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -137,4 +138,12 @@ - (BOOL)lazyLoadMembers
return lazyLoadMembers;
}


#pragma mark - NSCopying

- (id)copyWithZone:(NSZone *)zone
{
return [[MXRoomEventFilter alloc] initWithDictionary:self.dictionary];
}

@end
8 changes: 7 additions & 1 deletion MatrixSDK/Data/MXEventTimeline.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2016 OpenMarket Ltd
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,8 +75,13 @@ typedef void (^MXOnRoomEvent)(MXEvent *event, MXTimelineDirection direction, MXR

/**
The room events filter which is applied during the history pagination.
The default value can be nil. It depends if the lazy loading of room members
is enabled or not.
The filter can be modified but only before starting paginating, ie before calling one
the resetPagination methods.
*/
@property (nonatomic, readonly) MXRoomEventFilter *roomEventFilter;
@property (nonatomic, copy) MXRoomEventFilter *roomEventFilter;

/**
The state of the room at the top most recent event of the timeline.
Expand Down
52 changes: 52 additions & 0 deletions MatrixSDKTests/MXEventTimelineTests.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2016 OpenMarket Ltd
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -376,4 +377,55 @@ - (void)testForwardPaginationOnPastTimeline

}

/*
Test custom MXEventTimeline.roomEventFilter
- Run the initial condition scenario
- Set a custom filter on the live timeline
- Paginate all messages in one request
-> We must not receive filtered events
*/
- (void)testRoomEventFilter
{
// - Run the initial condition scenario
[self doTestWithARoomOf41Messages:self readyToTest:^(MXRoom *room, XCTestExpectation *expectation, NSString *initialEventId) {

[room liveTimeline:^(MXEventTimeline *liveTimeline) {

__block NSUInteger eventCount = 0;

// - Set a custom filter on the live timeline
MXRoomEventFilter *filter = liveTimeline.roomEventFilter;
if (!filter)
{
filter = [MXRoomEventFilter new];
}
filter.notTypes = @[kMXEventTypeStringRoomCreate, kMXEventTypeStringRoomMember];

liveTimeline.roomEventFilter = filter;

// - Paginate all messages in one request
[liveTimeline resetPagination];
[liveTimeline paginate:100 direction:MXTimelineDirectionBackwards onlyFromStore:NO complete:^{

XCTAssertGreaterThan(eventCount, 41, "We should get at least all messages events from the pagination");
[expectation fulfill];

} failure:^(NSError *error) {
XCTFail(@"The operation should not fail - NSError: %@", error);
[expectation fulfill];
}];

[liveTimeline listenToEvents:^(MXEvent *event, MXTimelineDirection direction, MXRoomState *roomState) {
eventCount++;

// -> We must not receive filtered events
XCTAssertNotEqualObjects(event.type, kMXEventTypeStringRoomCreate);
XCTAssertNotEqualObjects(event.type, kMXEventTypeStringRoomMember);
}];

}];
}];
}


@end

0 comments on commit 412ead7

Please sign in to comment.