mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Room preview of room link: Try to get more information to display from the hs
This commit is contained in:
parent
b4e7537301
commit
21ee7b6454
3 changed files with 47 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue