Console: BugFix - "Start chat with one of my contact opened an existing one to one room with this contact, but the contact had left the room".

--> We check now member's status before reusing existing room.
This commit is contained in:
giomfo 2015-02-13 15:16:30 +01:00
parent cfc3627434
commit 06bc9e4866
5 changed files with 37 additions and 37 deletions

View file

@ -78,16 +78,12 @@ typedef enum : NSUInteger {
// return a MatrixIDs list of 1:1 room members
- (NSArray*)oneToOneRoomMemberMatrixIDs;
// search if a private room has been started with this user
// returns the room ID
// nil if not found
- (NSString*) privateRoomIdWith:(NSString*)otherMatrixID;
// Searches if a private OneToOne room has been started with this user
// Returns the room ID (nil if not found)
- (NSString*)privateOneToOneRoomIdWithUserId:(NSString*)userId;
// check first if there no room between the both users
// if there is one, open it
// else create a new one
// create a private one to one chat room
- (void)startPrivateOneToOneRoomWith:(NSString*)otherMatrixID;
// Reopens an existing private OneToOne room with this userId or creates a new one (if it doesn't exist)
- (void)startPrivateOneToOneRoomWithUserId:(NSString*)userId;
// the pushes could have disabled for a dedicated room
// reenable them

View file

@ -682,32 +682,38 @@ static MatrixSDKHandler *sharedHandler = nil;
return matrixIDs;
}
// search if a private room has been started with this user
// returns the room ID
// nil if not found
- (NSString*) privateRoomIdWith:(NSString*)otherMatrixID {
//
- (NSString*)privateOneToOneRoomIdWithUserId:(NSString*)userId {
if (self.mxSession) {
// list the last messages of each room to get the rooms list
// List the last messages of each room to get the rooms list in chronological order
NSArray *recentEvents = [NSMutableArray arrayWithArray:[self.mxSession recentsWithTypeIn:self.eventsFilterForMessages]];
// loops
// Loops
for (MXEvent *mxEvent in recentEvents) {
// get the dedicated mxRooms
// Get the dedicated mxRooms
MXRoom *mxRoom = [self.mxSession roomWithRoomId:mxEvent.roomId];
// accept only room with 2 users
if (mxRoom.state.members.count == 2) {
// Consider only private room with 2 users
if (!mxRoom.state.isPublic && mxRoom.state.members.count == 2) {
NSArray* roomMembers = mxRoom.state.members;
// Check whether the provided userId is one of them
MXRoomMember* member = nil;
MXRoomMember* member1 = [roomMembers objectAtIndex:0];
MXRoomMember* member2 = [roomMembers objectAtIndex:1];
if ([member1.userId isEqualToString:userId]) {
member = member1;
} else {
MXRoomMember* member2 = [roomMembers objectAtIndex:1];
if ([member2.userId isEqualToString:userId]) {
member = member2;
}
}
// check if they are the dedicated users
if (
([member1.userId isEqualToString:self.mxSession.myUser.userId] || [member1.userId isEqualToString:otherMatrixID]) &&
([member2.userId isEqualToString:self.mxSession.myUser.userId] || [member2.userId isEqualToString:otherMatrixID])) {
return mxRoom.state.roomId;
if (member) {
// Check the membership of this member (Indeed the room should be ignored if the member left it)
if (member.membership != MXMembershipLeave && member.membership != MXMembershipBan) {
// We found the right room
return mxRoom.state.roomId;
}
}
}
}
@ -716,10 +722,9 @@ static MatrixSDKHandler *sharedHandler = nil;
return nil;
}
// create a private one to one chat room
- (void)startPrivateOneToOneRoomWith:(NSString*)otherMatrixID {
- (void)startPrivateOneToOneRoomWithUserId:(NSString*)userId {
if (self.mxRestClient) {
NSString* roomId = [self privateRoomIdWith:otherMatrixID];
NSString* roomId = [self privateOneToOneRoomIdWithUserId:userId];
// if the room exists
if (roomId) {
@ -732,13 +737,12 @@ static MatrixSDKHandler *sharedHandler = nil;
roomAlias:nil
topic:nil
success:^(MXCreateRoomResponse *response) {
// invite the other user only if it is defined and not onself
if (otherMatrixID && ![self.userId isEqualToString:otherMatrixID]) {
if (userId && ![self.userId isEqualToString:userId]) {
// add the user
[self.mxRestClient inviteUser:otherMatrixID toRoom:response.roomId success:^{
[self.mxRestClient inviteUser:userId toRoom:response.roomId success:^{
} failure:^(NSError *error) {
NSLog(@"%@ invitation failed (roomId: %@): %@", otherMatrixID, response.roomId, error);
NSLog(@"%@ invitation failed (roomId: %@): %@", userId, response.roomId, error);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];

View file

@ -109,7 +109,7 @@
if ([view isKindOfClass:[ContactDetailsTableCell class]]) {
dispatch_async(dispatch_get_main_queue(), ^{
[[MatrixSDKHandler sharedHandler] startPrivateOneToOneRoomWith:((ContactDetailsTableCell*)view).matrixUserIDLabel.text];
[[MatrixSDKHandler sharedHandler] startPrivateOneToOneRoomWithUserId:((ContactDetailsTableCell*)view).matrixUserIDLabel.text];
});
}
}

View file

@ -442,7 +442,7 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl
[self.startChatMenu addActionWithTitle:@"OK" style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) {
weakSelf.startChatMenu = nil;
[mxHandler startPrivateOneToOneRoomWith:matrixID];
[mxHandler startPrivateOneToOneRoomWithUserId:matrixID];
}];
} else {
self.startChatMenu = [[MXCAlert alloc] initWithTitle:[NSString stringWithFormat:@"Chat with "] message:nil style:MXCAlertStyleActionSheet];
@ -451,7 +451,7 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl
[self.startChatMenu addActionWithTitle:matrixID style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) {
weakSelf.startChatMenu = nil;
[mxHandler startPrivateOneToOneRoomWith:matrixID];
[mxHandler startPrivateOneToOneRoomWithUserId:matrixID];
}];
}

View file

@ -301,7 +301,7 @@
// offer to start a new chat only if the room is not a 1:1 room with this user
// it does not make sense : it would open the same room
NSString* roomId = [mxHandler privateRoomIdWith:_mxRoomMember.userId];
NSString* roomId = [mxHandler privateOneToOneRoomIdWithUserId:_mxRoomMember.userId];
if (![roomId isEqualToString:mxRoom.state.roomId]) {
[buttonsTitles addObject:@"Chat"];
}
@ -499,7 +499,7 @@
} else if ([text isEqualToString:@"Chat"]) {
[self addPendingActionMask];
[[MatrixSDKHandler sharedHandler] startPrivateOneToOneRoomWith:_mxRoomMember.userId];
[[MatrixSDKHandler sharedHandler] startPrivateOneToOneRoomWithUserId:_mxRoomMember.userId];
}
}
}