mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-06 07:57:42 +02:00
Merge pull request #378 from vector-im/room_history_preview
Room history preview
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -217,6 +217,7 @@
|
||||
[roomDataSource finalizeInitialization];
|
||||
|
||||
[roomViewController displayRoom:roomDataSource];
|
||||
roomViewController.hasRoomDataSourceOwnership = YES;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user