forked from TelegramMessenger/Telegram-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTGGroupInfoHeaderController.m
96 lines (74 loc) · 3 KB
/
TGGroupInfoHeaderController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#import "TGGroupInfoHeaderController.h"
#import <WatchCommonWatch/WatchCommonWatch.h>
#import "TGWatchCommon.h"
#import "TGStringUtils.h"
#import "WKInterfaceGroup+Signals.h"
#import "TGBridgeMediaSignals.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.online && user.identifier != context.userId)
onlineCount++;
}
NSString *membersText = [NSString stringWithFormat:TGLocalized([TGStringUtils integerValueFormat:@"Conversation.StatusMembers_" value:chat.participantsCount]), [NSString stringWithFormat:@"%d", (int32_t)chat.participantsCount]];
if (onlineCount > 1)
membersText = [NSString stringWithFormat:@"%@,", membersText];
self.participantsLabel.text = membersText;
self.onlineLabel.hidden = (onlineCount <= 1);
if (!self.onlineLabel.hidden)
{
self.onlineLabel.text = [NSString stringWithFormat:TGLocalized([TGStringUtils integerValueFormat:@"Conversation.StatusOnline_" value:onlineCount]), [NSString stringWithFormat:@"%d", (int32_t)onlineCount]];
}
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 avatarWithPeerId:chat.identifier url:_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