Watch: add some int64 support

This commit is contained in:
Ali 2022-01-18 20:26:30 +04:00
parent f5421b102f
commit 4011b75f17
13 changed files with 96 additions and 68 deletions

View File

@ -5,8 +5,8 @@
@interface TGBridgeUserCache : NSObject @interface TGBridgeUserCache : NSObject
- (TGBridgeUser *)userWithId:(int32_t)userId; - (TGBridgeUser *)userWithId:(int64_t)userId;
- (NSDictionary *)usersWithIndexSet:(NSIndexSet *)indexSet; - (NSDictionary *)usersWithIds:(NSArray<NSNumber *> *)indexSet;
- (void)storeUser:(TGBridgeUser *)user; - (void)storeUser:(TGBridgeUser *)user;
- (void)storeUsers:(NSArray *)users; - (void)storeUsers:(NSArray *)users;
- (NSArray *)applyUserChanges:(NSArray *)userChanges; - (NSArray *)applyUserChanges:(NSArray *)userChanges;

View File

@ -33,7 +33,7 @@
return self; return self;
} }
- (TGBridgeUser *)userWithId:(int32_t)userId - (TGBridgeUser *)userWithId:(int64_t)userId
{ {
__block TGBridgeUser *user = nil; __block TGBridgeUser *user = nil;
@ -44,26 +44,28 @@
return user; return user;
} }
- (NSDictionary *)usersWithIndexSet:(NSIndexSet *)indexSet - (NSDictionary *)usersWithIds:(NSArray<NSNumber *> *)indexSet
{ {
NSMutableDictionary *users = [[NSMutableDictionary alloc] init]; NSMutableDictionary *users = [[NSMutableDictionary alloc] init];
NSMutableIndexSet *neededUsers = [indexSet mutableCopy]; NSMutableSet<NSNumber *> *neededUsers = [indexSet mutableCopy];
NSMutableIndexSet *foundUsers = [[NSMutableIndexSet alloc] init]; NSMutableSet<NSNumber *> *foundUsers = [[NSMutableSet alloc] init];
OSSpinLockLock(&_userByUidLock); OSSpinLockLock(&_userByUidLock);
[neededUsers enumerateIndexesUsingBlock:^(NSUInteger index, BOOL * _Nonnull stop) for (NSNumber *nId in neededUsers) {
{ int64_t index = [nId longLongValue];
TGBridgeUser *user = _userByUid[@(index)]; TGBridgeUser *user = _userByUid[@(index)];
if (user != nil) if (user != nil)
{ {
users[@(index)] = user; users[@(index)] = user;
[foundUsers addIndex:index]; [foundUsers addObject:@(index)];
} }
}]; }
OSSpinLockUnlock(&_userByUidLock); OSSpinLockUnlock(&_userByUidLock);
[neededUsers removeIndexes:foundUsers]; for (NSNumber *nId in foundUsers) {
[neededUsers removeObject:nId];
}
return users; return users;
} }

View File

@ -59,7 +59,7 @@ NSString *const TGNeoChatRowIdentifier = @"TGNeoChatRow";
_currentChat = chat; _currentChat = chat;
NSDictionary *oldUsers = _currentUsers; 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]; bool shouldUpdate = [self shouldUpdateContentFrom:oldChat oldUsers:oldUsers to:_currentChat newUsers:_currentUsers];
if (shouldUpdate) if (shouldUpdate)

View File

