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..14320f8fe 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 created 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 the 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..57ee8a746 100644 --- a/Vector/Model/Room/RoomPreviewData.m +++ b/Vector/Model/Room/RoomPreviewData.m @@ -43,22 +43,19 @@ 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 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]; - // Make roomState digest state events of the room - for (MXEvent *stateEvent in roomInitialSync.state) - { - [_roomState handleStateEvent:stateEvent]; - } - - // 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 416703e5b..430b4549f 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -399,11 +399,15 @@ if (_currentRoomViewController) { - if (_currentRoomViewController.roomDataSource && _currentRoomViewController.roomDataSource.isLive) + // FIXME: review this code when peekingRoom will be supported + if (_currentRoomViewController.roomDataSource + && _currentRoomViewController.roomDataSource.isLive + && !_currentRoomViewController.roomDataSource.isPeeking) { - // Let the manager release this live room data source MXSession *mxSession = _currentRoomViewController.roomDataSource.mxSession; MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession]; + + // Let the manager release live room data sources where the user is in [roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:NO]; } @@ -608,6 +612,7 @@ // Open the room on the requested event roomDataSource = [[RoomDataSource alloc] initWithRoomId:_selectedRoomId initialEventId:_selectedEventId andMatrixSession:_selectedRoomSession]; [roomDataSource finalizeInitialization]; + _currentRoomViewController.hasRoomDataSourceOwnership = YES; } } else @@ -615,6 +620,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; } } diff --git a/Vector/Views/RoomTitle/PreviewRoomTitleView.m b/Vector/Views/RoomTitle/PreviewRoomTitleView.m index 4be54299f..cd4c25aa2 100644 --- a/Vector/Views/RoomTitle/PreviewRoomTitleView.m +++ b/Vector/Views/RoomTitle/PreviewRoomTitleView.m @@ -149,15 +149,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) {