2015-10-01 18:19:52 +02:00
|
|
|
#import "TGGroupInfoHeaderController.h"
|
|
|
|
|
|
|
|
#import "TGStringUtils.h"
|
|
|
|
|
|
|
|
#import "WKInterfaceGroup+Signals.h"
|
|
|
|
#import "TGBridgeMediaSignals.h"
|
|
|
|
|
|
|
|
#import "TGBridgeChat.h"
|
|
|
|
#import "TGBridgeUser.h"
|
|
|
|
|
|
|
|
#import "TGBridgeContext.h"
|
|
|
|
|
|
|
|
NSString *const TGGroupInfoHeaderIdentifier = @"TGGroupInfoHeader";
|
|
|
|
|
|
|
|
@interface TGGroupInfoHeaderController ()
|
|
|
|
{
|
|
|
|
NSString *_currentAvatarPhoto;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TGGroupInfoHeaderController
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)updateWithGroupChat:(TGBridgeChat *)chat users:(NSDictionary *)users context:(TGBridgeContext *)context
|
|
|
|
{
|
|
|
|
self.nameLabel.text = chat.groupTitle;
|
|
|
|
|
|
|
|
NSInteger onlineCount = 1;
|
|
|
|
for (NSNumber *uid in chat.participants)
|
|
|
|
{
|
|
|
|
TGBridgeUser *user = users[uid];
|
|
|
|
if (user != nil && user.isOnline && user.identifier != context.userId)
|
|
|
|
onlineCount++;
|
|
|
|
}
|
|
|
|
|
2016-02-25 01:03:51 +01:00
|
|
|
NSString *membersText = [NSString stringWithFormat:TGLocalized([TGStringUtils integerValueFormat:@"Conversation.StatusMembers_" value:chat.participantsCount]), [NSString stringWithFormat:@"%d", (int32_t)chat.participantsCount]];
|
2015-10-01 18:19:52 +02:00
|
|
|
|
|
|
|
if (onlineCount > 1)
|
|
|
|
membersText = [NSString stringWithFormat:@"%@,", membersText];
|
|
|
|
|
|
|
|
self.participantsLabel.text = membersText;
|
|
|
|
|
|
|
|
self.onlineLabel.hidden = (onlineCount <= 1);
|
|
|
|
if (!self.onlineLabel.hidden)
|
|
|
|
{
|
2016-02-25 01:03:51 +01:00
|
|
|
self.onlineLabel.text = [NSString stringWithFormat:TGLocalized([TGStringUtils integerValueFormat:@"Conversation.StatusOnline_" value:onlineCount]), [NSString stringWithFormat:@"%d", (int32_t)onlineCount]];
|
2015-10-01 18:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (chat.groupPhotoSmall.length > 0)
|
|
|
|
{
|
|
|
|
self.avatarButton.enabled = true;
|
|
|
|
self.avatarInitialsLabel.hidden = true;
|
|
|
|
self.avatarGroup.backgroundColor = [UIColor hexColor:0x1a1a1a];
|
|
|
|
if (![_currentAvatarPhoto isEqualToString:chat.groupPhotoSmall])
|
|
|
|
{
|
|
|
|
_currentAvatarPhoto = chat.groupPhotoSmall;
|
|
|
|
|
|
|
|
__weak TGGroupInfoHeaderController *weakSelf = self;
|
|
|
|
[self.avatarGroup setBackgroundImageSignal:[[TGBridgeMediaSignals avatarWithUrl:_currentAvatarPhoto type:TGBridgeMediaAvatarTypeProfile] onError:^(id error)
|
|
|
|
{
|
|
|
|
__strong TGGroupInfoHeaderController *strongSelf = weakSelf;
|
|
|
|
if (strongSelf == nil)
|
|
|
|
strongSelf->_currentAvatarPhoto = nil;
|
|
|
|
}] isVisible:self.isVisible];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.avatarButton.enabled = false;
|
|
|
|
self.avatarInitialsLabel.hidden = false;
|
|
|
|
self.avatarGroup.backgroundColor = [TGColor colorForGroupId:chat.identifier];
|
|
|
|
self.avatarInitialsLabel.text = [TGStringUtils initialForGroupName:chat.groupTitle];
|
|
|
|
|
|
|
|
_currentAvatarPhoto = nil;
|
|
|
|
[self.avatarGroup setBackgroundImageSignal:nil isVisible:self.isVisible];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)avatarPressedAction
|
|
|
|
{
|
|
|
|
if (self.avatarPressed != nil)
|
|
|
|
self.avatarPressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)notifyVisiblityChange
|
|
|
|
{
|
|
|
|
[self.avatarGroup updateIfNeeded];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
+ (NSString *)identifier
|
|
|
|
{
|
|
|
|
return TGGroupInfoHeaderIdentifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|