try to support new user-ids

WIP Int64 support

Int64 user Support for Bridge
This commit is contained in:
Kylmakalle 2025-01-15 10:22:22 +02:00
parent 27b7bc76b2
commit 08ab29c930
36 changed files with 118 additions and 105 deletions

View File

@ -28,7 +28,7 @@
@interface TGBridgeBotReplyMarkup : NSObject <NSCoding>
{
int32_t _userId;
int64_t _userId;
int32_t _messageId;
TGBridgeMessage *_message;
bool _hideKeyboardOnActivation;
@ -36,7 +36,7 @@
NSArray *_rows;
}
@property (nonatomic, readonly) int32_t userId;
@property (nonatomic, readonly) int64_t userId;
@property (nonatomic, readonly) int32_t messageId;
@property (nonatomic, readonly) TGBridgeMessage *message;
@property (nonatomic, readonly) bool hideKeyboardOnActivation;

View File

@ -2,7 +2,7 @@
@interface TGBridgeBotSignals : NSObject
+ (SSignal *)botInfoForUserId:(int32_t)userId;
+ (SSignal *)botInfoForUserId:(int64_t)userId;
+ (SSignal *)botReplyMarkupForPeerId:(int64_t)peerId;
@end

View File

@ -8,7 +8,7 @@
@implementation TGBridgeBotSignals
+ (SSignal *)botInfoForUserId:(int32_t)userId
+ (SSignal *)botInfoForUserId:(int64_t)userId
{
SSignal *cachedSignal = [[SSignal alloc] initWithGenerator:^id<SDisposable>(SSubscriber *subscriber)
{

View File

@ -2,7 +2,7 @@
@interface TGBridgeUserInfoSignals : NSObject
+ (SSignal *)userInfoWithUserId:(int32_t)userId;
+ (SSignal *)userInfoWithUserId:(int64_t)userId;
+ (SSignal *)usersInfoWithUserIds:(NSArray *)userIds;
@end

View File

@ -6,7 +6,7 @@
@implementation TGBridgeUserInfoSignals
+ (SSignal *)userInfoWithUserId:(int32_t)userId;
+ (SSignal *)userInfoWithUserId:(int64_t)userId;
{
return [[self usersInfoWithUserIds:@[ @(userId) ]] map:^TGBridgeUser *(NSDictionary *users)
{

View File

@ -56,7 +56,7 @@
{
self.label.hidden = false;
self.label.text = [TGStringUtils initialsForFirstName:_currentUser.firstName lastName:_currentUser.lastName single:true];
self.group.backgroundColor = [TGColor colorForUserId:(int32_t)user.identifier myUserId:context.userId];
self.group.backgroundColor = [TGColor colorForUserId:(int64_t)user.identifier myUserId:context.userId];
}
}
}

View File

@ -11,8 +11,8 @@
- (void)storeUsers:(NSArray *)users;
- (NSArray *)applyUserChanges:(NSArray *)userChanges;
- (TGBridgeBotInfo *)botInfoForUserId:(int32_t)userId;
- (void)storeBotInfo:(TGBridgeBotInfo *)botInfo forUserId:(int32_t)userId;
- (TGBridgeBotInfo *)botInfoForUserId:(int64_t)userId;
- (void)storeBotInfo:(TGBridgeBotInfo *)botInfo forUserId:(int64_t)userId;
+ (instancetype)instance;

View File

@ -115,7 +115,7 @@
return missedUserIds;
}
- (TGBridgeBotInfo *)botInfoForUserId:(int32_t)userId
- (TGBridgeBotInfo *)botInfoForUserId:(int64_t)userId
{
__block TGBridgeBotInfo *botInfo = nil;
@ -147,7 +147,7 @@
return botInfo;
}
- (void)storeBotInfo:(TGBridgeBotInfo *)botInfo forUserId:(int32_t)userId
- (void)storeBotInfo:(TGBridgeBotInfo *)botInfo forUserId:(int64_t)userId
{
OSSpinLockLock(&_botInfoByUidLock);
_botInfoByUid[@(userId)] = botInfo;

View File

@ -279,7 +279,7 @@ NSString *const TGGroupInfoControllerIdentifier = @"TGGroupInfoController";
return [[TGUserInfoControllerContext alloc] initWithUser:_currentParticipantsModels[indexPath.row]];
}
+ (NSMutableArray *)sortedParticipantsList:(NSMutableArray *)list preferredOrder:(NSDictionary *)preferredOrder ownUid:(int32_t)ownUid
+ (NSMutableArray *)sortedParticipantsList:(NSMutableArray *)list preferredOrder:(NSDictionary *)preferredOrder ownUid:(int64_t)ownUid
{
NSMutableArray *resultList = [list mutableCopy];

View File

@ -158,7 +158,7 @@ NSString *const TGMessageViewControllerIdentifier = @"TGMessageViewController";
}
else
{
TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:(int32_t)_context.message.fromUid];
TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:(int64_t)_context.message.fromUid];
[controller updateWithUser:user context:_context.context];
}
}
@ -173,7 +173,7 @@ NSString *const TGMessageViewControllerIdentifier = @"TGMessageViewController";
}
else
{
TGUserInfoControllerContext *context = [[TGUserInfoControllerContext alloc] initWithUserId:(int32_t)_context.message.fromUid];
TGUserInfoControllerContext *context = [[TGUserInfoControllerContext alloc] initWithUserId:(int64_t)_context.message.fromUid];
[self pushControllerWithClass:[TGUserInfoController class] context:context];
}
}
@ -280,7 +280,7 @@ NSString *const TGMessageViewControllerIdentifier = @"TGMessageViewController";
if (TGPeerIdIsChannel(peerId))
context = [[TGUserInfoControllerContext alloc] initWithChannel:_context.additionalPeers[@(peerId)]];
else
context = [[TGUserInfoControllerContext alloc] initWithUserId:(int32_t)peerId];
context = [[TGUserInfoControllerContext alloc] initWithUserId:(int64_t)peerId];
[strongSelf pushControllerWithClass:[TGUserInfoController class] context:context];
}