@ -703,9 +703,10 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4;
NSMutableArray *botInfoSignals = [[NSMutableArray alloc] init]; NSMutableArray *botInfoSignals = [[NSMutableArray alloc] init];
NSMutableArray *botUsers = [[NSMutableArray alloc] init]; NSMutableArray *botUsers = [[NSMutableArray alloc] init];
NSMutableArray *initialStates = [[NSMutableArray alloc] init]; NSMutableArray *initialStates = [[NSMutableArray alloc] init];
[_chatModel.participantsUserIds enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop)
{ for (NSNumber *nId in _chatModel.participantsUserIds) {
TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:(int32_t)idx]; int64_t idx = [nId longLongValue];
TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:idx];
if ([user isBot]) if ([user isBot])
{ {
[botUsers addObject:user]; [botUsers addObject:user];
@ -718,7 +719,7 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4;
return botInfo.commandList; return botInfo.commandList;
}]]; }]];
} }
}]; }
return [[SSignal combineSignals:botInfoSignals withInitialStates:initialStates] map:^id(NSArray *commandLists) return [[SSignal combineSignals:botInfoSignals withInitialStates:initialStates] map:^id(NSArray *commandLists)
{ {
@ -767,15 +768,14 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4;
if ([self peerIsAnyGroup]) if ([self peerIsAnyGroup])
{ {
[_chatModel.participantsUserIds enumerateIndexesUsingBlock:^(NSUInteger userId, BOOL * _Nonnull stop) for (NSNumber *nId in _chatModel.participantsUserIds) {
{ int64_t userId = [nId longLongValue];
TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:(int32_t)userId]; TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:userId];
if ([user isBot]) if ([user isBot]) {
{
_hasBots = true; _hasBots = true;
*stop = true; break;
} }
}]; }
} }
else else
{ {

View File

@ -144,7 +144,7 @@ NSString *const TGNeoMessageAudioAnimatedIcon = @"animatedIcon";
} }
NSMutableDictionary *users = [NSMutableDictionary dictionaryWithDictionary:additionalPeers]; 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]; return [[viewModelClass alloc] initWithMessage:message type:type users:users context:context];
} }

View File

@ -37,8 +37,8 @@
@property (nonatomic) int32_t participantsCount; @property (nonatomic) int32_t participantsCount;
@property (nonatomic, strong) NSArray *participants; @property (nonatomic, strong) NSArray *participants;
- (NSIndexSet *)involvedUserIds; - (NSArray<NSNumber *> *)involvedUserIds;
- (NSIndexSet *)participantsUserIds; - (NSArray<NSNumber *> *)participantsUserIds;
@end @end

View File

