diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index 68e520929..f1766bf20 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -843,16 +843,17 @@ if (queryParams) { roomPreviewData = [[RoomPreviewData alloc] initWithRoomId:roomIdOrAlias emailInvitationParams:queryParams andSession:account.mxSession]; + [self showRoomPreview:roomPreviewData]; } else { roomPreviewData = [[RoomPreviewData alloc] initWithRoomId:roomIdOrAlias andSession:account.mxSession]; - // TODO: Try to get more information about the room - // We could attempt to do a room initialSync on it + // Try to get more information about the room before opening its preview + [roomPreviewData fetchPreviewData:^(BOOL successed) { + [self showRoomPreview:roomPreviewData]; + }]; } - - [self showRoomPreview:roomPreviewData]; } } else diff --git a/Vector/Model/Room/RoomPreviewData.h b/Vector/Model/Room/RoomPreviewData.h index 52c2a9ccd..28b89c75d 100644 --- a/Vector/Model/Room/RoomPreviewData.h +++ b/Vector/Model/Room/RoomPreviewData.h @@ -44,7 +44,8 @@ @property (nonatomic) MXSession *mxSession; /** - TODO + Preview information. + They come from the `emailInvitationParams` or [self fetchPreviewData]. */ @property (nonatomic, readonly) NSString *roomName; @property (nonatomic, readonly) NSString *roomAvatarUrl; @@ -60,4 +61,15 @@ - (instancetype)initWithRoomId:(NSString*)roomId andSession:(MXSession*)mxSession; - (instancetype)initWithRoomId:(NSString*)roomId emailInvitationParams:(NSDictionary*)emailInvitationParams andSession:(MXSession*)mxSession; +/** + Attempt to get more information from the homeserver about the room. + + 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. + */ +- (void)fetchPreviewData:(void (^)(BOOL successed))completion; + @end diff --git a/Vector/Model/Room/RoomPreviewData.m b/Vector/Model/Room/RoomPreviewData.m index 9cb8308bd..7365eac2e 100644 --- a/Vector/Model/Room/RoomPreviewData.m +++ b/Vector/Model/Room/RoomPreviewData.m @@ -43,4 +43,33 @@ return self; } +- (void)fetchPreviewData:(void (^)(BOOL))completion +{ + // Make an /initialSync request to get preview data + [_mxSession.matrixRestClient initialSyncOfRoom:_roomId withLimit:0 success:^(MXRoomInitialSync *roomInitialSync) { + + MXRoomState *roomState = [[MXRoomState alloc] initWithRoomId:_roomId andMatrixSession:_mxSession andDirection:YES]; + + // Make roomState digest state events of the room + for (MXEvent *stateEvent in roomInitialSync.state) + { + // Skip members events as they are not not interesting here and can be numerous + if (stateEvent.eventType != MXEventTypeRoomMember) + { + [roomState handleStateEvent:stateEvent]; + } + } + + // Report retrieved data + _roomName = roomState.displayname; + _roomAvatarUrl = roomState.avatar; + _roomTopic = roomState.topic; + + completion(YES); + + } failure:^(NSError *error) { + completion(NO); + }]; +} + @end