mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Bug Fix: The preview header is empty for non world readable public room.
This commit is contained in:
parent
126c2449c8
commit
faf810de8f
5 changed files with 89 additions and 39 deletions
|
@ -52,10 +52,12 @@
|
|||
|
||||
/**
|
||||
Preview information.
|
||||
They come from the `emailInvitationParams` or [self fetchPreviewData].
|
||||
*/
|
||||
@property (nonatomic, readonly) NSString *roomName;
|
||||
@property (nonatomic, readonly) NSString *roomTopic;
|
||||
@property (nonatomic, readonly) NSString *roomAvatarUrl;
|
||||
@property (nonatomic, readonly) NSArray<NSString*> *roomAliases;
|
||||
@property (nonatomic, readonly) NSInteger numJoinedMembers; // -1 if unknown.
|
||||
|
||||
/**
|
||||
The RoomDataSource to peek into the room.
|
||||
|
@ -73,6 +75,14 @@
|
|||
- (instancetype)initWithRoomId:(NSString*)roomId andSession:(MXSession*)mxSession;
|
||||
- (instancetype)initWithRoomId:(NSString*)roomId emailInvitationParams:(NSDictionary*)emailInvitationParams andSession:(MXSession*)mxSession;
|
||||
|
||||
/**
|
||||
Contructors.
|
||||
|
||||
@param publicRoom a public room returned by the publicRoom request.
|
||||
@param mxSession the session to open the room preview with.
|
||||
*/
|
||||
- (instancetype)initWithPublicRoom:(MXPublicRoom*)publicRoom andSession:(MXSession*)mxSession;
|
||||
|
||||
/**
|
||||
Attempt to peek into the room to get room data (state, messages history, etc).
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
{
|
||||
_roomId = roomId;
|
||||
_mxSession = mxSession;
|
||||
_numJoinedMembers = -1;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -43,6 +44,21 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithPublicRoom:(MXPublicRoom*)publicRoom andSession:(MXSession*)mxSession
|
||||
{
|
||||
self = [self initWithRoomId:publicRoom.roomId andSession:mxSession];
|
||||
if (self)
|
||||
{
|
||||
// Report public room data
|
||||
_roomName = publicRoom.name;
|
||||
_roomAvatarUrl = publicRoom.avatarUrl;
|
||||
_roomTopic = publicRoom.topic;
|
||||
_roomAliases = publicRoom.aliases;
|
||||
_numJoinedMembers = publicRoom.numJoinedMembers;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if (_roomDataSource)
|
||||
|
@ -64,11 +80,26 @@
|
|||
|
||||
_roomName = peekingRoom.state.displayname;
|
||||
_roomAvatarUrl = peekingRoom.state.avatar;
|
||||
|
||||
_roomTopic = [MXTools stripNewlineCharacters:peekingRoom.state.topic];;
|
||||
_roomAliases = peekingRoom.state.aliases;
|
||||
|
||||
// Room members count
|
||||
// Note that room members presence/activity is not available
|
||||
_numJoinedMembers = 0;
|
||||
for (MXRoomMember *mxMember in peekingRoom.state.members)
|
||||
{
|
||||
if (mxMember.membership == MXMembershipJoin)
|
||||
{
|
||||
_numJoinedMembers ++;
|
||||
}
|
||||
}
|
||||
|
||||
completion(YES);
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
|
||||
_roomName = _roomId;
|
||||
completion(NO);
|
||||
|
||||
}];
|
||||
|
|
|
@ -120,7 +120,7 @@
|
|||
[super removeMatrixSession:matrixSession];
|
||||
|
||||
// sanity check
|
||||
if (matrixSession && matrixSession.myUser && matrixSession.myUser.userId)
|
||||
if (matrixSession.myUser && matrixSession.myUser.userId)
|
||||
{
|
||||
id roomTagListener = [roomTagsListenerByUserId objectForKey:matrixSession.myUser.userId];
|
||||
|
||||
|
@ -129,12 +129,12 @@
|
|||
[matrixSession removeListener:roomTagListener];
|
||||
[roomTagsListenerByUserId removeObjectForKey:matrixSession.myUser.userId];
|
||||
}
|
||||
|
||||
if (_publicRoomsDirectoryDataSource.mxSession == matrixSession)
|
||||
{
|
||||
[_publicRoomsDirectoryDataSource destroy];
|
||||
_publicRoomsDirectoryDataSource = nil;
|
||||
}
|
||||
}
|
||||
|
||||
if (_publicRoomsDirectoryDataSource.mxSession == matrixSession)
|
||||
{
|
||||
[_publicRoomsDirectoryDataSource destroy];
|
||||
_publicRoomsDirectoryDataSource = nil;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -124,13 +124,32 @@
|
|||
// Check whether the user has already joined the selected public room
|
||||
if ([dataSource.mxSession roomWithRoomId:publicRoom.roomId])
|
||||
{
|
||||
// Open the public room.
|
||||
[self openRoomWithId:publicRoom.roomId inMatrixSession:dataSource.mxSession];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Preview the public room
|
||||
NSString *fragment = [NSString stringWithFormat:@"/room/%@", [publicRoom.roomId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
||||
[[AppDelegate theDelegate] handleUniversalLinkFragment:fragment];
|
||||
if (publicRoom.worldReadable)
|
||||
{
|
||||
RoomPreviewData *roomPreviewData = [[RoomPreviewData alloc] initWithRoomId:publicRoom.roomId andSession:dataSource.mxSession];
|
||||
|
||||
[self startActivityIndicator];
|
||||
|
||||
// Try to get more information about the room before opening its preview
|
||||
[roomPreviewData peekInRoom:^(BOOL succeeded) {
|
||||
|
||||
[self stopActivityIndicator];
|
||||
|
||||
[[AppDelegate theDelegate].homeViewController showRoomPreview:roomPreviewData];
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
RoomPreviewData *roomPreviewData = [[RoomPreviewData alloc] initWithPublicRoom:publicRoom andSession:dataSource.mxSession];
|
||||
[[AppDelegate theDelegate].homeViewController showRoomPreview:roomPreviewData];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,9 +157,7 @@
|
|||
|
||||
- (void)openRoomWithId:(NSString*)roomId inMatrixSession:(MXSession*)mxSession
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[AppDelegate theDelegate].homeViewController selectRoomWithId:roomId andEventId:nil inMatrixSession:mxSession];
|
||||
});
|
||||
[[AppDelegate theDelegate].homeViewController selectRoomWithId:roomId andEventId:nil inMatrixSession:mxSession];
|
||||
}
|
||||
|
||||
- (void)refreshCurrentSelectedCell:(BOOL)forceVisible
|
||||
|
|
|
@ -83,39 +83,31 @@
|
|||
// Consider in priority the preview data (if any)
|
||||
if (self.roomPreviewData)
|
||||
{
|
||||
// Display more information if available
|
||||
// Room topic
|
||||
self.roomTopic.text = self.roomPreviewData.roomTopic;
|
||||
|
||||
// Joined members count
|
||||
if (self.roomPreviewData.numJoinedMembers == 1)
|
||||
{
|
||||
self.roomMembers.text = NSLocalizedStringFromTable(@"room_title_one_member", @"Vector", nil);
|
||||
}
|
||||
else if (self.roomPreviewData.numJoinedMembers != 1)
|
||||
{
|
||||
self.roomMembers.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_title_members", @"Vector", nil), self.roomPreviewData.numJoinedMembers];
|
||||
}
|
||||
else
|
||||
{
|
||||
self.roomMembers.text = nil;
|
||||
}
|
||||
|
||||
// Preview subtitle
|
||||
if (self.roomPreviewData.roomDataSource)
|
||||
{
|
||||
// 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.roomDataSource.room.state.members)
|
||||
{
|
||||
if (mxMember.membership == MXMembershipJoin)
|
||||
{
|
||||
memberCount ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (memberCount == 1)
|
||||
{
|
||||
self.roomMembers.text = NSLocalizedStringFromTable(@"room_title_one_member", @"Vector", nil);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.roomMembers.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_title_members", @"Vector", nil), memberCount];
|
||||
}
|
||||
|
||||
// Display the default preview subtitle in case of peeking
|
||||
self.subNoticeLabel.text = NSLocalizedStringFromTable(@"room_preview_subtitle", @"Vector", nil);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.roomTopic.text = nil;
|
||||
self.roomMembers.text = nil;
|
||||
self.subNoticeLabel.text = nil;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue