[Spaces] Show suggested in room lists #4501

- Preview suggested rooms
This commit is contained in:
Gil Eluard 2021-08-03 13:45:22 +02:00
parent 3797455c29
commit 7aff77f24d
5 changed files with 56 additions and 4 deletions

View file

@ -97,6 +97,14 @@
*/
- (instancetype)initWithPublicRoom:(MXPublicRoom*)publicRoom andSession:(MXSession*)mxSession;
/**
Contructors.
@param childInfo MXSpaceChildInfo instance that describes the child.
@param mxSession the session to open the room preview with.
*/
- (instancetype)initWithSpaceChildInfo:(MXSpaceChildInfo*)childInfo andSession:(MXSession*)mxSession;
/**
Attempt to peek into the room to get room data (state, messages history, etc).

View file

@ -16,6 +16,7 @@
*/
#import "RoomPreviewData.h"
#import <MatrixSDK-Swift.h>
@implementation RoomPreviewData
@ -79,6 +80,21 @@
return self;
}
- (instancetype)initWithSpaceChildInfo:(MXSpaceChildInfo*)childInfo andSession:(MXSession*)mxSession
{
self = [self init];
if (self)
{
_roomId = childInfo.childRoomId;
_roomName = childInfo.name;
_roomAvatarUrl = childInfo.avatarUrl;
_roomTopic = childInfo.topic;
_numJoinedMembers = childInfo.activeMemberCount;
_mxSession = mxSession;
}
return self;
}
- (void)dealloc
{
if (_roomDataSource)

View file

@ -57,7 +57,6 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
@property (nonatomic, assign, readwrite) CrossSigningBannerDisplay crossSigningBannerDisplay;
@property (nonatomic, strong) CrossSigningService *crossSigningService;
@property (nonatomic, strong) NSArray<MXSpaceChildInfo *> *lastSuggestedRooms;
@end
@ -1301,7 +1300,12 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
}
else if (recentCellDataStoring.spaceChildInfo != nil)
{
[suggestedRoomCellDataArray addObject:recentCellDataStoring];
MXRoomSummary *roomSummary = [mxSession roomSummaryWithRoomId:recentCellDataStoring.spaceChildInfo.childRoomId];
BOOL isJoined = roomSummary.membership == MXMembershipJoin || roomSummary.membershipTransitionState == MXMembershipTransitionStateJoined;
if (!isJoined)
{
[suggestedRoomCellDataArray addObject:recentCellDataStoring];
}
}
else
{
@ -1343,7 +1347,12 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
{
if (recentCellDataStoring.spaceChildInfo)
{
[suggestedRoomCellDataArray addObject:recentCellDataStoring];
MXRoomSummary *roomSummary = [mxSession roomSummaryWithRoomId:recentCellDataStoring.spaceChildInfo.childRoomId];
BOOL isJoined = roomSummary.membership == MXMembershipJoin || roomSummary.membershipTransitionState == MXMembershipTransitionStateJoined;
if (!isJoined)
{
[suggestedRoomCellDataArray addObject:recentCellDataStoring];
}
}
// Consider only non direct rooms.
else if (!room.isDirect)

View file

@ -2051,6 +2051,18 @@
[self dispayRoomWithRoomId:roomId inMatrixSession:matrixSession];
}
- (void)recentListViewController:(MXKRecentListViewController *)recentListViewController didSelectSuggestedRoom:(MXSpaceChildInfo *)childInfo
{
RoomPreviewData *previewData = [[RoomPreviewData alloc] initWithSpaceChildInfo:childInfo andSession:self.mainSession];
[self startActivityIndicator];
MXWeakify(self);
[previewData peekInRoom:^(BOOL succeeded) {
MXStrongifyAndReturnIfNil(self);
[self stopActivityIndicator];
[[AppDelegate theDelegate].masterTabBarController showRoomPreview:previewData];
}];
}
#pragma mark - UISearchBarDelegate
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset

View file

@ -557,7 +557,14 @@
id<MXKRecentCellDataStoring> renderedCellData = (id<MXKRecentCellDataStoring>)roomCollectionViewCell.renderedCellData;
[self.delegate recentListViewController:self didSelectRoom:renderedCellData.roomSummary.roomId inMatrixSession:renderedCellData.roomSummary.room.mxSession];
if (renderedCellData.spaceChildInfo)
{
[self.delegate recentListViewController:self didSelectSuggestedRoom:renderedCellData.spaceChildInfo];
}
else
{
[self.delegate recentListViewController:self didSelectRoom:renderedCellData.roomSummary.roomId inMatrixSession:renderedCellData.roomSummary.room.mxSession];
}
}
// Hide the keyboard when user select a room