2016-02-10 09:59:48 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2017-03-08 15:14:41 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2016-02-10 09:59:48 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "ExpandedRoomTitleView.h"
|
|
|
|
|
2017-03-08 15:14:41 +00:00
|
|
|
#import "RiotDesignValues.h"
|
2016-02-10 09:59:48 +00:00
|
|
|
|
2017-10-20 17:22:37 +00:00
|
|
|
#import "MXRoomSummary+Riot.h"
|
|
|
|
|
2016-02-10 09:59:48 +00:00
|
|
|
@implementation ExpandedRoomTitleView
|
|
|
|
|
|
|
|
+ (UINib *)nib
|
|
|
|
{
|
|
|
|
return [UINib nibWithNibName:NSStringFromClass([self class])
|
|
|
|
bundle:[NSBundle bundleForClass:[self class]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
[super awakeFromNib];
|
2017-08-08 08:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-(void)customizeViewRendering
|
|
|
|
{
|
|
|
|
[super customizeViewRendering];
|
2016-02-10 09:59:48 +00:00
|
|
|
|
2017-09-14 14:00:50 +00:00
|
|
|
self.displayNameTextField.textColor = (self.mxRoom.summary.displayname.length ? kRiotPrimaryTextColor : kRiotSecondaryTextColor);
|
2017-08-11 14:56:09 +00:00
|
|
|
self.roomTopic.textColor = kRiotTopicTextColor;
|
2017-03-08 15:14:41 +00:00
|
|
|
self.roomMembers.textColor = kRiotColorGreen;
|
2016-02-10 09:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)refreshDisplay
|
|
|
|
{
|
|
|
|
[super refreshDisplay];
|
|
|
|
|
|
|
|
if (self.mxRoom)
|
|
|
|
{
|
2017-10-20 17:22:37 +00:00
|
|
|
[self.mxRoom.summary setRoomAvatarImageIn:self.roomAvatar];
|
|
|
|
|
2017-09-14 14:00:50 +00:00
|
|
|
self.displayNameTextField.text = self.mxRoom.summary.displayname;
|
2016-03-17 10:32:18 +00:00
|
|
|
if (!self.displayNameTextField.text.length)
|
|
|
|
{
|
|
|
|
self.displayNameTextField.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
2017-08-11 14:56:09 +00:00
|
|
|
self.displayNameTextField.textColor = kRiotSecondaryTextColor;
|
2016-03-17 10:32:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-11 14:56:09 +00:00
|
|
|
self.displayNameTextField.textColor = kRiotPrimaryTextColor;
|
2016-03-17 10:32:18 +00:00
|
|
|
}
|
2016-02-10 09:59:48 +00:00
|
|
|
|
2018-07-16 20:30:55 +00:00
|
|
|
self.roomTopic.text = [MXTools stripNewlineCharacters:self.mxRoom.summary.topic];
|
2016-02-10 09:59:48 +00:00
|
|
|
|
|
|
|
// Compute active members count
|
2018-07-11 21:52:46 +00:00
|
|
|
NSArray *members = [self.mxRoom.state.members membersWithMembership:MXMembershipJoin includeConferenceUser:NO];
|
2016-02-10 09:59:48 +00:00
|
|
|
NSUInteger activeCount = 0;
|
|
|
|
NSUInteger memberCount = 0;
|
|
|
|
for (MXRoomMember *mxMember in members)
|
|
|
|
{
|
2016-08-09 07:52:05 +00:00
|
|
|
memberCount ++;
|
|
|
|
|
|
|
|
// Get the user that corresponds to this member
|
|
|
|
MXUser *user = [self.mxRoom.mxSession userWithUserId:mxMember.userId];
|
|
|
|
// existing user ?
|
|
|
|
if (user && user.presence == MXPresenceOnline)
|
2016-02-10 09:59:48 +00:00
|
|
|
{
|
2016-08-09 07:52:05 +00:00
|
|
|
activeCount ++;
|
2016-02-10 09:59:48 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-09 07:52:05 +00:00
|
|
|
|
2016-02-10 09:59:48 +00:00
|
|
|
if (memberCount)
|
|
|
|
{
|
2016-05-31 14:55:42 +00:00
|
|
|
// Check whether the logged in user is alone in this room
|
2018-07-17 16:00:56 +00:00
|
|
|
if (memberCount == 1 && self.mxRoom.summary.membership == MXMembershipJoin)
|
2016-02-10 09:59:48 +00:00
|
|
|
{
|
2016-05-31 14:55:42 +00:00
|
|
|
self.roomMembers.text = NSLocalizedStringFromTable(@"room_title_invite_members", @"Vector", nil);
|
2016-02-10 09:59:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-31 14:55:42 +00:00
|
|
|
if (activeCount > 1)
|
|
|
|
{
|
2017-02-13 16:58:29 +00:00
|
|
|
self.roomMembers.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_title_multiple_active_members", @"Vector", nil), @(activeCount), @(memberCount)];
|
2016-05-31 14:55:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-13 16:58:29 +00:00
|
|
|
self.roomMembers.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_title_one_active_member", @"Vector", nil), @(activeCount), @(memberCount)];
|
2016-05-31 14:55:42 +00:00
|
|
|
}
|
2016-02-10 09:59:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Should not happen
|
|
|
|
self.roomMembers.text = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-20 17:22:37 +00:00
|
|
|
self.roomAvatar.image = nil;
|
|
|
|
|
2016-02-10 09:59:48 +00:00
|
|
|
self.roomTopic.text = nil;
|
|
|
|
self.roomMembers.text = nil;
|
|
|
|
}
|
2016-04-25 15:26:39 +00:00
|
|
|
|
2017-10-20 17:22:37 +00:00
|
|
|
// Round image view for thumbnail
|
|
|
|
self.roomAvatar.layer.cornerRadius = self.roomAvatar.frame.size.width / 2;
|
|
|
|
self.roomAvatar.clipsToBounds = YES;
|
|
|
|
|
|
|
|
self.roomAvatar.defaultBackgroundColor = kRiotSecondaryBgColor;
|
|
|
|
|
2016-04-25 15:26:39 +00:00
|
|
|
// Force the layout of subviews to update the position of 'bottomBorderView' which is used to define the actual height of the preview container.
|
|
|
|
[self layoutIfNeeded];
|
2016-02-10 09:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|