@ -94,13 +94,13 @@ NSString *const TGBridgeChatsArrayKey = @"chats";
[aCoder encodeObject:self.participants forKey:TGBridgeChatGroupParticipantsKey]; [aCoder encodeObject:self.participants forKey:TGBridgeChatGroupParticipantsKey];
} }
- (NSIndexSet *)involvedUserIds - (NSArray<NSNumber *> *)involvedUserIds
{ {
NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; NSMutableSet<NSNumber *> *userIds = [[NSMutableSet alloc] init];
if (!self.isGroup && !self.isChannel && self.identifier != 0) 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) 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) for (TGBridgeMediaAttachment *attachment in self.media)
{ {
@ -108,21 +108,30 @@ NSString *const TGBridgeChatsArrayKey = @"chats";
{ {
TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment; TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment;
if (actionAttachment.actionData[@"uid"] != nil) 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<NSNumber *> *)participantsUserIds
{ {
NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; NSMutableSet<NSNumber *> *userIds = [[NSMutableSet alloc] init];
for (NSNumber *uid in self.participants) for (NSNumber *uid in self.participants) {
[userIds addIndex:uid.unsignedIntegerValue]; [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 - (BOOL)isEqual:(id)object

View File

@ -50,7 +50,7 @@ typedef NS_ENUM(NSUInteger, TGBridgeMessageDeliveryState) {
@property (nonatomic, strong) NSArray *media; @property (nonatomic, strong) NSArray *media;
@property (nonatomic) bool forceReply; @property (nonatomic) bool forceReply;
- (NSIndexSet *)involvedUserIds; - (NSArray<NSNumber *> *)involvedUserIds;
- (NSArray *)textCheckingResults; - (NSArray *)textCheckingResults;
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId; + (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId;

View File

@ -60,11 +60,11 @@ NSString *const TGBridgeMessagesArrayKey = @"messages";
[aCoder encodeBool:self.forceReply forKey:TGBridgeMessageForceReplyKey]; [aCoder encodeBool:self.forceReply forKey:TGBridgeMessageForceReplyKey];
} }
- (NSIndexSet *)involvedUserIds - (NSArray<NSNumber *> *)involvedUserIds
{ {
NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; NSMutableSet<NSNumber *> *userIds = [[NSMutableSet alloc] init];
if (!TGPeerIdIsChannel(self.fromUid)) if (!TGPeerIdIsChannel(self.fromUid))
[userIds addIndex:(int32_t)self.fromUid]; [userIds addObject:[NSNumber numberWithLongLong:self.fromUid]];
for (TGBridgeMediaAttachment *attachment in self.media) for (TGBridgeMediaAttachment *attachment in self.media)
{ {
@ -72,29 +72,33 @@ NSString *const TGBridgeMessagesArrayKey = @"messages";
{ {
TGBridgeContactMediaAttachment *contactAttachment = (TGBridgeContactMediaAttachment *)attachment; TGBridgeContactMediaAttachment *contactAttachment = (TGBridgeContactMediaAttachment *)attachment;
if (contactAttachment.uid != 0) if (contactAttachment.uid != 0)
[userIds addIndex:contactAttachment.uid]; [userIds addObject:[NSNumber numberWithLongLong:contactAttachment.uid]];
} }
else if ([attachment isKindOfClass:[TGBridgeForwardedMessageMediaAttachment class]]) else if ([attachment isKindOfClass:[TGBridgeForwardedMessageMediaAttachment class]])
{ {
TGBridgeForwardedMessageMediaAttachment *forwardAttachment = (TGBridgeForwardedMessageMediaAttachment *)attachment; TGBridgeForwardedMessageMediaAttachment *forwardAttachment = (TGBridgeForwardedMessageMediaAttachment *)attachment;
if (forwardAttachment.peerId != 0 && !TGPeerIdIsChannel(forwardAttachment.peerId)) 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]]) else if ([attachment isKindOfClass:[TGBridgeReplyMessageMediaAttachment class]])
{ {
TGBridgeReplyMessageMediaAttachment *replyAttachment = (TGBridgeReplyMessageMediaAttachment *)attachment; TGBridgeReplyMessageMediaAttachment *replyAttachment = (TGBridgeReplyMessageMediaAttachment *)attachment;
if (replyAttachment.message != nil && !TGPeerIdIsChannel(replyAttachment.message.fromUid)) 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]]) else if ([attachment isKindOfClass:[TGBridgeActionMediaAttachment class]])
{ {
TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment; TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment;
if (actionAttachment.actionData[@"uid"] != nil) 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 - (NSArray *)textCheckingResults

View File

@ -37,8 +37,8 @@
@property (nonatomic) int32_t participantsCount; @property (nonatomic) int32_t participantsCount;
@property (nonatomic, strong) NSArray *participants; @property (nonatomic, strong) NSArray *participants;
- (NSIndexSet *)involvedUserIds; - (NSArray<NSNumber *> *)involvedUserIds;
- (NSIndexSet *)participantsUserIds; - (NSArray<NSNumber *> *)participantsUserIds;
@end @end

View File

@ -50,7 +50,7 @@ typedef NS_ENUM(NSUInteger, TGBridgeMessageDeliveryState) {
@property (nonatomic, strong) NSArray *media; @property (nonatomic, strong) NSArray *media;
@property (nonatomic) bool forceReply; @property (nonatomic) bool forceReply;
- (NSIndexSet *)involvedUserIds; - (NSArray<NSNumber *> *)involvedUserIds;
- (NSArray *)textCheckingResults; - (NSArray *)textCheckingResults;
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId; + (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId;

View File

@ -94,13 +94,13 @@ NSString *const TGBridgeChatsArrayKey = @"chats";
[aCoder encodeObject:self.participants forKey:TGBridgeChatGroupParticipantsKey]; [aCoder encodeObject:self.participants forKey:TGBridgeChatGroupParticipantsKey];
} }
- (NSIndexSet *)involvedUserIds - (NSArray<NSNumber *> *)involvedUserIds
{ {
NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; NSMutableSet<NSNumber *> *userIds = [[NSMutableSet alloc] init];
if (!self.isGroup && !self.isChannel && self.identifier != 0) 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) 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) for (TGBridgeMediaAttachment *attachment in self.media)
{ {
@ -108,21 +108,30 @@ NSString *const TGBridgeChatsArrayKey = @"chats";
{ {
TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment; TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment;
if (actionAttachment.actionData[@"uid"] != nil) 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<NSNumber *> *)participantsUserIds
{ {
NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; NSMutableSet<NSNumber *> *userIds = [[NSMutableSet alloc] init];
for (NSNumber *uid in self.participants) for (NSNumber *uid in self.participants) {
[userIds addIndex:uid.unsignedIntegerValue]; [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 - (BOOL)isEqual:(id)object

View File

@ -60,11 +60,11 @@ NSString *const TGBridgeMessagesArrayKey = @"messages";
[aCoder encodeBool:self.forceReply forKey:TGBridgeMessageForceReplyKey]; [aCoder encodeBool:self.forceReply forKey:TGBridgeMessageForceReplyKey];
} }
- (NSIndexSet *)involvedUserIds - (NSArray<NSNumber *> *)involvedUserIds
{ {
NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; NSMutableSet<NSNumber *> *userIds = [[NSMutableSet alloc] init];
if (!TGPeerIdIsChannel(self.fromUid)) if (!TGPeerIdIsChannel(self.fromUid))
[userIds addIndex:(int32_t)self.fromUid]; [userIds addObject:[NSNumber numberWithLongLong:self.fromUid]];
for (TGBridgeMediaAttachment *attachment in self.media) for (TGBridgeMediaAttachment *attachment in self.media)
{ {
@ -72,29 +72,33 @@ NSString *const TGBridgeMessagesArrayKey = @"messages";
{ {
TGBridgeContactMediaAttachment *contactAttachment = (TGBridgeContactMediaAttachment *)attachment; TGBridgeContactMediaAttachment *contactAttachment = (TGBridgeContactMediaAttachment *)attachment;
if (contactAttachment.uid != 0) if (contactAttachment.uid != 0)
[userIds addIndex:contactAttachment.uid]; [userIds addObject:[NSNumber numberWithLongLong:contactAttachment.uid]];
} }
else if ([attachment isKindOfClass:[TGBridgeForwardedMessageMediaAttachment class]]) else if ([attachment isKindOfClass:[TGBridgeForwardedMessageMediaAttachment class]])
{ {
TGBridgeForwardedMessageMediaAttachment *forwardAttachment = (TGBridgeForwardedMessageMediaAttachment *)attachment; TGBridgeForwardedMessageMediaAttachment *forwardAttachment = (TGBridgeForwardedMessageMediaAttachment *)attachment;
if (forwardAttachment.peerId != 0 && !TGPeerIdIsChannel(forwardAttachment.peerId)) 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]]) else if ([attachment isKindOfClass:[TGBridgeReplyMessageMediaAttachment class]])
{ {
TGBridgeReplyMessageMediaAttachment *replyAttachment = (TGBridgeReplyMessageMediaAttachment *)attachment; TGBridgeReplyMessageMediaAttachment *replyAttachment = (TGBridgeReplyMessageMediaAttachment *)attachment;
if (replyAttachment.message != nil && !TGPeerIdIsChannel(replyAttachment.message.fromUid)) 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]]) else if ([attachment isKindOfClass:[TGBridgeActionMediaAttachment class]])
{ {
TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment; TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment;
if (actionAttachment.actionData[@"uid"] != nil) 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 - (NSArray *)textCheckingResults