From 88df216daa71f6e567734a0935da18e77e0ea1d1 Mon Sep 17 00:00:00 2001 From: manuroe Date: Wed, 8 Jun 2016 17:01:01 +0200 Subject: [PATCH 1/6] BF: Release room data source created to display messages in the past --- Vector/ViewController/HomeViewController.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m index 416703e5b..64184b4ac 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -399,12 +399,13 @@ if (_currentRoomViewController) { - if (_currentRoomViewController.roomDataSource && _currentRoomViewController.roomDataSource.isLive) + if (_currentRoomViewController.roomDataSource) { - // Let the manager release this live room data source MXSession *mxSession = _currentRoomViewController.roomDataSource.mxSession; MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession]; - [roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:NO]; + + // Let the manager release this live room data source + [roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:!_currentRoomViewController.roomDataSource.isLive]; } [_currentRoomViewController destroy]; @@ -621,7 +622,8 @@ } else { - [_currentRoomViewController displayRoomPreview:_selectedRoomPreviewData]; + [_currentRoomViewController displayRoom:_selectedRoomPreviewData.roomDataSource]; + //[_currentRoomViewController displayRoomPreview:_selectedRoomPreviewData]; _selectedRoomPreviewData = nil; } } From d60501b5308de4ff1798bbe74297aaa9ffaaf32f Mon Sep 17 00:00:00 2001 From: manuroe Date: Wed, 8 Jun 2016 18:02:22 +0200 Subject: [PATCH 2/6] Room messages preview: Updated RoomPreviewData to use MXPeekingRoom --- Vector/AppDelegate.m | 2 +- Vector/Model/Room/RoomPreviewData.h | 20 ++++++++--------- Vector/Model/Room/RoomPreviewData.m | 22 +++++++++---------- Vector/ViewController/HomeViewController.m | 6 ++--- Vector/Views/RoomTitle/PreviewRoomTitleView.m | 6 ++--- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index f74b9530b..cbae3cd75 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -1043,7 +1043,7 @@ NSString *const kAppDelegateDidTapStatusBarNotification = @"kAppDelegateDidTapSt roomPreviewData.eventId = (pathParams.count >= 3) ? pathParams[2] : nil; // Try to get more information about the room before opening its preview - [roomPreviewData fetchPreviewData:^(BOOL successed) { + [roomPreviewData peekInRoom:^(BOOL successed) { // Note: the activity indicator will not disappear if the session is not ready [_homeViewController stopActivityIndicator]; diff --git a/Vector/Model/Room/RoomPreviewData.h b/Vector/Model/Room/RoomPreviewData.h index 90bbc530c..90b2c9198 100644 --- a/Vector/Model/Room/RoomPreviewData.h +++ b/Vector/Model/Room/RoomPreviewData.h @@ -18,6 +18,7 @@ #import "RoomEmailInvitation.h" #import "MXSession.h" +#import "RoomDataSource.h" /** The `RoomEmailInvitation` gathers information for displaying the preview of a @@ -57,11 +58,10 @@ @property (nonatomic, readonly) NSString *roomAvatarUrl; /** - A snapshot of the room state. - Note: This ivar may be replaced by a RoomDataSource ivar when the room preview will be - fully implemented. + The RoomDataSource to peek into the room. + Note: this object is creating when [self peekInRoom:] succeeds. */ -@property (nonatomic, readonly) MXRoomState *roomState; +@property (nonatomic, readonly) RoomDataSource *roomDataSource; /** Contructors. @@ -74,14 +74,14 @@ - (instancetype)initWithRoomId:(NSString*)roomId emailInvitationParams:(NSDictionary*)emailInvitationParams andSession:(MXSession*)mxSession; /** - Attempt to get more information from the homeserver about the room. + Attempt to peek into room to get room data (state, messages history, etc). + + The operation succeeds only if the room history is world_readable. - NOTE: This method is temporary while we do not support the full room preview - with preview of messages. - @param completion the block called when the request is complete. `successed` means - the homeserver provided some information. + the self.roomDataSource has been created and is ready to provide + room history. */ -- (void)fetchPreviewData:(void (^)(BOOL successed))completion; +- (void)peekInRoom:(void (^)(BOOL successed))completion; @end diff --git a/Vector/Model/Room/RoomPreviewData.m b/Vector/Model/Room/RoomPreviewData.m index 70f5e669b..da22b3628 100644 --- a/Vector/Model/Room/RoomPreviewData.m +++ b/Vector/Model/Room/RoomPreviewData.m @@ -43,22 +43,20 @@ return self; } -- (void)fetchPreviewData:(void (^)(BOOL))completion +- (void)peekInRoom:(void (^)(BOOL successed))completion { - // Make an /initialSync request to get preview data - [_mxSession.matrixRestClient initialSyncOfRoom:_roomId withLimit:0 success:^(MXRoomInitialSync *roomInitialSync) { + [_mxSession peekInRoomWithRoomId:_roomId success:^(MXPeekingRoom *peekingRoom) { - _roomState = [[MXRoomState alloc] initWithRoomId:_roomId andMatrixSession:_mxSession andDirection:YES]; + // Create the room data source + // It will be automatically released when the RoomViewController that displays it will disappear + _roomDataSource = [[RoomDataSource alloc] initWithPeekingRoom:peekingRoom AndInitialEventId:_eventId]; + [_roomDataSource finalizeInitialization]; - // Make roomState digest state events of the room - for (MXEvent *stateEvent in roomInitialSync.state) - { - [_roomState handleStateEvent:stateEvent]; - } + MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:_mxSession]; + [roomDataSourceManager addRoomDataSource:_roomDataSource]; - // Report retrieved data - _roomName = _roomState.displayname; - _roomAvatarUrl = _roomState.avatar; + _roomName = peekingRoom.state.displayname; + _roomAvatarUrl = peekingRoom.state.avatar; completion(YES); diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m index 64184b4ac..e3b85973b 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -405,7 +405,8 @@ MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession]; // Let the manager release this live room data source - [roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:!_currentRoomViewController.roomDataSource.isLive]; + BOOL forceClose = !_currentRoomViewController.roomDataSource.isLive || _currentRoomViewController.roomDataSource.isPeeking; + [roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:forceClose]; } [_currentRoomViewController destroy]; @@ -622,8 +623,7 @@ } else { - [_currentRoomViewController displayRoom:_selectedRoomPreviewData.roomDataSource]; - //[_currentRoomViewController displayRoomPreview:_selectedRoomPreviewData]; + [_currentRoomViewController displayRoomPreview:_selectedRoomPreviewData]; _selectedRoomPreviewData = nil; } } diff --git a/Vector/Views/RoomTitle/PreviewRoomTitleView.m b/Vector/Views/RoomTitle/PreviewRoomTitleView.m index e2d96ec59..b430188d1 100644 --- a/Vector/Views/RoomTitle/PreviewRoomTitleView.m +++ b/Vector/Views/RoomTitle/PreviewRoomTitleView.m @@ -147,15 +147,15 @@ self.displayNameTextField.text = self.roomPreviewData.roomName; // Display more information if available - if (self.roomPreviewData.roomState) + if (self.roomPreviewData.roomDataSource) { // Topic - self.roomTopic.text = [MXTools stripNewlineCharacters:self.roomPreviewData.roomState.topic]; + self.roomTopic.text = [MXTools stripNewlineCharacters:self.roomPreviewData.roomDataSource.room.state.topic]; // Room members count // Note that room members presence/activity is not available NSUInteger memberCount = 0; - for (MXRoomMember *mxMember in self.roomPreviewData.roomState.members) + for (MXRoomMember *mxMember in self.roomPreviewData.roomDataSource.room.state.members) { if (mxMember.membership == MXMembershipJoin) { From 2e62b485ba8a4854f794e812b8fdb5ef3c42441d Mon Sep 17 00:00:00 2001 From: manuroe Date: Wed, 8 Jun 2016 18:29:35 +0200 Subject: [PATCH 3/6] Room messages preview: improved comments --- Vector/Model/Room/RoomPreviewData.h | 4 ++-- Vector/ViewController/HomeViewController.m | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Vector/Model/Room/RoomPreviewData.h b/Vector/Model/Room/RoomPreviewData.h index 90b2c9198..14320f8fe 100644 --- a/Vector/Model/Room/RoomPreviewData.h +++ b/Vector/Model/Room/RoomPreviewData.h @@ -59,7 +59,7 @@ /** The RoomDataSource to peek into the room. - Note: this object is creating when [self peekInRoom:] succeeds. + Note: this object is created when [self peekInRoom:] succeeds. */ @property (nonatomic, readonly) RoomDataSource *roomDataSource; @@ -74,7 +74,7 @@ - (instancetype)initWithRoomId:(NSString*)roomId emailInvitationParams:(NSDictionary*)emailInvitationParams andSession:(MXSession*)mxSession; /** - Attempt to peek into room to get room data (state, messages history, etc). + Attempt to peek into the room to get room data (state, messages history, etc). The operation succeeds only if the room history is world_readable. diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m index e3b85973b..a65197ab1 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -404,7 +404,8 @@ MXSession *mxSession = _currentRoomViewController.roomDataSource.mxSession; MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession]; - // Let the manager release this live room data source + // Let the manager release live room data sources where the user is in + // and force close all others. BOOL forceClose = !_currentRoomViewController.roomDataSource.isLive || _currentRoomViewController.roomDataSource.isPeeking; [roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:forceClose]; } From d82b1fbe4d68a47af5bddaefc410d16509ddd096 Mon Sep 17 00:00:00 2001 From: manuroe Date: Thu, 9 Jun 2016 11:52:39 +0200 Subject: [PATCH 4/6] Room messages preview: Release peeking room data source better --- Vector/Model/Room/RoomPreviewData.m | 8 +++----- Vector/ViewController/HomeViewController.m | 8 ++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Vector/Model/Room/RoomPreviewData.m b/Vector/Model/Room/RoomPreviewData.m index da22b3628..fe732d025 100644 --- a/Vector/Model/Room/RoomPreviewData.m +++ b/Vector/Model/Room/RoomPreviewData.m @@ -48,13 +48,11 @@ [_mxSession peekInRoomWithRoomId:_roomId success:^(MXPeekingRoom *peekingRoom) { // Create the room data source - // It will be automatically released when the RoomViewController that displays it will disappear - _roomDataSource = [[RoomDataSource alloc] initWithPeekingRoom:peekingRoom AndInitialEventId:_eventId]; + // It will be automatically released in the destroy metho of the RoomViewController + // that will display the data source + _roomDataSource = [[RoomDataSource alloc] initWithPeekingRoom:peekingRoom andInitialEventId:_eventId]; [_roomDataSource finalizeInitialization]; - MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:_mxSession]; - [roomDataSourceManager addRoomDataSource:_roomDataSource]; - _roomName = peekingRoom.state.displayname; _roomAvatarUrl = peekingRoom.state.avatar; diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m index a65197ab1..ccbe00b67 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -399,15 +399,15 @@ if (_currentRoomViewController) { - if (_currentRoomViewController.roomDataSource) + if (_currentRoomViewController.roomDataSource + && _currentRoomViewController.roomDataSource.isLive + && !_currentRoomViewController.roomDataSource.isPeeking) { MXSession *mxSession = _currentRoomViewController.roomDataSource.mxSession; MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession]; // Let the manager release live room data sources where the user is in - // and force close all others. - BOOL forceClose = !_currentRoomViewController.roomDataSource.isLive || _currentRoomViewController.roomDataSource.isPeeking; - [roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:forceClose]; + [roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:NO]; } [_currentRoomViewController destroy]; From 3cb28e091222349f932b3a3c0451066a675bb7cc Mon Sep 17 00:00:00 2001 From: manuroe Date: Thu, 9 Jun 2016 14:41:55 +0200 Subject: [PATCH 5/6] Room messages preview: Indicate to RoomVC when to release the datasource --- Vector/ViewController/HomeViewController.m | 2 ++ Vector/ViewController/RoomSearchViewController.m | 1 + 2 files changed, 3 insertions(+) diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m index ccbe00b67..faea5b073 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -611,6 +611,7 @@ // Open the room on the requested event roomDataSource = [[RoomDataSource alloc] initWithRoomId:_selectedRoomId initialEventId:_selectedEventId andMatrixSession:_selectedRoomSession]; [roomDataSource finalizeInitialization]; + _currentRoomViewController.hasRoomDataSourceOwnership = YES; } } else @@ -618,6 +619,7 @@ // Search result: Create a temp timeline from the selected event roomDataSource = [[RoomDataSource alloc] initWithRoomId:searchViewController.selectedEvent.roomId initialEventId:searchViewController.selectedEvent.eventId andMatrixSession:searchDataSource.mxSession]; [roomDataSource finalizeInitialization]; + _currentRoomViewController.hasRoomDataSourceOwnership = YES; } [_currentRoomViewController displayRoom:roomDataSource]; diff --git a/Vector/ViewController/RoomSearchViewController.m b/Vector/ViewController/RoomSearchViewController.m index 2456fa3a4..cd5373c12 100644 --- a/Vector/ViewController/RoomSearchViewController.m +++ b/Vector/ViewController/RoomSearchViewController.m @@ -217,6 +217,7 @@ [roomDataSource finalizeInitialization]; [roomViewController displayRoom:roomDataSource]; + roomViewController.hasRoomDataSourceOwnership = YES; } } From 4619214a7dde131dbdca6caabcbcc27030d82462 Mon Sep 17 00:00:00 2001 From: manuroe Date: Thu, 9 Jun 2016 14:42:17 +0200 Subject: [PATCH 6/6] Room messages preview: Added FIXMEs for Giom --- Vector/Model/Room/RoomPreviewData.m | 1 + Vector/ViewController/HomeViewController.m | 1 + 2 files changed, 2 insertions(+) diff --git a/Vector/Model/Room/RoomPreviewData.m b/Vector/Model/Room/RoomPreviewData.m index fe732d025..57ee8a746 100644 --- a/Vector/Model/Room/RoomPreviewData.m +++ b/Vector/Model/Room/RoomPreviewData.m @@ -50,6 +50,7 @@ // Create the room data source // It will be automatically released in the destroy metho of the RoomViewController // that will display the data source + // FIXME: release this room data source like it should be _roomDataSource = [[RoomDataSource alloc] initWithPeekingRoom:peekingRoom andInitialEventId:_eventId]; [_roomDataSource finalizeInitialization]; diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m index faea5b073..430b4549f 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -399,6 +399,7 @@ if (_currentRoomViewController) { + // FIXME: review this code when peekingRoom will be supported if (_currentRoomViewController.roomDataSource && _currentRoomViewController.roomDataSource.isLive && !_currentRoomViewController.roomDataSource.isPeeking)