Merge pull request #397 from vector-im/fix_room_public_preview

Bug Fix: The preview header is empty for non world readable public room.
This commit is contained in:
giomfo
2016-06-22 12:05:33 +02:00
committed by GitHub
5 changed files with 89 additions and 39 deletions
+11 -1
View File
@@ -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).
+31
View File
@@ -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);
}];