View File

@ -234,7 +234,7 @@ NSString *const TGMessageViewMessageRowIdentifier = @"TGMessageViewMessageRow";
else
{
self.avatarInitialsLabel.hidden = false;
self.avatarGroup.backgroundColor = [TGColor colorForUserId:(int32_t)user.identifier myUserId:context.userId];
self.avatarGroup.backgroundColor = [TGColor colorForUserId:(int64_t)user.identifier myUserId:context.userId];
self.avatarInitialsLabel.text = [TGStringUtils initialsForFirstName:user.firstName lastName:user.lastName single:true];
[self.avatarGroup setBackgroundImageSignal:nil isVisible:self.isVisible];
@ -280,7 +280,7 @@ NSString *const TGMessageViewMessageRowIdentifier = @"TGMessageViewMessageRow";
if (TGPeerIdIsChannel(forwardAttachment.peerId))
forwardPeer = additionalPeers[@(forwardAttachment.peerId)];
else
forwardPeer = [[TGBridgeUserCache instance] userWithId:(int32_t)forwardAttachment.peerId];
forwardPeer = [[TGBridgeUserCache instance] userWithId:(int64_t)forwardAttachment.peerId];
}
[TGMessageViewModel updateForwardHeaderGroup:self.forwardHeaderButton titleLabel:self.forwardTitleLabel fromLabel:self.forwardFromLabel forwardAttachment:forwardAttachment forwardPeer:forwardPeer textColor:[UIColor whiteColor]];

View File

@ -10,7 +10,7 @@
@interface TGMessageViewModel : NSObject
+ (void)updateAuthorLabel:(WKInterfaceLabel *)authorLabel isOutgoing:(bool)isOutgoing isGroup:(bool)isGroup user:(TGBridgeUser *)user ownUserId:(int32_t)ownUserId;
+ (void)updateAuthorLabel:(WKInterfaceLabel *)authorLabel isOutgoing:(bool)isOutgoing isGroup:(bool)isGroup user:(TGBridgeUser *)user ownUserId:(int64_t)ownUserId;
+ (void)updateMediaGroup:(WKInterfaceGroup *)mediaGroup activityIndicator:(WKInterfaceImage *)activityIndicator attachment:(TGBridgeMediaAttachment *)mediaAttachment message:(TGBridgeMessage *)message notification:(bool)notification currentPhoto:(int64_t *)currentPhoto standalone:(bool)standalone margin:(CGFloat)margin imageSize:(CGSize *)imageSize isVisible:(bool (^)(void))isVisible completion:(void (^)(void))completion;

