-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathTGMessageViewWebPageRowController.m
88 lines (68 loc) · 2.73 KB
/
TGMessageViewWebPageRowController.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
#import "TGMessageViewWebPageRowController.h"
#import <WatchCommonWatch/WatchCommonWatch.h>
#import "WKInterfaceGroup+Signals.h"
#import "TGBridgeMediaSignals.h"
#import "TGMessageViewModel.h"
NSString *const TGMessageViewWebPageRowIdentifier = @"TGMessageViewWebPageRow";
@interface TGMessageViewWebPageRowController ()
{
int64_t _photoId;
}
@end
@implementation TGMessageViewWebPageRowController
- (void)updateWithAttachment:(TGBridgeWebPageMediaAttachment *)attachment message:(TGBridgeMessage *)message
{
if (attachment.siteName.length > 0)
self.siteNameLabel.text = attachment.siteName;
else
self.siteNameLabel.hidden = true;
bool inTextImage = !([attachment.pageType isEqualToString:@"photo"] || [attachment.pageType isEqualToString:@"video"]);
if (attachment.pageDescription.length == 0)
inTextImage = false;
NSString *title = attachment.title;
if (title.length == 0)
title = attachment.author;
if (title.length > 0)
self.titleLabel.text = title;
else
self.titleLabel.hidden = true;
if (attachment.pageDescription.length > 0)
self.textLabel.text = attachment.pageDescription;
else
self.textLabel.hidden = true;
if (attachment.photo != nil)
{
if (inTextImage)
{
self.imageGroup.hidden = true;
[self.titleImageGroup setBackgroundImageSignal:[TGBridgeMediaSignals thumbnailWithPeerId:message.cid messageId:message.identifier size:CGSizeMake(26, 26) notification:false] isVisible:self.isVisible];
}
else
{
self.titleImageGroup.hidden = true;
self.imageGroup.hidden = false;
CGSize imageSize = CGSizeZero;
[TGMessageViewModel updateMediaGroup:self.imageGroup activityIndicator:self.activityIndicator attachment:attachment.photo message:message notification:false currentPhoto:&_photoId standalone:true margin:0 imageSize:&imageSize isVisible:self.isVisible completion:nil];
self.imageGroup.width = imageSize.width;
self.imageGroup.height = imageSize.height;
}
}
else
{
self.titleImageGroup.hidden = true;
self.imageGroup.hidden = true;
}
if (attachment.duration != nil)
{
self.durationGroup.hidden = false;
NSInteger duration = [attachment.duration doubleValue];
NSInteger durationMinutes = floor(duration / 60.0);
NSInteger durationSeconds = duration % 60;
self.durationLabel.text = [NSString stringWithFormat:@"%ld:%02ld", (long)durationMinutes, (long)durationSeconds];
}
}
+ (NSString *)identifier
{
return TGMessageViewWebPageRowIdentifier;
}
@end