From 4011b75f1768d91e31a87817d61eda8dded17ec2 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Tue, 18 Jan 2022 20:26:30 +0400 Subject: [PATCH] Watch: add some int64 support --- Telegram/Watch/Extension/TGBridgeUserCache.h | 4 +-- Telegram/Watch/Extension/TGBridgeUserCache.m | 20 ++++++------ .../Watch/Extension/TGNeoChatRowController.m | 2 +- .../Extension/TGNeoConversationController.m | 22 ++++++------- .../Watch/Extension/TGNeoMessageViewModel.m | 2 +- .../Watch/WatchCommonWatch/TGBridgeChat.h | 4 +-- .../Watch/WatchCommonWatch/TGBridgeChat.m | 31 ++++++++++++------- .../Watch/WatchCommonWatch/TGBridgeMessage.h | 2 +- .../Watch/WatchCommonWatch/TGBridgeMessage.m | 20 +++++++----- .../PublicHeaders/WatchCommon/TGBridgeChat.h | 4 +-- .../WatchCommon/TGBridgeMessage.h | 2 +- .../WatchCommon/Host/Sources/TGBridgeChat.m | 31 ++++++++++++------- .../Host/Sources/TGBridgeMessage.m | 20 +++++++----- 13 files changed, 96 insertions(+), 68 deletions(-) diff --git a/Telegram/Watch/Extension/TGBridgeUserCache.h b/Telegram/Watch/Extension/TGBridgeUserCache.h index 533341e37c..b48906356f 100644 --- a/Telegram/Watch/Extension/TGBridgeUserCache.h +++ b/Telegram/Watch/Extension/TGBridgeUserCache.h @@ -5,8 +5,8 @@ @interface TGBridgeUserCache : NSObject -- (TGBridgeUser *)userWithId:(int32_t)userId; -- (NSDictionary *)usersWithIndexSet:(NSIndexSet *)indexSet; +- (TGBridgeUser *)userWithId:(int64_t)userId; +- (NSDictionary *)usersWithIds:(NSArray *)indexSet; - (void)storeUser:(TGBridgeUser *)user; - (void)storeUsers:(NSArray *)users; - (NSArray *)applyUserChanges:(NSArray *)userChanges; diff --git a/Telegram/Watch/Extension/TGBridgeUserCache.m b/Telegram/Watch/Extension/TGBridgeUserCache.m index 9ba7651bbc..92a77bc055 100644 --- a/Telegram/Watch/Extension/TGBridgeUserCache.m +++ b/Telegram/Watch/Extension/TGBridgeUserCache.m @@ -33,7 +33,7 @@ return self; } -- (TGBridgeUser *)userWithId:(int32_t)userId +- (TGBridgeUser *)userWithId:(int64_t)userId { __block TGBridgeUser *user = nil; @@ -44,26 +44,28 @@ return user; } -- (NSDictionary *)usersWithIndexSet:(NSIndexSet *)indexSet +- (NSDictionary *)usersWithIds:(NSArray *)indexSet { NSMutableDictionary *users = [[NSMutableDictionary alloc] init]; - NSMutableIndexSet *neededUsers = [indexSet mutableCopy]; + NSMutableSet *neededUsers = [indexSet mutableCopy]; - NSMutableIndexSet *foundUsers = [[NSMutableIndexSet alloc] init]; + NSMutableSet *foundUsers = [[NSMutableSet alloc] init]; OSSpinLockLock(&_userByUidLock); - [neededUsers enumerateIndexesUsingBlock:^(NSUInteger index, BOOL * _Nonnull stop) - { + for (NSNumber *nId in neededUsers) { + int64_t index = [nId longLongValue]; TGBridgeUser *user = _userByUid[@(index)]; if (user != nil) { users[@(index)] = user; - [foundUsers addIndex:index]; + [foundUsers addObject:@(index)]; } - }]; + } OSSpinLockUnlock(&_userByUidLock); - [neededUsers removeIndexes:foundUsers]; + for (NSNumber *nId in foundUsers) { + [neededUsers removeObject:nId]; + } return users; } diff --git a/Telegram/Watch/Extension/TGNeoChatRowController.m b/Telegram/Watch/Extension/TGNeoChatRowController.m index 9b0dcf4e30..2b5471c737 100644 --- a/Telegram/Watch/Extension/TGNeoChatRowController.m +++ b/Telegram/Watch/Extension/TGNeoChatRowController.m @@ -59,7 +59,7 @@ NSString *const TGNeoChatRowIdentifier = @"TGNeoChatRow"; _currentChat = chat; NSDictionary *oldUsers = _currentUsers; - _currentUsers = [[TGBridgeUserCache instance] usersWithIndexSet:[chat involvedUserIds]]; + _currentUsers = [[TGBridgeUserCache instance] usersWithIds:[chat involvedUserIds]]; bool shouldUpdate = [self shouldUpdateContentFrom:oldChat oldUsers:oldUsers to:_currentChat newUsers:_currentUsers]; if (shouldUpdate) diff --git a/Telegram/Watch/Extension/TGNeoConversationController.m b/Telegram/Watch/Extension/TGNeoConversationController.m index 4c099a70c3..a40861f6d5 100644 --- a/Telegram/Watch/Extension/TGNeoConversationController.m +++ b/Telegram/Watch/Extension/TGNeoConversationController.m @@ -703,9 +703,10 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4; NSMutableArray *botInfoSignals = [[NSMutableArray alloc] init]; NSMutableArray *botUsers = [[NSMutableArray alloc] init]; NSMutableArray *initialStates = [[NSMutableArray alloc] init]; - [_chatModel.participantsUserIds enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) - { - TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:(int32_t)idx]; + + for (NSNumber *nId in _chatModel.participantsUserIds) { + int64_t idx = [nId longLongValue]; + TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:idx]; if ([user isBot]) { [botUsers addObject:user]; @@ -718,7 +719,7 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4; return botInfo.commandList; }]]; } - }]; + } return [[SSignal combineSignals:botInfoSignals withInitialStates:initialStates] map:^id(NSArray *commandLists) { @@ -767,15 +768,14 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4; if ([self peerIsAnyGroup]) { - [_chatModel.participantsUserIds enumerateIndexesUsingBlock:^(NSUInteger userId, BOOL * _Nonnull stop) - { - TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:(int32_t)userId]; - if ([user isBot]) - { + for (NSNumber *nId in _chatModel.participantsUserIds) { + int64_t userId = [nId longLongValue]; + TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:userId]; + if ([user isBot]) { _hasBots = true; - *stop = true; + break; } - }]; + } } else { diff --git a/Telegram/Watch/Extension/TGNeoMessageViewModel.m b/Telegram/Watch/Extension/TGNeoMessageViewModel.m index 555211c67f..e82ed2841e 100644 --- a/Telegram/Watch/Extension/TGNeoMessageViewModel.m +++ b/Telegram/Watch/Extension/TGNeoMessageViewModel.m @@ -144,7 +144,7 @@ NSString *const TGNeoMessageAudioAnimatedIcon = @"animatedIcon"; } NSMutableDictionary *users = [NSMutableDictionary dictionaryWithDictionary:additionalPeers]; - [users addEntriesFromDictionary:[[TGBridgeUserCache instance] usersWithIndexSet:[message involvedUserIds]]]; + [users addEntriesFromDictionary:[[TGBridgeUserCache instance] usersWithIds:[message involvedUserIds]]]; return [[viewModelClass alloc] initWithMessage:message type:type users:users context:context]; } diff --git a/Telegram/Watch/WatchCommonWatch/TGBridgeChat.h b/Telegram/Watch/WatchCommonWatch/TGBridgeChat.h index d326e18fcf..0e218eb133 100644 --- a/Telegram/Watch/WatchCommonWatch/TGBridgeChat.h +++ b/Telegram/Watch/WatchCommonWatch/TGBridgeChat.h @@ -37,8 +37,8 @@ @property (nonatomic) int32_t participantsCount; @property (nonatomic, strong) NSArray *participants; -- (NSIndexSet *)involvedUserIds; -- (NSIndexSet *)participantsUserIds; +- (NSArray *)involvedUserIds; +- (NSArray *)participantsUserIds; @end diff --git a/Telegram/Watch/WatchCommonWatch/TGBridgeChat.m b/Telegram/Watch/WatchCommonWatch/TGBridgeChat.m index 4ea9552f08..973522fa3c 100644 --- a/Telegram/Watch/WatchCommonWatch/TGBridgeChat.m +++ b/Telegram/Watch/WatchCommonWatch/TGBridgeChat.m @@ -94,13 +94,13 @@ NSString *const TGBridgeChatsArrayKey = @"chats"; [aCoder encodeObject:self.participants forKey:TGBridgeChatGroupParticipantsKey]; } -- (NSIndexSet *)involvedUserIds +- (NSArray *)involvedUserIds { - NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; + NSMutableSet *userIds = [[NSMutableSet alloc] init]; if (!self.isGroup && !self.isChannel && self.identifier != 0) - [userIds addIndex:(int32_t)self.identifier]; + [userIds addObject:[NSNumber numberWithLongLong:self.identifier]]; if ((!self.isChannel || self.isChannelGroup) && self.fromUid != self.identifier && self.fromUid != 0 && !TGPeerIdIsChannel(self.fromUid) && self.fromUid > 0) - [userIds addIndex:(int32_t)self.fromUid]; + [userIds addObject:[NSNumber numberWithLongLong:self.fromUid]]; for (TGBridgeMediaAttachment *attachment in self.media) { @@ -108,21 +108,30 @@ NSString *const TGBridgeChatsArrayKey = @"chats"; { TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment; if (actionAttachment.actionData[@"uid"] != nil) - [userIds addIndex:[actionAttachment.actionData[@"uid"] integerValue]]; + [userIds addObject:[NSNumber numberWithLongLong:[actionAttachment.actionData[@"uid"] longLongValue]]]; } } - return userIds; + NSMutableArray *result = [[NSMutableArray alloc] init]; + for (NSNumber *object in userIds) { + [result addObject:object]; + } + return result; } -- (NSIndexSet *)participantsUserIds +- (NSArray *)participantsUserIds { - NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; + NSMutableSet *userIds = [[NSMutableSet alloc] init]; - for (NSNumber *uid in self.participants) - [userIds addIndex:uid.unsignedIntegerValue]; + for (NSNumber *uid in self.participants) { + [userIds addObject:[NSNumber numberWithLongLong:uid.longLongValue]]; + } - return userIds; + NSMutableArray *result = [[NSMutableArray alloc] init]; + for (NSNumber *object in userIds) { + [result addObject:object]; + } + return result; } - (BOOL)isEqual:(id)object diff --git a/Telegram/Watch/WatchCommonWatch/TGBridgeMessage.h b/Telegram/Watch/WatchCommonWatch/TGBridgeMessage.h index 59ec1178d2..d4bae69554 100644 --- a/Telegram/Watch/WatchCommonWatch/TGBridgeMessage.h +++ b/Telegram/Watch/WatchCommonWatch/TGBridgeMessage.h @@ -50,7 +50,7 @@ typedef NS_ENUM(NSUInteger, TGBridgeMessageDeliveryState) { @property (nonatomic, strong) NSArray *media; @property (nonatomic) bool forceReply; -- (NSIndexSet *)involvedUserIds; +- (NSArray *)involvedUserIds; - (NSArray *)textCheckingResults; + (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId; diff --git a/Telegram/Watch/WatchCommonWatch/TGBridgeMessage.m b/Telegram/Watch/WatchCommonWatch/TGBridgeMessage.m index 4f5e5bb6e7..e66e3313b3 100644 --- a/Telegram/Watch/WatchCommonWatch/TGBridgeMessage.m +++ b/Telegram/Watch/WatchCommonWatch/TGBridgeMessage.m @@ -60,11 +60,11 @@ NSString *const TGBridgeMessagesArrayKey = @"messages"; [aCoder encodeBool:self.forceReply forKey:TGBridgeMessageForceReplyKey]; } -- (NSIndexSet *)involvedUserIds +- (NSArray *)involvedUserIds { - NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; + NSMutableSet *userIds = [[NSMutableSet alloc] init]; if (!TGPeerIdIsChannel(self.fromUid)) - [userIds addIndex:(int32_t)self.fromUid]; + [userIds addObject:[NSNumber numberWithLongLong:self.fromUid]]; for (TGBridgeMediaAttachment *attachment in self.media) { @@ -72,29 +72,33 @@ NSString *const TGBridgeMessagesArrayKey = @"messages"; { TGBridgeContactMediaAttachment *contactAttachment = (TGBridgeContactMediaAttachment *)attachment; if (contactAttachment.uid != 0) - [userIds addIndex:contactAttachment.uid]; + [userIds addObject:[NSNumber numberWithLongLong:contactAttachment.uid]]; } else if ([attachment isKindOfClass:[TGBridgeForwardedMessageMediaAttachment class]]) { TGBridgeForwardedMessageMediaAttachment *forwardAttachment = (TGBridgeForwardedMessageMediaAttachment *)attachment; if (forwardAttachment.peerId != 0 && !TGPeerIdIsChannel(forwardAttachment.peerId)) - [userIds addIndex:(int32_t)forwardAttachment.peerId]; + [userIds addObject:[NSNumber numberWithLongLong:forwardAttachment.peerId]]; } else if ([attachment isKindOfClass:[TGBridgeReplyMessageMediaAttachment class]]) { TGBridgeReplyMessageMediaAttachment *replyAttachment = (TGBridgeReplyMessageMediaAttachment *)attachment; if (replyAttachment.message != nil && !TGPeerIdIsChannel(replyAttachment.message.fromUid)) - [userIds addIndex:(int32_t)replyAttachment.message.fromUid]; + [userIds addObject:[NSNumber numberWithLongLong:replyAttachment.message.fromUid]]; } else if ([attachment isKindOfClass:[TGBridgeActionMediaAttachment class]]) { TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment; if (actionAttachment.actionData[@"uid"] != nil) - [userIds addIndex:(int32_t)[actionAttachment.actionData[@"uid"] intValue]]; + [userIds addObject:[NSNumber numberWithLongLong:[actionAttachment.actionData[@"uid"] intValue]]]; } } - return userIds; + NSMutableArray *result = [[NSMutableArray alloc] init]; + for (NSNumber *object in userIds) { + [result addObject:object]; + } + return result; } - (NSArray *)textCheckingResults diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeChat.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeChat.h index 047521d720..fa56be05f2 100644 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeChat.h +++ b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeChat.h @@ -37,8 +37,8 @@ @property (nonatomic) int32_t participantsCount; @property (nonatomic, strong) NSArray *participants; -- (NSIndexSet *)involvedUserIds; -- (NSIndexSet *)participantsUserIds; +- (NSArray *)involvedUserIds; +- (NSArray *)participantsUserIds; @end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessage.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessage.h index f6aefd84a4..a55e149121 100644 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessage.h +++ b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessage.h @@ -50,7 +50,7 @@ typedef NS_ENUM(NSUInteger, TGBridgeMessageDeliveryState) { @property (nonatomic, strong) NSArray *media; @property (nonatomic) bool forceReply; -- (NSIndexSet *)involvedUserIds; +- (NSArray *)involvedUserIds; - (NSArray *)textCheckingResults; + (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId; diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeChat.m b/submodules/WatchCommon/Host/Sources/TGBridgeChat.m index 4ea9552f08..973522fa3c 100644 --- a/submodules/WatchCommon/Host/Sources/TGBridgeChat.m +++ b/submodules/WatchCommon/Host/Sources/TGBridgeChat.m @@ -94,13 +94,13 @@ NSString *const TGBridgeChatsArrayKey = @"chats"; [aCoder encodeObject:self.participants forKey:TGBridgeChatGroupParticipantsKey]; } -- (NSIndexSet *)involvedUserIds +- (NSArray *)involvedUserIds { - NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; + NSMutableSet *userIds = [[NSMutableSet alloc] init]; if (!self.isGroup && !self.isChannel && self.identifier != 0) - [userIds addIndex:(int32_t)self.identifier]; + [userIds addObject:[NSNumber numberWithLongLong:self.identifier]]; if ((!self.isChannel || self.isChannelGroup) && self.fromUid != self.identifier && self.fromUid != 0 && !TGPeerIdIsChannel(self.fromUid) && self.fromUid > 0) - [userIds addIndex:(int32_t)self.fromUid]; + [userIds addObject:[NSNumber numberWithLongLong:self.fromUid]]; for (TGBridgeMediaAttachment *attachment in self.media) { @@ -108,21 +108,30 @@ NSString *const TGBridgeChatsArrayKey = @"chats"; { TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment; if (actionAttachment.actionData[@"uid"] != nil) - [userIds addIndex:[actionAttachment.actionData[@"uid"] integerValue]]; + [userIds addObject:[NSNumber numberWithLongLong:[actionAttachment.actionData[@"uid"] longLongValue]]]; } } - return userIds; + NSMutableArray *result = [[NSMutableArray alloc] init]; + for (NSNumber *object in userIds) { + [result addObject:object]; + } + return result; } -- (NSIndexSet *)participantsUserIds +- (NSArray *)participantsUserIds { - NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; + NSMutableSet *userIds = [[NSMutableSet alloc] init]; - for (NSNumber *uid in self.participants) - [userIds addIndex:uid.unsignedIntegerValue]; + for (NSNumber *uid in self.participants) { + [userIds addObject:[NSNumber numberWithLongLong:uid.longLongValue]]; + } - return userIds; + NSMutableArray *result = [[NSMutableArray alloc] init]; + for (NSNumber *object in userIds) { + [result addObject:object]; + } + return result; } - (BOOL)isEqual:(id)object diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeMessage.m b/submodules/WatchCommon/Host/Sources/TGBridgeMessage.m index 4f5e5bb6e7..e66e3313b3 100644 --- a/submodules/WatchCommon/Host/Sources/TGBridgeMessage.m +++ b/submodules/WatchCommon/Host/Sources/TGBridgeMessage.m @@ -60,11 +60,11 @@ NSString *const TGBridgeMessagesArrayKey = @"messages"; [aCoder encodeBool:self.forceReply forKey:TGBridgeMessageForceReplyKey]; } -- (NSIndexSet *)involvedUserIds +- (NSArray *)involvedUserIds { - NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; + NSMutableSet *userIds = [[NSMutableSet alloc] init]; if (!TGPeerIdIsChannel(self.fromUid)) - [userIds addIndex:(int32_t)self.fromUid]; + [userIds addObject:[NSNumber numberWithLongLong:self.fromUid]]; for (TGBridgeMediaAttachment *attachment in self.media) { @@ -72,29 +72,33 @@ NSString *const TGBridgeMessagesArrayKey = @"messages"; { TGBridgeContactMediaAttachment *contactAttachment = (TGBridgeContactMediaAttachment *)attachment; if (contactAttachment.uid != 0) - [userIds addIndex:contactAttachment.uid]; + [userIds addObject:[NSNumber numberWithLongLong:contactAttachment.uid]]; } else if ([attachment isKindOfClass:[TGBridgeForwardedMessageMediaAttachment class]]) { TGBridgeForwardedMessageMediaAttachment *forwardAttachment = (TGBridgeForwardedMessageMediaAttachment *)attachment; if (forwardAttachment.peerId != 0 && !TGPeerIdIsChannel(forwardAttachment.peerId)) - [userIds addIndex:(int32_t)forwardAttachment.peerId]; + [userIds addObject:[NSNumber numberWithLongLong:forwardAttachment.peerId]]; } else if ([attachment isKindOfClass:[TGBridgeReplyMessageMediaAttachment class]]) { TGBridgeReplyMessageMediaAttachment *replyAttachment = (TGBridgeReplyMessageMediaAttachment *)attachment; if (replyAttachment.message != nil && !TGPeerIdIsChannel(replyAttachment.message.fromUid)) - [userIds addIndex:(int32_t)replyAttachment.message.fromUid]; + [userIds addObject:[NSNumber numberWithLongLong:replyAttachment.message.fromUid]]; } else if ([attachment isKindOfClass:[TGBridgeActionMediaAttachment class]]) { TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment; if (actionAttachment.actionData[@"uid"] != nil) - [userIds addIndex:(int32_t)[actionAttachment.actionData[@"uid"] intValue]]; + [userIds addObject:[NSNumber numberWithLongLong:[actionAttachment.actionData[@"uid"] intValue]]]; } } - return userIds; + NSMutableArray *result = [[NSMutableArray alloc] init]; + for (NSNumber *object in userIds) { + [result addObject:object]; + } + return result; } - (NSArray *)textCheckingResults