View File

@ -58,13 +58,13 @@
*thumbnailSize = imageSize;
}
+ (void)updateAuthorLabel:(WKInterfaceLabel *)authorLabel isOutgoing:(bool)isOutgoing isGroup:(bool)isGroup user:(TGBridgeUser *)user ownUserId:(int32_t)ownUserId
+ (void)updateAuthorLabel:(WKInterfaceLabel *)authorLabel isOutgoing:(bool)isOutgoing isGroup:(bool)isGroup user:(TGBridgeUser *)user ownUserId:(int64_t)ownUserId
{
if (isGroup && !isOutgoing)
{
authorLabel.hidden = false;
authorLabel.text = user.displayName;
authorLabel.textColor = [TGColor colorForUserId:(int32_t)user.identifier myUserId:ownUserId];
authorLabel.textColor = [TGColor colorForUserId:(int64_t)user.identifier myUserId:ownUserId];
}
else
{
@ -268,7 +268,7 @@
textColor = subtitleColor;
}
authorLabel.text = [[[TGBridgeUserCache instance] userWithId:(int32_t)message.fromUid] displayName];
authorLabel.text = [[[TGBridgeUserCache instance] userWithId:(int64_t)message.fromUid] displayName];
imageGroup.hidden = !hasImagePreview;
textLabel.text = messageText;
textLabel.textColor = textColor;
@ -325,7 +325,7 @@
+ (NSString *)stringForActionAttachment:(TGBridgeActionMediaAttachment *)actionAttachment message:(TGBridgeMessage *)message users:(NSDictionary *)users forChannel:(bool)forChannel
{
NSString *messageText = nil;
TGBridgeUser *author = (users != nil) ? users[@(message.fromUid)] : [[TGBridgeUserCache instance] userWithId:(int32_t)message.fromUid];
TGBridgeUser *author = (users != nil) ? users[@(message.fromUid)] : [[TGBridgeUserCache instance] userWithId:(int64_t)message.fromUid];
switch (actionAttachment.actionType)
{
@ -373,7 +373,7 @@
case TGBridgeMessageActionChatDeleteMember:
{
NSString *authorName = [TGStringUtils initialsForFirstName:author.firstName lastName:author.lastName single:false];
TGBridgeUser *user = (users != nil) ? users[actionAttachment.actionData[@"uid"]] : [[TGBridgeUserCache instance] userWithId:[actionAttachment.actionData[@"uid"] int32Value]];
TGBridgeUser *user = (users != nil) ? users[actionAttachment.actionData[@"uid"]] : [[TGBridgeUserCache instance] userWithId:[actionAttachment.actionData[@"uid"] int64Value]];
if (user.identifier == author.identifier)
{
@ -419,7 +419,7 @@
case TGBridgeMessageActionChannelInviter:
{
TGBridgeUser *user = (users != nil) ? users[actionAttachment.actionData[@"uid"]] : [[TGBridgeUserCache instance] userWithId:[actionAttachment.actionData[@"uid"] int32Value]];
TGBridgeUser *user = (users != nil) ? users[actionAttachment.actionData[@"uid"]] : [[TGBridgeUserCache instance] userWithId:[actionAttachment.actionData[@"uid"] int64Value]];
NSString *authorName = [TGStringUtils initialsForFirstName:user.firstName lastName:user.lastName single:false];
NSString *formatString = TGLocalized(@"Notification.ChannelInviter");
@ -486,7 +486,7 @@
+ (void)updateWithMessage:(TGBridgeMessage *)message notification:(bool)notification isGroup:(bool)isGroup context:(TGBridgeContext *)context currentDocumentId:(int64_t *)currentDocumentId authorLabel:(WKInterfaceLabel *)authorLabel imageGroup:(WKInterfaceGroup *)imageGroup isVisible:(bool (^)(void))isVisible completion:(void (^)(void))completion
{
[TGMessageViewModel updateAuthorLabel:authorLabel isOutgoing:message.outgoing isGroup:isGroup user:[[TGBridgeUserCache instance] userWithId:(int32_t)message.fromUid] ownUserId:context.userId];
[TGMessageViewModel updateAuthorLabel:authorLabel isOutgoing:message.outgoing isGroup:isGroup user:[[TGBridgeUserCache instance] userWithId:(int64_t)message.fromUid] ownUserId:context.userId];
for (TGBridgeMediaAttachment *attachment in message.media)
{

View File

@ -198,7 +198,7 @@
case TGBridgeMessageActionChatDeleteMember:
{
NSString *authorName = [TGStringUtils initialsForFirstName:author.firstName lastName:author.lastName single:false];
TGBridgeUser *user = users[@([actionAttachment.actionData[@"uid"] int32Value])];
TGBridgeUser *user = users[@([actionAttachment.actionData[@"uid"] int64Value])];
if (user.identifier == author.identifier)
{
@ -276,7 +276,7 @@
case TGBridgeMessageActionChannelInviter:
{
TGBridgeUser *user = users[@([actionAttachment.actionData[@"uid"] int32Value])];
TGBridgeUser *user = users[@([actionAttachment.actionData[@"uid"] int64Value])];
NSString *authorName = [TGStringUtils initialsForFirstName:user.firstName lastName:user.lastName single:false];
NSString *formatString = TGLocalized(@"Notification.ChannelInviter");

View File

@ -28,7 +28,7 @@ const CGFloat TGNeoBubbleHeaderSpacing = 2.0f;
if (!message.outgoing && type == TGNeoMessageTypeGroup)
{
_authorNameModel = [[TGNeoLabelViewModel alloc] initWithText:[users[@(message.fromUid)] displayName] font:[UIFont systemFontOfSize:14] color:[TGColor colorForUserId:(int32_t)message.fromUid myUserId:context.userId] attributes:nil];
_authorNameModel = [[TGNeoLabelViewModel alloc] initWithText:[users[@(message.fromUid)] displayName] font:[UIFont systemFontOfSize:14] color:[TGColor colorForUserId:(int64_t)message.fromUid myUserId:context.userId] attributes:nil];
[self addSubmodel:_authorNameModel];
}

View File

@ -12,8 +12,8 @@
TGNeoLabelViewModel *_nameModel;
TGNeoLabelViewModel *_phoneModel;
int32_t _userId;
int32_t _ownUserId;
int64_t _userId;
int64_t _ownUserId;
NSString *_avatarUrl;
NSString *_firstName;
NSString *_lastName;

View File

@ -513,7 +513,7 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4 * 2;
else if (_context.context.userId == _context.peerId)
return TGLocalized(@"Conversation.SavedMessages");
else
return [[[TGBridgeUserCache instance] userWithId:(int32_t)[self peerId]] displayName];
return [[[TGBridgeUserCache instance] userWithId:(int64_t)[self peerId]] displayName];
}
- (void)configureHandoff
@ -582,7 +582,7 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4 * 2;
}
else
{
TGUserInfoControllerContext *context = [[TGUserInfoControllerContext alloc] initWithUserId:(int32_t)[strongSelf peerId]];
TGUserInfoControllerContext *context = [[TGUserInfoControllerContext alloc] initWithUserId:(int64_t)[strongSelf peerId]];
context.disallowCompose = true;
[controller pushControllerWithClass:[TGUserInfoController class] context:context];
}
@ -736,7 +736,7 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4 * 2;
}
else if ([self _userIsBot])
{
int32_t userId = (int32_t)[self peerId];
int64_t userId = (int64_t)[self peerId];
return [[TGBridgeBotSignals botInfoForUserId:userId] map:^NSArray *(TGBridgeBotInfo *botInfo)
{
if (botInfo != nil)
@ -757,7 +757,7 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4 * 2;
if ([self peerId] < 0)
return false;
TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:(int32_t)[self peerId]];
TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:(int64_t)[self peerId]];
return [user isBot];
}
@ -779,7 +779,7 @@ const NSInteger TGNeoConversationControllerInitialRenderCount = 4 * 2;
}
else
{
TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:(int32_t)[self peerId]];
TGBridgeUser *user = [[TGBridgeUserCache instance] userWithId:(int64_t)[self peerId]];
_hasBots = [user isBot];
}
}

View File

@ -94,7 +94,7 @@ const UIEdgeInsets TGNeoChatInfoInsets = { 12, 0, 12, 0 };
case TGBridgeMessageActionChatDeleteMember:
{
NSString *authorName = author.displayName;
TGBridgeUser *user = users[@([actionAttachment.actionData[@"uid"] int32Value])];
TGBridgeUser *user = users[@([actionAttachment.actionData[@"uid"] int64Value])];
if (user.identifier == author.identifier)
{
@ -172,7 +172,7 @@ const UIEdgeInsets TGNeoChatInfoInsets = { 12, 0, 12, 0 };
case TGBridgeMessageActionChannelInviter:
{
TGBridgeUser *user = users[@([actionAttachment.actionData[@"uid"] int32Value])];
TGBridgeUser *user = users[@([actionAttachment.actionData[@"uid"] int64Value])];
NSString *authorName = user.displayName;
NSString *formatString = TGLocalized(@"Notification.ChannelInviter");
actionText = [[NSString alloc] initWithFormat:formatString, authorName];

View File

@ -28,7 +28,7 @@ const CGFloat TGNeoSmiliesMessageHeight = 39;
if (message.cid < 0 && type != TGNeoMessageTypeChannel && !message.outgoing)
{
_authorNameModel = [[TGNeoLabelViewModel alloc] initWithText:[users[@(message.fromUid)] displayName] font:[UIFont systemFontOfSize:14] color:[TGColor colorForUserId:(int32_t)message.fromUid myUserId:context.userId] attributes:nil];
_authorNameModel = [[TGNeoLabelViewModel alloc] initWithText:[users[@(message.fromUid)] displayName] font:[UIFont systemFontOfSize:14] color:[TGColor colorForUserId:(int64_t)message.fromUid myUserId:context.userId] attributes:nil];
[self addSubmodel:_authorNameModel];
}

View File

@ -50,7 +50,7 @@
if (message.cid < 0 && !TGPeerIdIsChannel(message.cid) && !message.outgoing)
{
_authorNameModel = [[TGNeoLabelViewModel alloc] initWithText:[users[@(message.fromUid)] displayName] font:[UIFont systemFontOfSize:14] color:[TGColor colorForUserId:(int32_t)message.fromUid myUserId:context.userId] attributes:nil];
_authorNameModel = [[TGNeoLabelViewModel alloc] initWithText:[users[@(message.fromUid)] displayName] font:[UIFont systemFontOfSize:14] color:[TGColor colorForUserId:(int64_t)message.fromUid myUserId:context.userId] attributes:nil];
[self addSubmodel:_authorNameModel];
}
}

View File

@ -349,7 +349,7 @@
if (TGPeerIdIsChannel(forwardAttachment.peerId))
forwardPeer = users[@(forwardAttachment.peerId)];
else
forwardPeer = [[TGBridgeUserCache instance] userWithId:(int32_t)forwardAttachment.peerId];
forwardPeer = [[TGBridgeUserCache instance] userWithId:(int64_t)forwardAttachment.peerId];
}
[TGMessageViewModel updateForwardHeaderGroup:self.forwardHeaderGroup titleLabel:self.forwardTitleLabel fromLabel:self.forwardFromLabel forwardAttachment:forwardAttachment forwardPeer:forwardPeer textColor:[UIColor blackColor]];

View File

@ -8,14 +8,14 @@
@property (nonatomic, strong) TGBridgeContext *context;
@property (nonatomic, readonly) TGBridgeUser *user;
@property (nonatomic, readonly) int32_t userId;
@property (nonatomic, readonly) int64_t userId;
@property (nonatomic, readonly) TGBridgeChat *channel;
@property (nonatomic, assign) bool disallowCompose;
- (instancetype)initWithUser:(TGBridgeUser *)user;
- (instancetype)initWithUserId:(int32_t)userId;
- (instancetype)initWithUserId:(int64_t)userId;
- (instancetype)initWithChannel:(TGBridgeChat *)channel;

View File

@ -34,7 +34,7 @@ NSString *const TGUserInfoControllerIdentifier = @"TGUserInfoController";
return self;
}
- (instancetype)initWithUserId:(int32_t)userId
- (instancetype)initWithUserId:(int64_t)userId
{
self = [super init];
if (self != nil)
@ -138,7 +138,7 @@ NSString *const TGUserInfoControllerIdentifier = @"TGUserInfoController";
{
self.title = TGLocalized(@"Watch.UserInfo.Title");
int32_t userId = (_context.user != nil) ? (int32_t)_context.user.identifier : _context.userId;
int64_t userId = (_context.user != nil) ? (int64_t)_context.user.identifier : _context.userId;
SSignal *remoteUserSignal = [TGBridgeUserInfoSignals userInfoWithUserId:userId];
SSignal *userSignal = nil;

View File

@ -9,7 +9,7 @@
@interface TGColor : NSObject
+ (UIColor *)colorForUserId:(int32_t)userId myUserId:(int32_t)myUserId;
+ (UIColor *)colorForUserId:(int64_t)userId myUserId:(int64_t)myUserId;
+ (UIColor *)colorForGroupId:(int64_t)groupId;
+ (UIColor *)accentColor;

View File

@ -36,14 +36,14 @@
return colors;
}
+ (UIColor *)colorForUserId:(int32_t)userId myUserId:(int32_t)myUserId
+ (UIColor *)colorForUserId:(int64_t)userId myUserId:(int64_t)myUserId
{
return [self placeholderColors][abs(userId) % 7];
}
+ (UIColor *)colorForGroupId:(int64_t)groupId
{
int32_t peerId = 0;
int64_t peerId = 0;
if (TGPeerIdIsGroup(groupId)) {
peerId = TGGroupIdFromPeerId(groupId);
} else if (TGPeerIdIsChannel(groupId)) {

View File

@ -5,7 +5,7 @@
@property (nonatomic) int64_t identifier;
@property (nonatomic) NSTimeInterval date;
@property (nonatomic) int32_t fromUid;
@property (nonatomic) int64_t fromUid;
@property (nonatomic, strong) NSString *text;
@property (nonatomic, strong) NSArray *media;

View File

@ -2,7 +2,7 @@
@interface TGBridgeContactMediaAttachment : TGBridgeMediaAttachment
@property (nonatomic, assign) int32_t uid;
@property (nonatomic, assign) int64_t uid;
@property (nonatomic, strong) NSString *firstName;
@property (nonatomic, strong) NSString *lastName;
@property (nonatomic, strong) NSString *phoneNumber;

View File

@ -11,7 +11,7 @@
- (instancetype)initWithDictionary:(NSDictionary *)dictionary;
- (NSDictionary *)dictionary;
- (TGBridgeContext *)updatedWithAuthorized:(bool)authorized peerId:(int32_t)peerId;
- (TGBridgeContext *)updatedWithAuthorized:(bool)authorized peerId:(int64_t)peerId;
- (TGBridgeContext *)updatedWithPreheatData:(NSDictionary *)data;
- (TGBridgeContext *)updatedWithMicAccessAllowed:(bool)allowed;

View File

@ -16,7 +16,7 @@ NSString *const TGBridgeContextStartupDataVersion = @"version";
if (self != nil)
{
_authorized = [dictionary[TGBridgeContextAuthorized] boolValue];
_userId = (int32_t)[dictionary[TGBridgeContextUserId] intValue];
_userId = (int64_t)[dictionary[TGBridgeContextUserId] intValue];
_micAccessAllowed = [dictionary[TGBridgeContextMicAccessAllowed] boolValue];
if (dictionary[TGBridgeContextStartupData] != nil) {

View File

@ -53,11 +53,11 @@ typedef NS_ENUM(NSUInteger, TGBridgeMessageDeliveryState) {
- (NSArray<NSNumber *> *)involvedUserIds;
- (NSArray *)textCheckingResults;
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId;
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId replyToMessage:(TGBridgeMessage *)replyToMessage;
+ (instancetype)temporaryNewMessageForSticker:(TGBridgeDocumentMediaAttachment *)sticker userId:(int32_t)userId;
+ (instancetype)temporaryNewMessageForLocation:(TGBridgeLocationMediaAttachment *)location userId:(int32_t)userId;
+ (instancetype)temporaryNewMessageForAudioWithDuration:(int32_t)duration userId:(int32_t)userId localAudioId:(int64_t)localAudioId;
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int64_t)userId;
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int64_t)userId replyToMessage:(TGBridgeMessage *)replyToMessage;
+ (instancetype)temporaryNewMessageForSticker:(TGBridgeDocumentMediaAttachment *)sticker userId:(int64_t)userId;
+ (instancetype)temporaryNewMessageForLocation:(TGBridgeLocationMediaAttachment *)location userId:(int64_t)userId;
+ (instancetype)temporaryNewMessageForAudioWithDuration:(int32_t)duration userId:(int64_t)userId localAudioId:(int64_t)localAudioId;
@end

View File

@ -157,12 +157,12 @@ NSString *const TGBridgeMessagesArrayKey = @"messages";
return self.identifier == message.identifier;
}
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int64_t)userId
{
return [self temporaryNewMessageForText:text userId:userId replyToMessage:nil];
}
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId replyToMessage:(TGBridgeMessage *)replyToMessage
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int64_t)userId replyToMessage:(TGBridgeMessage *)replyToMessage
{
int64_t randomId = 0;
arc4random_buf(&randomId, 8);
@ -192,17 +192,17 @@ NSString *const TGBridgeMessagesArrayKey = @"messages";
return message;
}
+ (instancetype)temporaryNewMessageForSticker:(TGBridgeDocumentMediaAttachment *)sticker userId:(int32_t)userId
+ (instancetype)temporaryNewMessageForSticker:(TGBridgeDocumentMediaAttachment *)sticker userId:(int64_t)userId
{
return [self _temporaryNewMessageForMediaAttachment:sticker userId:userId];
}
+ (instancetype)temporaryNewMessageForLocation:(TGBridgeLocationMediaAttachment *)location userId:(int32_t)userId
+ (instancetype)temporaryNewMessageForLocation:(TGBridgeLocationMediaAttachment *)location userId:(int64_t)userId
{
return [self _temporaryNewMessageForMediaAttachment:location userId:userId];
}
+ (instancetype)temporaryNewMessageForAudioWithDuration:(int32_t)duration userId:(int32_t)userId localAudioId:(int64_t)localAudioId
+ (instancetype)temporaryNewMessageForAudioWithDuration:(int32_t)duration userId:(int64_t)userId localAudioId:(int64_t)localAudioId
{
TGBridgeDocumentMediaAttachment *document = [[TGBridgeDocumentMediaAttachment alloc] init];
document.isAudio = true;
@ -213,7 +213,7 @@ NSString *const TGBridgeMessagesArrayKey = @"messages";
return [self _temporaryNewMessageForMediaAttachment:document userId:userId];
}
+ (instancetype)_temporaryNewMessageForMediaAttachment:(TGBridgeMediaAttachment *)attachment userId:(int32_t)userId
+ (instancetype)_temporaryNewMessageForMediaAttachment:(TGBridgeMediaAttachment *)attachment userId:(int64_t)userId
{
int64_t randomId = 0;
arc4random_buf(&randomId, 8);

View File

@ -1,52 +1,60 @@
#ifndef Telegraph_TGPeerIdAdapter_h
#define Telegraph_TGPeerIdAdapter_h
static inline bool TGPeerIdIsGroup(int64_t peerId) {
return peerId < 0 && peerId > INT32_MIN;
}
#define TG_USER_ID_BITS 52
#define TG_MAX_USER_ID ((int64_t)1 << TG_USER_ID_BITS)
// Using bit shifts to divide the negative space into quarters
// -2^63 (INT64_MIN) divided into 4 parts using shifts
#define TG_GROUP_RANGE_START ((int64_t)-1)
#define TG_CHANNEL_RANGE_START (((int64_t)1) << 62) // -2^62
#define TG_SECRET_CHAT_RANGE_START (((int64_t)1) << 63) // -2^63 (INT64_MIN)
#define TG_ADMIN_LOG_RANGE_START (-((int64_t)1 << 62) - ((int64_t)1 << 61)) // -2^62 - 2^61
static inline bool TGPeerIdIsUser(int64_t peerId) {
return peerId > 0 && peerId < INT32_MAX;
return peerId > 0 && peerId < TG_MAX_USER_ID;
}
static inline bool TGPeerIdIsGroup(int64_t peerId) {
return peerId < 0 && peerId > TG_CHANNEL_RANGE_START;
}
static inline bool TGPeerIdIsChannel(int64_t peerId) {
return peerId <= ((int64_t)INT32_MIN) * 2 && peerId > ((int64_t)INT32_MIN) * 3;
}
static inline bool TGPeerIdIsAdminLog(int64_t peerId) {
return peerId <= ((int64_t)INT32_MIN) * 3 && peerId > ((int64_t)INT32_MIN) * 4;
}
static inline int32_t TGChannelIdFromPeerId(int64_t peerId) {
if (TGPeerIdIsChannel(peerId)) {
return (int32_t)(((int64_t)INT32_MIN) * 2 - peerId);
} else {
return 0;
}
}
static inline int64_t TGPeerIdFromChannelId(int32_t channelId) {
return ((int64_t)INT32_MIN) * 2 - ((int64_t)channelId);
}
static inline int64_t TGPeerIdFromAdminLogId(int32_t channelId) {
return ((int64_t)INT32_MIN) * 3 - ((int64_t)channelId);
}
static inline int64_t TGPeerIdFromGroupId(int32_t groupId) {
return -groupId;
}
static inline int32_t TGGroupIdFromPeerId(int64_t peerId) {
if (TGPeerIdIsGroup(peerId)) {
return (int32_t)-peerId;
} else {
return 0;
}
return peerId <= TG_CHANNEL_RANGE_START && peerId > TG_SECRET_CHAT_RANGE_START;
}
static inline bool TGPeerIdIsSecretChat(int64_t peerId) {
return peerId <= ((int64_t)INT32_MIN) && peerId > ((int64_t)INT32_MIN) * 2;
return peerId <= TG_SECRET_CHAT_RANGE_START && peerId > TG_ADMIN_LOG_RANGE_START;
}
static inline bool TGPeerIdIsAdminLog(int64_t peerId) {
return peerId <= TG_ADMIN_LOG_RANGE_START && peerId > INT64_MIN;
}
static inline int64_t TGChannelIdFromPeerId(int64_t peerId) {
if (TGPeerIdIsChannel(peerId)) {
return TG_CHANNEL_RANGE_START - peerId;
}
return 0;
}
static inline int64_t TGPeerIdFromChannelId(int64_t channelId) {
return TG_CHANNEL_RANGE_START - channelId;
}
static inline int64_t TGPeerIdFromAdminLogId(int64_t channelId) {
return TG_ADMIN_LOG_RANGE_START - channelId;
}
static inline int64_t TGPeerIdFromGroupId(int64_t groupId) {
return -groupId;
}
static inline int64_t TGGroupIdFromPeerId(int64_t peerId) {
if (TGPeerIdIsGroup(peerId)) {
return -peerId;
}
return 0;
}
#endif

View File

@ -49,10 +49,10 @@ typedef NS_ENUM(NSUInteger, TGBridgeBotKind) {
@interface TGBridgeUserChange : NSObject <NSCoding>
@property (nonatomic, readonly) int32_t userIdentifier;
@property (nonatomic, readonly) int64_t userIdentifier;
@property (nonatomic, readonly) NSDictionary *fields;
- (instancetype)initWithUserIdentifier:(int32_t)userIdentifier fields:(NSDictionary *)fields;
- (instancetype)initWithUserIdentifier:(int64_t)userIdentifier fields:(NSDictionary *)fields;
@end

View File

@ -255,7 +255,7 @@ NSString *const TGBridgeUserChangeFieldsKey = @"fields";
@implementation TGBridgeUserChange
- (instancetype)initWithUserIdentifier:(int32_t)userIdentifier fields:(NSDictionary *)fields
- (instancetype)initWithUserIdentifier:(int64_t)userIdentifier fields:(NSDictionary *)fields
{
self = [super init];
if (self != nil)

View File

@ -1,12 +1,15 @@
#ifndef Telegraph_TGPeerIdAdapter_h
#define Telegraph_TGPeerIdAdapter_h
#define TG_USER_ID_BITS 52
#define TG_MAX_USER_ID ((int64_t)1 << TG_USER_ID_BITS)
static inline bool TGPeerIdIsGroup(int64_t peerId) {
return peerId < 0 && peerId > INT32_MIN;
}
static inline bool TGPeerIdIsUser(int64_t peerId) {
return peerId > 0 && peerId < INT32_MAX;
return peerId > 0 && peerId < TG_MAX_USER_ID;
}
static inline bool TGPeerIdIsChannel(int64_t peerId) {

View File

@ -18,7 +18,9 @@ func makePeerIdFromBridgeIdentifier(_ identifier: Int64) -> PeerId? {
return PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(-identifier))
} else if identifier < Int64(Int32.min) * 2 && identifier > Int64(Int32.min) * 3 {
return PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(Int64(Int32.min) &* 2 &- identifier))
} else if identifier > 0 && identifier < Int32.max {
// MARK: Swiftgram
// supports 52 bits
} else if identifier > 0 && identifier < (1 << 52) {
return PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(identifier))
} else {
return nil