Room messages preview: Updated RoomPreviewData to use MXPeekingRoom

This commit is contained in:
manuroe
2016-06-08 18:02:22 +02:00
parent 88df216daa
commit d60501b530
5 changed files with 27 additions and 29 deletions
+1 -1
View File
@@ -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];
+10 -10
View File
@@ -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
+10 -12
View File
@@ -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);
+3 -3
View File
@@ -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;
}
}
@@ -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)
{