mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 16:22:39 +00:00
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:
parent
cfc3627434
commit
06bc9e4866
5 changed files with 37 additions and 37 deletions
|
@ -78,16 +78,12 @@ typedef enum : NSUInteger {
|
||||||
// return a MatrixIDs list of 1:1 room members
|
// return a MatrixIDs list of 1:1 room members
|
||||||
- (NSArray*)oneToOneRoomMemberMatrixIDs;
|
- (NSArray*)oneToOneRoomMemberMatrixIDs;
|
||||||
|
|
||||||
// search if a private room has been started with this user
|
// Searches if a private OneToOne room has been started with this user
|
||||||
// returns the room ID
|
// Returns the room ID (nil if not found)
|
||||||
// nil if not found
|
- (NSString*)privateOneToOneRoomIdWithUserId:(NSString*)userId;
|
||||||
- (NSString*) privateRoomIdWith:(NSString*)otherMatrixID;
|
|
||||||
|
|
||||||
// check first if there no room between the both users
|
// Reopens an existing private OneToOne room with this userId or creates a new one (if it doesn't exist)
|
||||||
// if there is one, open it
|
- (void)startPrivateOneToOneRoomWithUserId:(NSString*)userId;
|
||||||
// else create a new one
|
|
||||||
// create a private one to one chat room
|
|
||||||
- (void)startPrivateOneToOneRoomWith:(NSString*)otherMatrixID;
|
|
||||||
|
|
||||||
// the pushes could have disabled for a dedicated room
|
// the pushes could have disabled for a dedicated room
|
||||||
// reenable them
|
// reenable them
|
||||||
|
|
|
@ -682,32 +682,38 @@ static MatrixSDKHandler *sharedHandler = nil;
|
||||||
return matrixIDs;
|
return matrixIDs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// search if a private room has been started with this user
|
- (NSString*)privateOneToOneRoomIdWithUserId:(NSString*)userId {
|
||||||
// returns the room ID
|
|
||||||
// nil if not found
|
|
||||||
- (NSString*) privateRoomIdWith:(NSString*)otherMatrixID {
|
|
||||||
//
|
|
||||||
if (self.mxSession) {
|
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]];
|
NSArray *recentEvents = [NSMutableArray arrayWithArray:[self.mxSession recentsWithTypeIn:self.eventsFilterForMessages]];
|
||||||
|
|
||||||
// loops
|
// Loops
|
||||||
for (MXEvent *mxEvent in recentEvents) {
|
for (MXEvent *mxEvent in recentEvents) {
|
||||||
// get the dedicated mxRooms
|
// Get the dedicated mxRooms
|
||||||
MXRoom *mxRoom = [self.mxSession roomWithRoomId:mxEvent.roomId];
|
MXRoom *mxRoom = [self.mxSession roomWithRoomId:mxEvent.roomId];
|
||||||
|
|
||||||
// accept only room with 2 users
|
// Consider only private room with 2 users
|
||||||
if (mxRoom.state.members.count == 2) {
|
if (!mxRoom.state.isPublic && mxRoom.state.members.count == 2) {
|
||||||
NSArray* roomMembers = mxRoom.state.members;
|
NSArray* roomMembers = mxRoom.state.members;
|
||||||
|
|
||||||
|
// Check whether the provided userId is one of them
|
||||||
|
MXRoomMember* member = nil;
|
||||||
MXRoomMember* member1 = [roomMembers objectAtIndex:0];
|
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 (member) {
|
||||||
if (
|
// Check the membership of this member (Indeed the room should be ignored if the member left it)
|
||||||
([member1.userId isEqualToString:self.mxSession.myUser.userId] || [member1.userId isEqualToString:otherMatrixID]) &&
|
if (member.membership != MXMembershipLeave && member.membership != MXMembershipBan) {
|
||||||
([member2.userId isEqualToString:self.mxSession.myUser.userId] || [member2.userId isEqualToString:otherMatrixID])) {
|
// We found the right room
|
||||||
return mxRoom.state.roomId;
|
return mxRoom.state.roomId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -716,10 +722,9 @@ static MatrixSDKHandler *sharedHandler = nil;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a private one to one chat room
|
- (void)startPrivateOneToOneRoomWithUserId:(NSString*)userId {
|
||||||
- (void)startPrivateOneToOneRoomWith:(NSString*)otherMatrixID {
|
|
||||||
if (self.mxRestClient) {
|
if (self.mxRestClient) {
|
||||||
NSString* roomId = [self privateRoomIdWith:otherMatrixID];
|
NSString* roomId = [self privateOneToOneRoomIdWithUserId:userId];
|
||||||
|
|
||||||
// if the room exists
|
// if the room exists
|
||||||
if (roomId) {
|
if (roomId) {
|
||||||
|
@ -732,13 +737,12 @@ static MatrixSDKHandler *sharedHandler = nil;
|
||||||
roomAlias:nil
|
roomAlias:nil
|
||||||
topic:nil
|
topic:nil
|
||||||
success:^(MXCreateRoomResponse *response) {
|
success:^(MXCreateRoomResponse *response) {
|
||||||
|
|
||||||
// invite the other user only if it is defined and not onself
|
// 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
|
// add the user
|
||||||
[self.mxRestClient inviteUser:otherMatrixID toRoom:response.roomId success:^{
|
[self.mxRestClient inviteUser:userId toRoom:response.roomId success:^{
|
||||||
} failure:^(NSError *error) {
|
} failure:^(NSError *error) {
|
||||||
NSLog(@"%@ invitation failed (roomId: %@): %@", otherMatrixID, response.roomId, error);
|
NSLog(@"%@ invitation failed (roomId: %@): %@", userId, response.roomId, error);
|
||||||
//Alert user
|
//Alert user
|
||||||
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||||
}];
|
}];
|
||||||
|
|
|
@ -109,7 +109,7 @@
|
||||||
|
|
||||||
if ([view isKindOfClass:[ContactDetailsTableCell class]]) {
|
if ([view isKindOfClass:[ContactDetailsTableCell class]]) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[[MatrixSDKHandler sharedHandler] startPrivateOneToOneRoomWith:((ContactDetailsTableCell*)view).matrixUserIDLabel.text];
|
[[MatrixSDKHandler sharedHandler] startPrivateOneToOneRoomWithUserId:((ContactDetailsTableCell*)view).matrixUserIDLabel.text];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
[self.startChatMenu addActionWithTitle:@"OK" style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) {
|
||||||
weakSelf.startChatMenu = nil;
|
weakSelf.startChatMenu = nil;
|
||||||
|
|
||||||
[mxHandler startPrivateOneToOneRoomWith:matrixID];
|
[mxHandler startPrivateOneToOneRoomWithUserId:matrixID];
|
||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
self.startChatMenu = [[MXCAlert alloc] initWithTitle:[NSString stringWithFormat:@"Chat with "] message:nil style:MXCAlertStyleActionSheet];
|
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) {
|
[self.startChatMenu addActionWithTitle:matrixID style:MXCAlertActionStyleDefault handler:^(MXCAlert *alert) {
|
||||||
weakSelf.startChatMenu = nil;
|
weakSelf.startChatMenu = nil;
|
||||||
|
|
||||||
[mxHandler startPrivateOneToOneRoomWith:matrixID];
|
[mxHandler startPrivateOneToOneRoomWithUserId:matrixID];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -301,7 +301,7 @@
|
||||||
|
|
||||||
// offer to start a new chat only if the room is not a 1:1 room with this user
|
// 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
|
// 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]) {
|
if (![roomId isEqualToString:mxRoom.state.roomId]) {
|
||||||
[buttonsTitles addObject:@"Chat"];
|
[buttonsTitles addObject:@"Chat"];
|
||||||
}
|
}
|
||||||
|
@ -499,7 +499,7 @@
|
||||||
|
|
||||||
} else if ([text isEqualToString:@"Chat"]) {
|
} else if ([text isEqualToString:@"Chat"]) {
|
||||||
[self addPendingActionMask];
|
[self addPendingActionMask];
|
||||||
[[MatrixSDKHandler sharedHandler] startPrivateOneToOneRoomWith:_mxRoomMember.userId];
|
[[MatrixSDKHandler sharedHandler] startPrivateOneToOneRoomWithUserId:_mxRoomMember.userId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue