From c8dcf5691eb0114383d923988db61cd34aa8f01e Mon Sep 17 00:00:00 2001 From: giomfo Date: Thu, 3 Nov 2016 16:56:19 +0100 Subject: [PATCH 1/2] Converting existing rooms to/from DMs #715 Apply MatrixSDK changes (matrix-org/matrix-ios-sdk#158): Remove privateOneToOneRoomWithUserId: and privateOneToOneUsers (the developer must use the directRooms property instread). --- Vector/ViewController/ContactDetailsViewController.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Vector/ViewController/ContactDetailsViewController.m b/Vector/ViewController/ContactDetailsViewController.m index bc0c8d44e..56525779e 100644 --- a/Vector/ViewController/ContactDetailsViewController.m +++ b/Vector/ViewController/ContactDetailsViewController.m @@ -935,12 +935,14 @@ [self addPendingActionMask]; NSString *matrixId = self.firstMatrixId; - MXRoom* oneToOneRoom = [self.mainSession privateOneToOneRoomWithUserId:matrixId]; + + NSString *directRoomId = self.mainSession.directRooms[matrixId].firstObject; + MXRoom* directRoom = [self.mainSession roomWithRoomId:directRoomId]; // Place the call directly if the room exists - if (oneToOneRoom) + if (directRoom) { - [oneToOneRoom placeCallWithVideo:isVideoCall success:nil failure:nil]; + [directRoom placeCallWithVideo:isVideoCall success:nil failure:nil]; [self removePendingActionMask]; } else From 58769b1fc15f90da93d77489ce92de673ba9caa7 Mon Sep 17 00:00:00 2001 From: giomfo Date: Thu, 3 Nov 2016 18:12:08 +0100 Subject: [PATCH 2/2] Converting existing rooms to/from DMs #715 Use the new method added in MXSession API `directJoinedRoomWithUserId:`: returns the first joined direct chat listed in account data for this user. --- Vector/AppDelegate.m | 7 ++--- .../ContactDetailsViewController.m | 28 +++++++++++++------ .../RoomMemberDetailsViewController.m | 17 ++++++++--- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index d8ff042b5..3d93ffdde 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -1878,14 +1878,13 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN if (mxSession) { - NSArray *directRooms = mxSession.directRooms[userId]; - NSString *firstDirectRoomId = directRooms.firstObject; + MXRoom *directRoom = [mxSession directJoinedRoomWithUserId:userId]; // if the room exists - if (firstDirectRoomId) + if (directRoom) { // open it - [self showRoom:firstDirectRoomId andEventId:nil withMatrixSession:mxSession]; + [self showRoom:directRoom.roomId andEventId:nil withMatrixSession:mxSession]; if (completion) { diff --git a/Vector/ViewController/ContactDetailsViewController.m b/Vector/ViewController/ContactDetailsViewController.m index 56525779e..da45d78a9 100644 --- a/Vector/ViewController/ContactDetailsViewController.m +++ b/Vector/ViewController/ContactDetailsViewController.m @@ -65,7 +65,7 @@ /** List of the direct chats (room ids) with this contact. */ - NSArray *directChatsArray; + NSMutableArray *directChatsArray; NSInteger directChatsIndex; /** @@ -111,6 +111,7 @@ } actionsArray = [[NSMutableArray alloc] init]; + directChatsArray = [[NSMutableArray alloc] init]; // Setup `MXKViewControllerHandling` properties self.defaultBarTintColor = kVectorNavBarTintColor; @@ -517,7 +518,7 @@ NSInteger sectionCount = 0; [actionsArray removeAllObjects]; - directChatsArray = nil; + [directChatsArray removeAllObjects]; actionsIndex = directChatsIndex = -1; @@ -553,8 +554,6 @@ actionsIndex = sectionCount++; } - // Retrieve the existing direct chats - directChatsArray = self.mainSession.directRooms[matrixId]; directChatsIndex = sectionCount++; } // Else check whether the contact has been instantiated with an email or a matrix id @@ -564,11 +563,25 @@ } else if ([MXTools isMatrixUserIdentifier:_contact.displayName]) { - // Retrieve the existing direct chats - directChatsArray = self.mainSession.directRooms[_contact.displayName]; + matrixId = _contact.displayName; directChatsIndex = sectionCount++; } + if (matrixId.length) + { + // Retrieve the existing direct chats + NSArray *directRoomIds = self.mainSession.directRooms[matrixId]; + + // Check whether the room is still existing + for (NSString* directRoomId in directRoomIds) + { + if ([self.mainSession roomWithRoomId:directRoomId]) + { + [directChatsArray addObject:directRoomId]; + } + } + } + return sectionCount; } @@ -936,8 +949,7 @@ NSString *matrixId = self.firstMatrixId; - NSString *directRoomId = self.mainSession.directRooms[matrixId].firstObject; - MXRoom* directRoom = [self.mainSession roomWithRoomId:directRoomId]; + MXRoom* directRoom = [self.mainSession directJoinedRoomWithUserId:matrixId]; // Place the call directly if the room exists if (directRoom) diff --git a/Vector/ViewController/RoomMemberDetailsViewController.m b/Vector/ViewController/RoomMemberDetailsViewController.m index 234010c15..37eb45539 100644 --- a/Vector/ViewController/RoomMemberDetailsViewController.m +++ b/Vector/ViewController/RoomMemberDetailsViewController.m @@ -53,7 +53,7 @@ /** List of the direct chats (room ids) with this member. */ - NSArray *directChatsArray; + NSMutableArray *directChatsArray; NSInteger directChatsIndex; /** @@ -88,6 +88,7 @@ adminActionsArray = [[NSMutableArray alloc] init]; otherActionsArray = [[NSMutableArray alloc] init]; + directChatsArray = [[NSMutableArray alloc] init]; // Setup `MXKViewControllerHandling` properties self.defaultBarTintColor = kVectorNavBarTintColor; @@ -351,7 +352,7 @@ [adminActionsArray removeAllObjects]; [otherActionsArray removeAllObjects]; - directChatsArray = nil; + [directChatsArray removeAllObjects]; // Consider the case of the user himself if ([self.mxRoomMember.userId isEqualToString:self.mainSession.myUser.userId]) @@ -487,11 +488,19 @@ } // Retrieve the existing direct chats - directChatsArray = self.mainSession.directRooms[self.mxRoomMember.userId]; + NSArray *directRoomIds = self.mainSession.directRooms[self.mxRoomMember.userId]; + + // Check whether the room is still existing + for (NSString* directRoomId in directRoomIds) + { + if ([self.mainSession roomWithRoomId:directRoomId]) + { + [directChatsArray addObject:directRoomId]; + } + } adminToolsIndex = otherActionsIndex = directChatsIndex = -1; - if (otherActionsArray.count) { otherActionsIndex = sectionCount++;