Skip to content

Commit

Permalink
Merge branch 'release/0.22.6/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderas committed Mar 14, 2022
2 parents 8568c45 + 2ace3b7 commit 707e703
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Changes in 0.22.6 (2022-03-14)

🙌 Improvements

- Room: API to ignore the sender of a room invite before the room is joined ([#5807](https://github.com/vector-im/element-ios/issues/5807))


## Changes in 0.22.5 (2022-03-08)

🙌 Improvements
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MatrixSDK"
s.version = "0.22.5"
s.version = "0.22.6"
s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)"

s.description = <<-DESC
Expand Down
17 changes: 17 additions & 0 deletions MatrixSDK/Data/MXRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ FOUNDATION_EXPORT NSString *const kMXRoomDidFlushDataNotification;
*/
FOUNDATION_EXPORT NSInteger const kMXRoomAlreadyJoinedErrorCode;

/**
Error code when attempting to use a room invite sender which is invalid.
*/
FOUNDATION_EXPORT NSInteger const kMXRoomInvalidInviteSenderErrorCode;

/**
`MXRoom` is the class
*/
Expand Down Expand Up @@ -777,6 +782,18 @@ FOUNDATION_EXPORT NSInteger const kMXRoomAlreadyJoinedErrorCode;
- (MXHTTPOperation*)leave:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;

/**
Ignore the user who sent the invite to this room. This user is then added to the current
user's ignore list.
@param success A block object called when the operation is complete.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)ignoreInviteSender:(void (^)(void))success
failure:(void (^)(NSError *error))failure;

/**
Invite a user to this room.
Expand Down
19 changes: 19 additions & 0 deletions MatrixSDK/Data/MXRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
NSString *const kMXRoomDidFlushDataNotification = @"kMXRoomDidFlushDataNotification";
NSString *const kMXRoomInitialSyncNotification = @"kMXRoomInitialSyncNotification";
NSInteger const kMXRoomAlreadyJoinedErrorCode = 9001;
NSInteger const kMXRoomInvalidInviteSenderErrorCode = 9002;

@interface MXRoom ()
{
Expand Down Expand Up @@ -1896,6 +1897,24 @@ - (MXHTTPOperation*)leave:(void (^)(void))success
return [mxSession leaveRoom:self.roomId success:success failure:failure];
}

- (MXHTTPOperation*)ignoreInviteSender:(void (^)(void))success
failure:(void (^)(NSError *))failure {
MXHTTPOperation *operation = [[MXHTTPOperation alloc] init];
[self state:^(MXRoomState *roomState) {
MXRoomMember *myUser = [roomState.members memberWithUserId:self.mxSession.myUserId];
NSString *inviteSenderID = myUser.originalEvent.sender;
if (!inviteSenderID || [inviteSenderID isEqualToString:myUser.userId]) {
NSError *error = [NSError errorWithDomain:kMXNSErrorDomain code:kMXRoomInvalidInviteSenderErrorCode userInfo:nil];
failure(error);
return;
}

MXHTTPOperation *operation2 = [self.mxSession ignoreUsers:@[inviteSenderID] success:success failure:failure];
[operation mutateTo:operation2];
}];
return operation;
}

- (MXHTTPOperation*)inviteUser:(NSString*)userId
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/MatrixSDKVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

#import <Foundation/Foundation.h>

NSString *const MatrixSDKVersion = @"0.22.5";
NSString *const MatrixSDKVersion = @"0.22.6";
46 changes: 46 additions & 0 deletions MatrixSDKTests/MXRoomTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,52 @@ - (void)testLeave
}];
}

- (void)testIgnoreInviteSender
{
[matrixSDKTestsData doMXRestClientTestWithBobAndARoom:self readyToTest:^(MXRestClient *bobClient, NSString *roomId, XCTestExpectation *expectation) {

[matrixSDKTestsData doMXRestClientTestWithAlice:nil readyToTest:^(MXRestClient *aliceClient, XCTestExpectation *expectation2) {

MXSession *mxSession = [[MXSession alloc] initWithMatrixRestClient:aliceClient];
[matrixSDKTestsData retain:mxSession];

[bobClient inviteUser:aliceClient.credentials.userId toRoom:roomId success:^{
[mxSession startWithSyncFilter:[MXFilterJSONModel syncFilterWithMessageLimit:0]
onServerSyncDone:^{

MXRoom *room = [mxSession roomWithRoomId:roomId];
XCTAssertEqual(mxSession.ignoredUsers.count, 0);
XCTAssertEqual([mxSession isUserIgnored:bobClient.credentials.userId], NO);

// Listen to mxSession.ignoredUsers changes where the successful assertion happens
[[NSNotificationCenter defaultCenter] addObserverForName:kMXSessionIgnoredUsersDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull notif) {
if (notif.object == mxSession)
{
XCTAssertEqual(mxSession.ignoredUsers.count, 1);
XCTAssertEqual([mxSession isUserIgnored:bobClient.credentials.userId], YES);

[expectation fulfill];
}
}];

[room ignoreInviteSender:nil failure:^(NSError *error) {
XCTFail(@"Failed to ignore invite sender - NSError: %@", error);
[expectation fulfill];
}];

} failure:^(NSError *error) {;
XCTFail(@"Cannot set up intial test conditions - error: %@", error);
[expectation fulfill];
}];

} failure:^(NSError *error) {
XCTFail(@"Cannot set up intial test conditions - error: %@", error);
[expectation fulfill];
}];
}];
}];
}

- (void)testJoin
{
[matrixSDKTestsData doMXRestClientTestWithBobAndARoom:self readyToTest:^(MXRestClient *bobRestClient, NSString *roomId, XCTestExpectation *expectation) {
Expand Down

0 comments on commit 707e703

Please sign in to comment.