From b6f2f36fc77172df07aa1eed9c327b5ff3c2331c Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 10 Jul 2018 02:13:36 +0300 Subject: [PATCH] no message --- LegacyComponents/TGConversation.h | 5 +++ LegacyComponents/TGConversation.m | 30 ++++++++++++++++- LegacyComponents/TGLocationLiveCell.m | 2 +- .../TGLocationLiveSessionItemView.m | 2 +- .../TGLocationPinAnnotationView.m | 2 +- LegacyComponents/TGMediaOriginInfo.h | 7 ++-- LegacyComponents/TGMediaOriginInfo.m | 11 +++++-- .../TGMediaPickerGalleryVideoScrubber.m | 8 +++-- LegacyComponents/TGMentionPanelCell.m | 2 +- LegacyComponents/TGUser.h | 5 +++ LegacyComponents/TGUser.m | 33 +++++++++++++++++-- 11 files changed, 94 insertions(+), 13 deletions(-) diff --git a/LegacyComponents/TGConversation.h b/LegacyComponents/TGConversation.h index 472ac1bb36..1640dd7cc0 100644 --- a/LegacyComponents/TGConversation.h +++ b/LegacyComponents/TGConversation.h @@ -208,6 +208,11 @@ typedef enum { @property (nonatomic, strong) NSString *chatPhotoSmall; @property (nonatomic, strong) NSString *chatPhotoMedium; @property (nonatomic, strong) NSString *chatPhotoBig; +@property (nonatomic) NSData *chatPhotoFileReferenceSmall; +@property (nonatomic) NSData *chatPhotoFileReferenceBig; + +@property (nonatomic, strong) NSString *chatPhotoFullSmall; +@property (nonatomic, strong) NSString *chatPhotoFullBig; @property (nonatomic) int chatParticipantCount; diff --git a/LegacyComponents/TGConversation.m b/LegacyComponents/TGConversation.m index 8de9bb9e68..f2fe6ab177 100644 --- a/LegacyComponents/TGConversation.m +++ b/LegacyComponents/TGConversation.m @@ -1,7 +1,7 @@ #import "TGConversation.h" #import "LegacyComponentsInternal.h" - +#import "TGStringUtils.h" #import "TGMessage.h" #import "PSKeyValueCoder.h" @@ -502,6 +502,8 @@ _chatPhotoSmall = [coder decodeStringForCKey:"cp.s"]; _chatPhotoMedium = [coder decodeStringForCKey:"cp.m"]; _chatPhotoBig = [coder decodeStringForCKey:"cp.l"]; + _chatPhotoFileReferenceSmall = [coder decodeDataCorCKey:"cp.frs"]; + _chatPhotoFileReferenceBig = [coder decodeDataCorCKey:"cp.frb"]; _chatParticipants = nil; _chatParticipantCount = 0; _chatVersion = [coder decodeInt32ForCKey:"ver"]; @@ -565,6 +567,8 @@ [coder encodeString:_chatPhotoSmall forCKey:"cp.s"]; [coder encodeString:_chatPhotoMedium forCKey:"cp.m"]; [coder encodeString:_chatPhotoBig forCKey:"cp.l"]; + [coder encodeData:_chatPhotoFileReferenceSmall forCKey:"cp.frs"]; + [coder encodeData:_chatPhotoFileReferenceBig forCKey:"cp.frb"]; [coder encodeInt32:_chatVersion forCKey:"ver"]; [coder encodeInt32:_chatIsAdmin ? 1 : 0 forCKey:"adm"]; [coder encodeInt32:_channelRole forCKey:"role"]; @@ -1313,4 +1317,28 @@ return TGPeerIdIsAd(_conversationId); } +- (NSString *)chatPhotoFullSmall +{ + NSString *finalAvatarUrl = self.chatPhotoSmall; + if (finalAvatarUrl.length == 0) + return finalAvatarUrl; + + if (self.chatPhotoFileReferenceSmall != nil) + finalAvatarUrl = [finalAvatarUrl stringByAppendingFormat:@"_%@", [self.chatPhotoFileReferenceSmall stringByEncodingInHex]]; + + return finalAvatarUrl; +} + +- (NSString *)chatPhotoFullBig +{ + NSString *finalAvatarUrl = self.chatPhotoBig; + if (finalAvatarUrl.length == 0) + return finalAvatarUrl; + + if (self.chatPhotoFileReferenceBig != nil) + finalAvatarUrl = [finalAvatarUrl stringByAppendingFormat:@"_%@", [self.chatPhotoFileReferenceBig stringByEncodingInHex]]; + + return finalAvatarUrl; +} + @end diff --git a/LegacyComponents/TGLocationLiveCell.m b/LegacyComponents/TGLocationLiveCell.m index 8a24e2e294..6f33a8106e 100644 --- a/LegacyComponents/TGLocationLiveCell.m +++ b/LegacyComponents/TGLocationLiveCell.m @@ -181,7 +181,7 @@ const CGFloat TGLocationLiveCellHeight = 68; UIImage *placeholder = _pallete != nil ? _pallete.avatarPlaceholder : staticPlaceholder; bool isUser = [peer isKindOfClass:[TGUser class]]; - NSString *avatarUrl = isUser ? ((TGUser *)peer).photoUrlSmall : ((TGConversation *)peer).chatPhotoSmall; + NSString *avatarUrl = isUser ? ((TGUser *)peer).photoFullUrlSmall : ((TGConversation *)peer).chatPhotoFullSmall; if (avatarUrl.length != 0) { _avatarView.fadeTransitionDuration = 0.3; diff --git a/LegacyComponents/TGLocationLiveSessionItemView.m b/LegacyComponents/TGLocationLiveSessionItemView.m index d61a4b36be..d73dba038e 100644 --- a/LegacyComponents/TGLocationLiveSessionItemView.m +++ b/LegacyComponents/TGLocationLiveSessionItemView.m @@ -58,7 +58,7 @@ UIGraphicsEndImageContext(); }); - NSString *avatarUrl = isUser ? ((TGUser *)peer).photoUrlSmall : ((TGConversation *)peer).chatPhotoSmall; + NSString *avatarUrl = isUser ? ((TGUser *)peer).photoFullUrlSmall : ((TGConversation *)peer).chatPhotoFullSmall; if (avatarUrl.length != 0) { _avatarView.fadeTransitionDuration = 0.3; diff --git a/LegacyComponents/TGLocationPinAnnotationView.m b/LegacyComponents/TGLocationPinAnnotationView.m index ed24d79c13..3bd7548fb6 100644 --- a/LegacyComponents/TGLocationPinAnnotationView.m +++ b/LegacyComponents/TGLocationPinAnnotationView.m @@ -372,7 +372,7 @@ NSString *const TGLocationPinAnnotationKind = @"TGLocationPinAnnotation"; } bool isUser = [peer isKindOfClass:[TGUser class]]; - NSString *avatarUrl = isUser ? ((TGUser *)peer).photoUrlSmall : ((TGConversation *)peer).chatPhotoSmall; + NSString *avatarUrl = isUser ? ((TGUser *)peer).photoFullUrlSmall : ((TGConversation *)peer).chatPhotoFullSmall; if (avatarUrl.length != 0) { _avatarView.fadeTransitionDuration = 0.3; diff --git a/LegacyComponents/TGMediaOriginInfo.h b/LegacyComponents/TGMediaOriginInfo.h index 7d29711645..0c9a751ffe 100644 --- a/LegacyComponents/TGMediaOriginInfo.h +++ b/LegacyComponents/TGMediaOriginInfo.h @@ -11,6 +11,7 @@ typedef enum { @property (nonatomic, readonly) TGMediaOriginType type; @property (nonatomic, readonly, strong) NSData *fileReference; +@property (nonatomic, readonly, strong) NSDictionary *fileReferences; @property (nonatomic, readonly, strong) NSNumber *cid; @property (nonatomic, readonly, strong) NSNumber *mid; @@ -21,8 +22,10 @@ typedef enum { @property (nonatomic, readonly, strong) NSNumber *profilePhotoUserId; @property (nonatomic, readonly, strong) NSNumber *profilePhotoOffset; -+ (instancetype)mediaOriginInfoWithFileReference:(NSData *)fileReference cid:(int64_t)cid mid:(int32_t)mid; +- (NSData *)fileReferenceForVolumeId:(int64_t)volumeId localId:(int32_t)localId; + ++ (instancetype)mediaOriginInfoWithFileReference:(NSData *)fileReference fileReferences:(NSDictionary *)fileReferences cid:(int64_t)cid mid:(int32_t)mid; + (instancetype)mediaOriginInfoWithFileReference:(NSData *)fileReference stickerPackId:(int64_t)packId accessHash:(int64_t)accessHash; -+ (instancetype)mediaOriginInfoWithFileReference:(NSData *)fileReference userId:(int32_t)userId offset:(int32_t)offset; ++ (instancetype)mediaOriginInfoWithFileReference:(NSData *)fileReference fileReferences:(NSDictionary *)fileReferences userId:(int32_t)userId offset:(int32_t)offset; @end diff --git a/LegacyComponents/TGMediaOriginInfo.m b/LegacyComponents/TGMediaOriginInfo.m index 2d26b79252..7a19c5e254 100644 --- a/LegacyComponents/TGMediaOriginInfo.m +++ b/LegacyComponents/TGMediaOriginInfo.m @@ -2,11 +2,17 @@ @implementation TGMediaOriginInfo -+ (instancetype)mediaOriginInfoWithFileReference:(NSData *)fileReference cid:(int64_t)cid mid:(int32_t)mid +- (NSData *)fileReferenceForVolumeId:(int64_t)volumeId localId:(int32_t)localId +{ + return _fileReferences[[NSString stringWithFormat:@"%lld_%d", volumeId, localId]]; +} + ++ (instancetype)mediaOriginInfoWithFileReference:(NSData *)fileReference fileReferences:(NSDictionary *)fileReferences cid:(int64_t)cid mid:(int32_t)mid { TGMediaOriginInfo *info = [[TGMediaOriginInfo alloc] init]; info->_type = TGMediaOriginTypeMessage; info->_fileReference = fileReference; + info->_fileReferences = fileReferences; info->_cid = @(cid); info->_mid = @(mid); return info; @@ -22,11 +28,12 @@ return info; } -+ (instancetype)mediaOriginInfoWithFileReference:(NSData *)fileReference userId:(int32_t)userId offset:(int32_t)offset ++ (instancetype)mediaOriginInfoWithFileReference:(NSData *)fileReference fileReferences:(NSDictionary *)fileReferences userId:(int32_t)userId offset:(int32_t)offset { TGMediaOriginInfo *info = [[TGMediaOriginInfo alloc] init]; info->_type = TGMediaOriginTypeProfilePhoto; info->_fileReference = fileReference; + info->_fileReferences = fileReferences; info->_profilePhotoUserId = @(userId); info->_profilePhotoOffset = @(offset); return info; diff --git a/LegacyComponents/TGMediaPickerGalleryVideoScrubber.m b/LegacyComponents/TGMediaPickerGalleryVideoScrubber.m index 855f1e5e99..5b39e13544 100644 --- a/LegacyComponents/TGMediaPickerGalleryVideoScrubber.m +++ b/LegacyComponents/TGMediaPickerGalleryVideoScrubber.m @@ -1177,6 +1177,10 @@ typedef enum if (zoomedIn) { + CGFloat zoomedDuration = _zoomedDuration; + if (zoomedDuration < FLT_EPSILON) + zoomedDuration = _duration; + CGFloat newWidth = (CGFloat)(width * _duration / _zoomedDuration); CGFloat newPosition = _zoomPivotCenter * newWidth / width; @@ -1248,8 +1252,8 @@ typedef enum CGRect trimRect = [self _scrubbingRectZoomedIn:zoomedIn]; CGRect normalScrubbingRect = [self _scrubbingRectZoomedIn:false]; - CGFloat minX = (CGFloat)startPosition * trimRect.size.width / (CGFloat)duration + trimRect.origin.x - normalScrubbingRect.origin.x; - CGFloat maxX = (CGFloat)endPosition * trimRect.size.width / (CGFloat)duration + trimRect.origin.x + normalScrubbingRect.origin.x; + CGFloat minX = duration > FLT_EPSILON ? ((CGFloat)startPosition * trimRect.size.width / (CGFloat)duration + trimRect.origin.x - normalScrubbingRect.origin.x) : 0.0f; + CGFloat maxX = duration > FLT_EPSILON ? ((CGFloat)endPosition * trimRect.size.width / (CGFloat)duration + trimRect.origin.x + normalScrubbingRect.origin.x) : 0.0f; return CGRectMake(minX, 0, maxX - minX, 36); } diff --git a/LegacyComponents/TGMentionPanelCell.m b/LegacyComponents/TGMentionPanelCell.m index 46eb025fce..b9affa9f34 100644 --- a/LegacyComponents/TGMentionPanelCell.m +++ b/LegacyComponents/TGMentionPanelCell.m @@ -103,7 +103,7 @@ NSString *const TGMentionPanelCellKind = @"TGMentionPanelCell"; _nameLabel.text = user.displayName; _usernameLabel.text = user.userName.length == 0 ? @"" : [[NSString alloc] initWithFormat:@"@%@", user.userName]; - NSString *avatarUrl = user.photoUrlSmall; + NSString *avatarUrl = user.photoFullUrlSmall; CGFloat diameter = 32.0f; diff --git a/LegacyComponents/TGUser.h b/LegacyComponents/TGUser.h index 0f54cb5e23..5c8b0aa7c3 100644 --- a/LegacyComponents/TGUser.h +++ b/LegacyComponents/TGUser.h @@ -78,6 +78,11 @@ typedef enum { @property (nonatomic) NSString *photoUrlSmall; @property (nonatomic) NSString *photoUrlMedium; @property (nonatomic) NSString *photoUrlBig; +@property (nonatomic) NSData *photoFileReferenceSmall; +@property (nonatomic) NSData *photoFileReferenceBig; + +@property (nonatomic) NSString *photoFullUrlSmall; +@property (nonatomic) NSString *photoFullUrlBig; @property (nonatomic) TGUserPresence presence; diff --git a/LegacyComponents/TGUser.m b/LegacyComponents/TGUser.m index 71882b156a..adb1933523 100644 --- a/LegacyComponents/TGUser.m +++ b/LegacyComponents/TGUser.m @@ -59,6 +59,8 @@ typedef enum { _contextBotPlaceholder = [coder decodeStringForCKey:"cbp"]; } _about = [coder decodeStringForCKey:"a"]; + _photoFileReferenceSmall = [coder decodeDataCorCKey:"frs"]; + _photoFileReferenceBig = [coder decodeDataCorCKey:"frb"]; } return self; } @@ -77,6 +79,8 @@ typedef enum { [coder encodeString:_contextBotPlaceholder forCKey:"cbp"]; } [coder encodeString:_about forCKey:"a"]; + [coder encodeData:_photoFileReferenceSmall forCKey:"frs"]; + [coder encodeData:_photoFileReferenceBig forCKey:"frb"]; } - (id)copyWithZone:(NSZone *)__unused zone @@ -95,6 +99,8 @@ typedef enum { user.photoUrlSmall = _photoUrlSmall; user.photoUrlMedium = _photoUrlMedium; user.photoUrlBig = _photoUrlBig; + user.photoFileReferenceSmall = _photoFileReferenceSmall; + user.photoFileReferenceBig = _photoFileReferenceBig; user.presence = _presence; user.customProperties = _customProperties; user.contactId = _contactId; @@ -261,8 +267,7 @@ typedef enum { anotherUser.phoneNumberHash == _phoneNumberHash && ((anotherUser.photoUrlSmall == nil && _photoUrlSmall == nil) || [anotherUser.photoUrlSmall isEqualToString:_photoUrlSmall]) && ((anotherUser.photoUrlMedium == nil && _photoUrlMedium == nil) || [anotherUser.photoUrlMedium isEqualToString:_photoUrlMedium]) && - ((anotherUser.photoUrlBig == nil && _photoUrlBig == nil) || [anotherUser.photoUrlBig isEqualToString:_photoUrlBig]) && - anotherUser.presence.online == _presence.online && anotherUser.presence.lastSeen == _presence.lastSeen && TGStringCompare(_userName, anotherUser.userName) && anotherUser.kind == _kind && anotherUser.botKind == _botKind && + ((anotherUser.photoUrlBig == nil && _photoUrlBig == nil) || [anotherUser.photoUrlBig isEqualToString:_photoUrlBig]) && TGObjectCompare(anotherUser.photoFileReferenceSmall, _photoFileReferenceSmall) && TGObjectCompare(anotherUser.photoFileReferenceBig, _photoFileReferenceBig) && anotherUser.presence.online == _presence.online && anotherUser.presence.lastSeen == _presence.lastSeen && TGStringCompare(_userName, anotherUser.userName) && anotherUser.kind == _kind && anotherUser.botKind == _botKind && TGStringCompare(_restrictionReason, anotherUser.restrictionReason)) { return true; @@ -412,4 +417,28 @@ typedef enum { } } +- (NSString *)photoFullUrlSmall +{ + NSString *finalAvatarUrl = self.photoUrlSmall; + if (finalAvatarUrl.length == 0) + return finalAvatarUrl; + + if (self.photoFileReferenceSmall != nil) + finalAvatarUrl = [finalAvatarUrl stringByAppendingFormat:@"_%@", [self.photoFileReferenceSmall stringByEncodingInHex]]; + + return finalAvatarUrl; +} + +- (NSString *)photoFullUrlBig +{ + NSString *finalAvatarUrl = self.photoUrlBig; + if (finalAvatarUrl.length == 0) + return finalAvatarUrl; + + if (self.photoFileReferenceBig != nil) + finalAvatarUrl = [finalAvatarUrl stringByAppendingFormat:@"_%@", [self.photoFileReferenceBig stringByEncodingInHex]]; + + return finalAvatarUrl; +} + @end