GLEGram 12.5 — Initial public release

Based on Swiftgram 12.5 (Telegram iOS 12.5).
All GLEGram features ported and organized in GLEGram/ folder.

Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass,
Font Replacement, Fake Profile, Chat Export, Plugin System, and more.

See CHANGELOG_12.5.md for full details.
This commit is contained in:
Leeksov
2026-04-06 09:48:12 +03:00
commit 4647310322
39685 changed files with 11052678 additions and 0 deletions
@@ -0,0 +1,33 @@
#import "TGBridgeActionMediaAttachment.h"
#import "TGBridgeImageMediaAttachment.h"
const NSInteger TGBridgeActionMediaAttachmentType = 0x1167E28B;
NSString *const TGBridgeActionMediaTypeKey = @"actionType";
NSString *const TGBridgeActionMediaDataKey = @"actionData";
@implementation TGBridgeActionMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_actionType = (TGBridgeMessageAction)[aDecoder decodeInt32ForKey:TGBridgeActionMediaTypeKey];
_actionData = [aDecoder decodeObjectForKey:TGBridgeActionMediaDataKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt32:self.actionType forKey:TGBridgeActionMediaTypeKey];
[aCoder encodeObject:self.actionData forKey:TGBridgeActionMediaDataKey];
}
+ (NSInteger)mediaType
{
return TGBridgeActionMediaAttachmentType;
}
@end
@@ -0,0 +1,65 @@
#import "TGBridgeAudioMediaAttachment.h"
const NSInteger TGBridgeAudioMediaAttachmentType = 0x3A0E7A32;
NSString *const TGBridgeAudioMediaAudioIdKey = @"audioId";
NSString *const TGBridgeAudioMediaAccessHashKey = @"accessHash";
NSString *const TGBridgeAudioMediaLocalIdKey = @"localId";
NSString *const TGBridgeAudioMediaDatacenterIdKey = @"datacenterId";
NSString *const TGBridgeAudioMediaDurationKey = @"duration";
NSString *const TGBridgeAudioMediaFileSizeKey = @"fileSize";
@implementation TGBridgeAudioMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_audioId = [aDecoder decodeInt64ForKey:TGBridgeAudioMediaAudioIdKey];
_accessHash = [aDecoder decodeInt64ForKey:TGBridgeAudioMediaAccessHashKey];
_localAudioId = [aDecoder decodeInt64ForKey:TGBridgeAudioMediaLocalIdKey];
_datacenterId = [aDecoder decodeInt32ForKey:TGBridgeAudioMediaDatacenterIdKey];
_duration = [aDecoder decodeInt32ForKey:TGBridgeAudioMediaDurationKey];
_fileSize = [aDecoder decodeInt32ForKey:TGBridgeAudioMediaFileSizeKey];
}
return self;
}
- (void)encodeWithCoder:(nonnull NSCoder *)aCoder
{
[aCoder encodeInt64:self.audioId forKey:TGBridgeAudioMediaAudioIdKey];
[aCoder encodeInt64:self.accessHash forKey:TGBridgeAudioMediaAccessHashKey];
[aCoder encodeInt64:self.localAudioId forKey:TGBridgeAudioMediaLocalIdKey];
[aCoder encodeInt32:self.datacenterId forKey:TGBridgeAudioMediaDatacenterIdKey];
[aCoder encodeInt32:self.duration forKey:TGBridgeAudioMediaDurationKey];
[aCoder encodeInt32:self.fileSize forKey:TGBridgeAudioMediaFileSizeKey];
}
- (int64_t)identifier
{
if (self.localAudioId != 0)
return self.localAudioId;
return self.audioId;
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return YES;
if (!object || ![object isKindOfClass:[self class]])
return NO;
TGBridgeAudioMediaAttachment *audio = (TGBridgeAudioMediaAttachment *)object;
return (self.audioId == audio.audioId || self.localAudioId == audio.localAudioId);
}
+ (NSInteger)mediaType
{
return TGBridgeAudioMediaAttachmentType;
}
@end
@@ -0,0 +1,25 @@
#import "TGBridgeBotCommandInfo.h"
NSString *const TGBridgeBotCommandInfoCommandKey = @"command";
NSString *const TGBridgeBotCommandDescriptionKey = @"commandDescription";
@implementation TGBridgeBotCommandInfo
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_command = [aDecoder decodeObjectForKey:TGBridgeBotCommandInfoCommandKey];
_commandDescription = [aDecoder decodeObjectForKey:TGBridgeBotCommandDescriptionKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.command forKey:TGBridgeBotCommandInfoCommandKey];
[aCoder encodeObject:self.commandDescription forKey:TGBridgeBotCommandDescriptionKey];
}
@end
@@ -0,0 +1,25 @@
#import "TGBridgeBotInfo.h"
NSString *const TGBridgeBotInfoShortDescriptionKey = @"shortDescription";
NSString *const TGBridgeBotInfoCommandListKey = @"commandList";
@implementation TGBridgeBotInfo
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_shortDescription = [aDecoder decodeObjectForKey:TGBridgeBotInfoShortDescriptionKey];
_commandList = [aDecoder decodeObjectForKey:TGBridgeBotInfoCommandListKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.shortDescription forKey:TGBridgeBotInfoShortDescriptionKey];
[aCoder encodeObject:self.commandList forKey:TGBridgeBotInfoCommandListKey];
}
@end
@@ -0,0 +1,148 @@
#import "TGBridgeChat.h"
#import "TGBridgePeerIdAdapter.h"
NSString *const TGBridgeChatIdentifierKey = @"identifier";
NSString *const TGBridgeChatDateKey = @"date";
NSString *const TGBridgeChatFromUidKey = @"fromUid";
NSString *const TGBridgeChatTextKey = @"text";
NSString *const TGBridgeChatOutgoingKey = @"outgoing";
NSString *const TGBridgeChatUnreadKey = @"unread";
NSString *const TGBridgeChatMediaKey = @"media";
NSString *const TGBridgeChatUnreadCountKey = @"unreadCount";
NSString *const TGBridgeChatGroupTitleKey = @"groupTitle";
NSString *const TGBridgeChatGroupPhotoSmallKey = @"groupPhotoSmall";
NSString *const TGBridgeChatGroupPhotoBigKey = @"groupPhotoBig";
NSString *const TGBridgeChatIsGroupKey = @"isGroup";
NSString *const TGBridgeChatHasLeftGroupKey = @"hasLeftGroup";
NSString *const TGBridgeChatIsKickedFromGroupKey = @"isKickedFromGroup";
NSString *const TGBridgeChatIsChannelKey = @"isChannel";
NSString *const TGBridgeChatIsChannelGroupKey = @"isChannelGroup";
NSString *const TGBridgeChatUserNameKey = @"userName";
NSString *const TGBridgeChatAboutKey = @"about";
NSString *const TGBridgeChatVerifiedKey = @"verified";
NSString *const TGBridgeChatGroupParticipantsCountKey = @"participantsCount";
NSString *const TGBridgeChatGroupParticipantsKey = @"participants";
NSString *const TGBridgeChatDeliveryStateKey = @"deliveryState";
NSString *const TGBridgeChatDeliveryErrorKey = @"deliveryError";
NSString *const TGBridgeChatKey = @"chat";
NSString *const TGBridgeChatsArrayKey = @"chats";
@implementation TGBridgeChat
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_identifier = [aDecoder decodeInt64ForKey:TGBridgeChatIdentifierKey];
_date = [aDecoder decodeDoubleForKey:TGBridgeChatDateKey];
_fromUid = [aDecoder decodeInt32ForKey:TGBridgeChatFromUidKey];
_text = [aDecoder decodeObjectForKey:TGBridgeChatTextKey];
_outgoing = [aDecoder decodeBoolForKey:TGBridgeChatOutgoingKey];
_unread = [aDecoder decodeBoolForKey:TGBridgeChatUnreadKey];
_unreadCount = [aDecoder decodeInt32ForKey:TGBridgeChatUnreadCountKey];
_deliveryState = [aDecoder decodeInt32ForKey:TGBridgeChatDeliveryStateKey];
_deliveryError = [aDecoder decodeBoolForKey:TGBridgeChatDeliveryErrorKey];
_media = [aDecoder decodeObjectForKey:TGBridgeChatMediaKey];
_groupTitle = [aDecoder decodeObjectForKey:TGBridgeChatGroupTitleKey];
_groupPhotoSmall = [aDecoder decodeObjectForKey:TGBridgeChatGroupPhotoSmallKey];
_groupPhotoBig = [aDecoder decodeObjectForKey:TGBridgeChatGroupPhotoBigKey];
_isGroup = [aDecoder decodeBoolForKey:TGBridgeChatIsGroupKey];
_hasLeftGroup = [aDecoder decodeBoolForKey:TGBridgeChatHasLeftGroupKey];
_isKickedFromGroup = [aDecoder decodeBoolForKey:TGBridgeChatIsKickedFromGroupKey];
_isChannel = [aDecoder decodeBoolForKey:TGBridgeChatIsChannelKey];
_isChannelGroup = [aDecoder decodeBoolForKey:TGBridgeChatIsChannelGroupKey];
_userName = [aDecoder decodeObjectForKey:TGBridgeChatUserNameKey];
_about = [aDecoder decodeObjectForKey:TGBridgeChatAboutKey];
_verified = [aDecoder decodeBoolForKey:TGBridgeChatVerifiedKey];
_participantsCount = [aDecoder decodeInt32ForKey:TGBridgeChatGroupParticipantsCountKey];
_participants = [aDecoder decodeObjectForKey:TGBridgeChatGroupParticipantsKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt64:self.identifier forKey:TGBridgeChatIdentifierKey];
[aCoder encodeDouble:self.date forKey:TGBridgeChatDateKey];
[aCoder encodeInt32:self.fromUid forKey:TGBridgeChatFromUidKey];
[aCoder encodeObject:self.text forKey:TGBridgeChatTextKey];
[aCoder encodeBool:self.outgoing forKey:TGBridgeChatOutgoingKey];
[aCoder encodeBool:self.unread forKey:TGBridgeChatUnreadKey];
[aCoder encodeInt32:self.unreadCount forKey:TGBridgeChatUnreadCountKey];
[aCoder encodeInt32:self.deliveryState forKey:TGBridgeChatDeliveryStateKey];
[aCoder encodeBool:self.deliveryError forKey:TGBridgeChatDeliveryErrorKey];
[aCoder encodeObject:self.media forKey:TGBridgeChatMediaKey];
[aCoder encodeObject:self.groupTitle forKey:TGBridgeChatGroupTitleKey];
[aCoder encodeObject:self.groupPhotoSmall forKey:TGBridgeChatGroupPhotoSmallKey];
[aCoder encodeObject:self.groupPhotoBig forKey:TGBridgeChatGroupPhotoBigKey];
[aCoder encodeBool:self.isGroup forKey:TGBridgeChatIsGroupKey];
[aCoder encodeBool:self.hasLeftGroup forKey:TGBridgeChatHasLeftGroupKey];
[aCoder encodeBool:self.isKickedFromGroup forKey:TGBridgeChatIsKickedFromGroupKey];
[aCoder encodeBool:self.isChannel forKey:TGBridgeChatIsChannelKey];
[aCoder encodeBool:self.isChannelGroup forKey:TGBridgeChatIsChannelGroupKey];
[aCoder encodeObject:self.userName forKey:TGBridgeChatUserNameKey];
[aCoder encodeObject:self.about forKey:TGBridgeChatAboutKey];
[aCoder encodeBool:self.verified forKey:TGBridgeChatVerifiedKey];
[aCoder encodeInt32:self.participantsCount forKey:TGBridgeChatGroupParticipantsCountKey];
[aCoder encodeObject:self.participants forKey:TGBridgeChatGroupParticipantsKey];
}
- (NSArray<NSNumber *> *)involvedUserIds
{
NSMutableSet<NSNumber *> *userIds = [[NSMutableSet alloc] init];
if (!self.isGroup && !self.isChannel && self.identifier != 0)
[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 addObject:[NSNumber numberWithLongLong:self.fromUid]];
for (TGBridgeMediaAttachment *attachment in self.media)
{
if ([attachment isKindOfClass:[TGBridgeActionMediaAttachment class]])
{
TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment;
if (actionAttachment.actionData[@"uid"] != nil)
[userIds addObject:[NSNumber numberWithLongLong:[actionAttachment.actionData[@"uid"] longLongValue]]];
}
}
NSMutableArray *result = [[NSMutableArray alloc] init];
for (NSNumber *object in userIds) {
[result addObject:object];
}
return result;
}
- (NSArray<NSNumber *> *)participantsUserIds
{
NSMutableSet<NSNumber *> *userIds = [[NSMutableSet alloc] init];
for (NSNumber *uid in self.participants) {
[userIds addObject:[NSNumber numberWithLongLong:uid.longLongValue]];
}
NSMutableArray *result = [[NSMutableArray alloc] init];
for (NSNumber *object in userIds) {
[result addObject:object];
}
return result;
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return YES;
if (!object || ![object isKindOfClass:[self class]])
return NO;
return self.identifier == ((TGBridgeChat *)object).identifier;
}
@end
@@ -0,0 +1,27 @@
#import "TGBridgeChatMessages.h"
#import "TGBridgeMessage.h"
NSString *const TGBridgeChatMessageListViewMessagesKey = @"messages";
NSString *const TGBridgeChatMessageListViewEarlierMessageIdKey = @"earlier";
NSString *const TGBridgeChatMessageListViewLaterMessageIdKey = @"later";
NSString *const TGBridgeChatMessageListViewKey = @"messageListView";
@implementation TGBridgeChatMessages
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_messages = [aDecoder decodeObjectForKey:TGBridgeChatMessageListViewMessagesKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.messages forKey:TGBridgeChatMessageListViewMessagesKey];
}
@end
@@ -0,0 +1,295 @@
#import "TGBridgeCommon.h"
NSString *const TGBridgeIncomingFileTypeKey = @"type";
NSString *const TGBridgeIncomingFileIdentifierKey = @"identifier";
NSString *const TGBridgeIncomingFileRandomIdKey = @"randomId";
NSString *const TGBridgeIncomingFilePeerIdKey = @"peerId";
NSString *const TGBridgeIncomingFileReplyToMidKey = @"replyToMid";
NSString *const TGBridgeIncomingFileTypeAudio = @"audio";
NSString *const TGBridgeIncomingFileTypeImage = @"image";
NSString *const TGBridgeResponseSubscriptionIdentifier = @"identifier";
NSString *const TGBridgeResponseTypeKey = @"type";
NSString *const TGBridgeResponseNextKey = @"next";
NSString *const TGBridgeResponseErrorKey = @"error";
@implementation TGBridgeResponse
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_subscriptionIdentifier = [aDecoder decodeInt64ForKey:TGBridgeResponseSubscriptionIdentifier];
_type = [aDecoder decodeInt32ForKey:TGBridgeResponseTypeKey];
_next = [aDecoder decodeObjectForKey:TGBridgeResponseNextKey];
_error = [aDecoder decodeObjectForKey:TGBridgeResponseErrorKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt64:self.subscriptionIdentifier forKey:TGBridgeResponseSubscriptionIdentifier];
[aCoder encodeInt32:self.type forKey:TGBridgeResponseTypeKey];
[aCoder encodeObject:self.next forKey:TGBridgeResponseNextKey];
[aCoder encodeObject:self.error forKey:TGBridgeResponseErrorKey];
}
+ (TGBridgeResponse *)single:(id)next forSubscription:(TGBridgeSubscription *)subscription
{
TGBridgeResponse *response = [[TGBridgeResponse alloc] init];
response->_subscriptionIdentifier = subscription.identifier;
response->_type = TGBridgeResponseTypeNext;
response->_next = next;
return response;
}
+ (TGBridgeResponse *)fail:(id)error forSubscription:(TGBridgeSubscription *)subscription
{
TGBridgeResponse *response = [[TGBridgeResponse alloc] init];
response->_subscriptionIdentifier = subscription.identifier;
response->_type = TGBridgeResponseTypeFailed;
response->_error = error;
return response;
}
+ (TGBridgeResponse *)completeForSubscription:(TGBridgeSubscription *)subscription
{
TGBridgeResponse *response = [[TGBridgeResponse alloc] init];
response->_subscriptionIdentifier = subscription.identifier;
response->_type = TGBridgeResponseTypeCompleted;
return response;
}
@end
NSString *const TGBridgeSubscriptionIdentifierKey = @"identifier";
NSString *const TGBridgeSubscriptionNameKey = @"name";
NSString *const TGBridgeSubscriptionParametersKey = @"parameters";
@implementation TGBridgeSubscription
- (instancetype)init
{
self = [super init];
if (self != nil)
{
int64_t randomId = 0;
arc4random_buf(&randomId, sizeof(int64_t));
_identifier = randomId;
_name = [[self class] subscriptionName];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_identifier = [aDecoder decodeInt64ForKey:TGBridgeSubscriptionIdentifierKey];
_name = [aDecoder decodeObjectForKey:TGBridgeSubscriptionNameKey];
[self _unserializeParametersWithCoder:aDecoder];
}
return self;
}
- (bool)synchronous
{
return false;
}
- (bool)renewable
{
return true;
}
- (bool)dropPreviouslyQueued
{
return false;
}
- (void)_serializeParametersWithCoder:(NSCoder *)__unused aCoder
{
}
- (void)_unserializeParametersWithCoder:(NSCoder *)__unused aDecoder
{
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt64:self.identifier forKey:TGBridgeSubscriptionIdentifierKey];
[aCoder encodeObject:self.name forKey:TGBridgeSubscriptionNameKey];
[self _serializeParametersWithCoder:aCoder];
}
+ (NSString *)subscriptionName
{
return nil;
}
@end
@implementation TGBridgeDisposal
- (instancetype)initWithIdentifier:(int64_t)identifier
{
self = [super init];
if (self != nil)
{
_identifier = identifier;
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_identifier = [aDecoder decodeInt64ForKey:TGBridgeSubscriptionIdentifierKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt64:self.identifier forKey:TGBridgeSubscriptionIdentifierKey];
}
@end
NSString *const TGBridgeFileDataKey = @"data";
NSString *const TGBridgeFileMetadataKey = @"metadata";
@implementation TGBridgeFile
- (instancetype)initWithData:(NSData *)data metadata:(NSDictionary *)metadata
{
self = [super init];
if (self != nil)
{
_data = data;
_metadata = metadata;
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_data = [aDecoder decodeObjectForKey:TGBridgeFileDataKey];
_metadata = [aDecoder decodeObjectForKey:TGBridgeFileMetadataKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.data forKey:TGBridgeFileDataKey];
[aCoder encodeObject:self.metadata forKey:TGBridgeFileMetadataKey];
}
@end
NSString *const TGBridgeSessionIdKey = @"sessionId";
@implementation TGBridgePing
- (instancetype)initWithSessionId:(int32_t)sessionId
{
self = [super init];
if (self != nil)
{
_sessionId = sessionId;
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_sessionId = [aDecoder decodeInt32ForKey:TGBridgeSessionIdKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt32:self.sessionId forKey:TGBridgeSessionIdKey];
}
@end
@implementation TGBridgeSubscriptionListRequest
- (instancetype)initWithSessionId:(int32_t)sessionId
{
self = [super init];
if (self != nil)
{
_sessionId = sessionId;
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_sessionId = [aDecoder decodeInt32ForKey:TGBridgeSessionIdKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt32:self.sessionId forKey:TGBridgeSessionIdKey];
}
@end
NSString *const TGBridgeSubscriptionListSubscriptionsKey = @"subscriptions";
@implementation TGBridgeSubscriptionList
- (instancetype)initWithArray:(NSArray *)array
{
self = [super init];
if (self != nil)
{
_subscriptions = array;
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_subscriptions = [aDecoder decodeObjectForKey:TGBridgeSubscriptionListSubscriptionsKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.subscriptions forKey:TGBridgeSubscriptionListSubscriptionsKey];
}
@end
@@ -0,0 +1,60 @@
#import "TGBridgeContactMediaAttachment.h"
//#import "../Extension/TGStringUtils.h"
const NSInteger TGBridgeContactMediaAttachmentType = 0xB90A5663;
NSString *const TGBridgeContactMediaUidKey = @"uid";
NSString *const TGBridgeContactMediaFirstNameKey = @"firstName";
NSString *const TGBridgeContactMediaLastNameKey = @"lastName";
NSString *const TGBridgeContactMediaPhoneNumberKey = @"phoneNumber";
NSString *const TGBridgeContactMediaPrettyPhoneNumberKey = @"prettyPhoneNumber";
@implementation TGBridgeContactMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_uid = [aDecoder decodeInt32ForKey:TGBridgeContactMediaUidKey];
_firstName = [aDecoder decodeObjectForKey:TGBridgeContactMediaFirstNameKey];
_lastName = [aDecoder decodeObjectForKey:TGBridgeContactMediaLastNameKey];
_phoneNumber = [aDecoder decodeObjectForKey:TGBridgeContactMediaPhoneNumberKey];
_prettyPhoneNumber = [aDecoder decodeObjectForKey:TGBridgeContactMediaPrettyPhoneNumberKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt32:self.uid forKey:TGBridgeContactMediaUidKey];
[aCoder encodeObject:self.firstName forKey:TGBridgeContactMediaFirstNameKey];
[aCoder encodeObject:self.lastName forKey:TGBridgeContactMediaLastNameKey];
[aCoder encodeObject:self.phoneNumber forKey:TGBridgeContactMediaPhoneNumberKey];
[aCoder encodeObject:self.prettyPhoneNumber forKey:TGBridgeContactMediaPrettyPhoneNumberKey];
}
- (NSString *)displayName
{
NSString *firstName = self.firstName;
NSString *lastName = self.lastName;
if (firstName != nil && firstName.length != 0 && lastName != nil && lastName.length != 0)
{
return [[NSString alloc] initWithFormat:@"%@ %@", firstName, lastName];
}
else if (firstName != nil && firstName.length != 0)
return firstName;
else if (lastName != nil && lastName.length != 0)
return lastName;
return @"";
}
+ (NSInteger)mediaType
{
return TGBridgeContactMediaAttachmentType;
}
@end
@@ -0,0 +1,101 @@
#import "TGBridgeContext.h"
#import "TGBridgeCommon.h"
//#import "TGWatchCommon.h"
NSString *const TGBridgeContextAuthorized = @"authorized";
NSString *const TGBridgeContextUserId = @"userId";
NSString *const TGBridgeContextMicAccessAllowed = @"micAccessAllowed";
NSString *const TGBridgeContextStartupData = @"startupData";
NSString *const TGBridgeContextStartupDataVersion = @"version";
@implementation TGBridgeContext
- (instancetype)initWithDictionary:(NSDictionary *)dictionary
{
self = [super init];
if (self != nil)
{
_authorized = [dictionary[TGBridgeContextAuthorized] boolValue];
_userId = (int32_t)[dictionary[TGBridgeContextUserId] intValue];
_micAccessAllowed = [dictionary[TGBridgeContextMicAccessAllowed] boolValue];
if (dictionary[TGBridgeContextStartupData] != nil) {
_preheatData = [NSKeyedUnarchiver unarchiveObjectWithData:dictionary[TGBridgeContextStartupData]];
_preheatVersion = [dictionary[TGBridgeContextStartupDataVersion] integerValue];
}
}
return self;
}
- (NSDictionary *)dictionary
{
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
dictionary[TGBridgeContextAuthorized] = @(self.authorized);
dictionary[TGBridgeContextUserId] = @(self.userId);
dictionary[TGBridgeContextMicAccessAllowed] = @(self.micAccessAllowed);
if (self.preheatData != nil) {
dictionary[TGBridgeContextStartupData] = [NSKeyedArchiver archivedDataWithRootObject:self.preheatData];
dictionary[TGBridgeContextStartupDataVersion] = @(self.preheatVersion);
}
return dictionary;
}
- (TGBridgeContext *)updatedWithAuthorized:(bool)authorized peerId:(int32_t)peerId
{
TGBridgeContext *context = [[TGBridgeContext alloc] init];
context->_authorized = authorized;
context->_userId = peerId;
context->_micAccessAllowed = self.micAccessAllowed;
if (authorized) {
context->_preheatData = self.preheatData;
context->_preheatVersion = self.preheatVersion;
}
return context;
}
- (TGBridgeContext *)updatedWithPreheatData:(NSDictionary *)data
{
TGBridgeContext *context = [[TGBridgeContext alloc] init];
context->_authorized = self.authorized;
context->_userId = self.userId;
context->_micAccessAllowed = self.micAccessAllowed;
if (data != nil) {
context->_preheatData = data;
context->_preheatVersion = (int32_t)[NSDate date].timeIntervalSinceReferenceDate;
}
return context;
}
- (TGBridgeContext *)updatedWithMicAccessAllowed:(bool)allowed
{
TGBridgeContext *context = [[TGBridgeContext alloc] init];
context->_authorized = self.authorized;
context->_userId = self.userId;
context->_micAccessAllowed = allowed;
context->_preheatData = self.preheatData;
context->_preheatVersion = self.preheatVersion;
return context;
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return true;
if (!object || ![object isKindOfClass:[self class]])
return false;
TGBridgeContext *context = (TGBridgeContext *)object;
if (context.authorized != self.authorized)
return false;
if (context.userId != self.userId)
return false;
if (context.micAccessAllowed != self.micAccessAllowed)
return false;
if (context.preheatVersion != self.preheatVersion)
return false;
return true;
}
@end
@@ -0,0 +1,84 @@
#import "TGBridgeDocumentMediaAttachment.h"
const NSInteger TGBridgeDocumentMediaAttachmentType = 0xE6C64318;
NSString *const TGBridgeDocumentMediaDocumentIdKey = @"documentId";
NSString *const TGBridgeDocumentMediaLocalDocumentIdKey = @"localDocumentId";
NSString *const TGBridgeDocumentMediaFileSizeKey = @"fileSize";
NSString *const TGBridgeDocumentMediaFileNameKey = @"fileName";
NSString *const TGBridgeDocumentMediaImageSizeKey = @"imageSize";
NSString *const TGBridgeDocumentMediaAnimatedKey = @"animated";
NSString *const TGBridgeDocumentMediaStickerKey = @"sticker";
NSString *const TGBridgeDocumentMediaStickerAltKey = @"stickerAlt";
NSString *const TGBridgeDocumentMediaStickerPackIdKey = @"stickerPackId";
NSString *const TGBridgeDocumentMediaStickerPackAccessHashKey = @"stickerPackAccessHash";
NSString *const TGBridgeDocumentMediaAudioKey = @"audio";
NSString *const TGBridgeDocumentMediaAudioTitleKey = @"title";
NSString *const TGBridgeDocumentMediaAudioPerformerKey = @"performer";
NSString *const TGBridgeDocumentMediaAudioVoice = @"voice";
NSString *const TGBridgeDocumentMediaAudioDuration = @"duration";
@implementation TGBridgeDocumentMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_documentId = [aDecoder decodeInt64ForKey:TGBridgeDocumentMediaDocumentIdKey];
_localDocumentId = [aDecoder decodeInt64ForKey:TGBridgeDocumentMediaLocalDocumentIdKey];
_fileSize = [aDecoder decodeInt32ForKey:TGBridgeDocumentMediaFileSizeKey];
_fileName = [aDecoder decodeObjectForKey:TGBridgeDocumentMediaFileNameKey];
_imageSize = [aDecoder decodeObjectForKey:TGBridgeDocumentMediaImageSizeKey];
_isAnimated = [aDecoder decodeBoolForKey:TGBridgeDocumentMediaAnimatedKey];
_isSticker = [aDecoder decodeBoolForKey:TGBridgeDocumentMediaStickerKey];
_stickerAlt = [aDecoder decodeObjectForKey:TGBridgeDocumentMediaStickerAltKey];
_stickerPackId = [aDecoder decodeInt64ForKey:TGBridgeDocumentMediaStickerPackIdKey];
_stickerPackAccessHash = [aDecoder decodeInt64ForKey:TGBridgeDocumentMediaStickerPackAccessHashKey];
_isAudio = [aDecoder decodeBoolForKey:TGBridgeDocumentMediaAudioKey];
_title = [aDecoder decodeObjectForKey:TGBridgeDocumentMediaAudioTitleKey];
_performer = [aDecoder decodeObjectForKey:TGBridgeDocumentMediaAudioPerformerKey];
_isVoice = [aDecoder decodeBoolForKey:TGBridgeDocumentMediaAudioVoice];
_duration = [aDecoder decodeInt32ForKey:TGBridgeDocumentMediaAudioDuration];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt64:self.documentId forKey:TGBridgeDocumentMediaDocumentIdKey];
[aCoder encodeInt64:self.localDocumentId forKey:TGBridgeDocumentMediaLocalDocumentIdKey];
[aCoder encodeInt32:self.fileSize forKey:TGBridgeDocumentMediaFileSizeKey];
[aCoder encodeObject:self.fileName forKey:TGBridgeDocumentMediaFileNameKey];
[aCoder encodeObject:self.imageSize forKey:TGBridgeDocumentMediaImageSizeKey];
[aCoder encodeBool:self.isAnimated forKey:TGBridgeDocumentMediaAnimatedKey];
[aCoder encodeBool:self.isSticker forKey:TGBridgeDocumentMediaStickerKey];
[aCoder encodeObject:self.stickerAlt forKey:TGBridgeDocumentMediaStickerAltKey];
[aCoder encodeInt64:self.stickerPackId forKey:TGBridgeDocumentMediaStickerPackIdKey];
[aCoder encodeInt64:self.stickerPackAccessHash forKey:TGBridgeDocumentMediaStickerPackAccessHashKey];
[aCoder encodeBool:self.isAudio forKey:TGBridgeDocumentMediaAudioKey];
[aCoder encodeObject:self.title forKey:TGBridgeDocumentMediaAudioTitleKey];
[aCoder encodeObject:self.performer forKey:TGBridgeDocumentMediaAudioPerformerKey];
[aCoder encodeBool:self.isVoice forKey:TGBridgeDocumentMediaAudioVoice];
[aCoder encodeInt32:self.duration forKey:TGBridgeDocumentMediaAudioDuration];
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return YES;
if (!object || ![object isKindOfClass:[self class]])
return NO;
TGBridgeDocumentMediaAttachment *document = (TGBridgeDocumentMediaAttachment *)object;
return (self.localDocumentId == 0 && self.documentId == document.documentId) || (self.localDocumentId != 0 && self.localDocumentId == document.localDocumentId);
}
+ (NSInteger)mediaType
{
return TGBridgeDocumentMediaAttachmentType;
}
@end
@@ -0,0 +1,35 @@
#import "TGBridgeForwardedMessageMediaAttachment.h"
const NSInteger TGBridgeForwardedMessageMediaAttachmentType = 0xAA1050C1;
NSString *const TGBridgeForwardedMessageMediaPeerIdKey = @"peerId";
NSString *const TGBridgeForwardedMessageMediaMidKey = @"mid";
NSString *const TGBridgeForwardedMessageMediaDateKey = @"date";
@implementation TGBridgeForwardedMessageMediaAttachment
- (nullable instancetype)initWithCoder:(nonnull NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_peerId = [aDecoder decodeInt64ForKey:TGBridgeForwardedMessageMediaPeerIdKey];
_mid = [aDecoder decodeInt32ForKey:TGBridgeForwardedMessageMediaMidKey];
_date = [aDecoder decodeInt32ForKey:TGBridgeForwardedMessageMediaDateKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt64:self.peerId forKey:TGBridgeForwardedMessageMediaPeerIdKey];
[aCoder encodeInt32:self.mid forKey:TGBridgeForwardedMessageMediaMidKey];
[aCoder encodeInt32:self.date forKey:TGBridgeForwardedMessageMediaDateKey];
}
+ (NSInteger)mediaType
{
return TGBridgeForwardedMessageMediaAttachmentType;
}
@end
@@ -0,0 +1,33 @@
#import "TGBridgeImageMediaAttachment.h"
#import <UIKit/UIKit.h>
const NSInteger TGBridgeImageMediaAttachmentType = 0x269BD8A8;
NSString *const TGBridgeImageMediaImageIdKey = @"imageId";
NSString *const TGBridgeImageMediaDimensionsKey = @"dimensions";
@implementation TGBridgeImageMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_imageId = [aDecoder decodeInt64ForKey:TGBridgeImageMediaImageIdKey];
_dimensions = [aDecoder decodeCGSizeForKey:TGBridgeImageMediaDimensionsKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt64:self.imageId forKey:TGBridgeImageMediaImageIdKey];
[aCoder encodeCGSize:self.dimensions forKey:TGBridgeImageMediaDimensionsKey];
}
+ (NSInteger)mediaType
{
return TGBridgeImageMediaAttachmentType;
}
@end
@@ -0,0 +1,95 @@
#import "TGBridgeLocationMediaAttachment.h"
const NSInteger TGBridgeLocationMediaAttachmentType = 0x0C9ED06E;
NSString *const TGBridgeLocationMediaLatitudeKey = @"lat";
NSString *const TGBridgeLocationMediaLongitudeKey = @"lon";
NSString *const TGBridgeLocationMediaVenueKey = @"venue";
NSString *const TGBridgeVenueTitleKey = @"title";
NSString *const TGBridgeVenueAddressKey = @"address";
NSString *const TGBridgeVenueProviderKey = @"provider";
NSString *const TGBridgeVenueIdKey = @"venueId";
@implementation TGBridgeVenueAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_title = [aDecoder decodeObjectForKey:TGBridgeVenueTitleKey];
_address = [aDecoder decodeObjectForKey:TGBridgeVenueAddressKey];
_provider = [aDecoder decodeObjectForKey:TGBridgeVenueProviderKey];
_venueId = [aDecoder decodeObjectForKey:TGBridgeVenueIdKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.title forKey:TGBridgeVenueTitleKey];
[aCoder encodeObject:self.address forKey:TGBridgeVenueAddressKey];
[aCoder encodeObject:self.provider forKey:TGBridgeVenueProviderKey];
[aCoder encodeObject:self.venueId forKey:TGBridgeVenueIdKey];
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return YES;
if (!object || ![object isKindOfClass:[self class]])
return NO;
TGBridgeVenueAttachment *venue = (TGBridgeVenueAttachment *)object;
return [self.title isEqualToString:venue.title] && [self.address isEqualToString:venue.address] && [self.provider isEqualToString:venue.provider] && [self.venueId isEqualToString:venue.venueId];
}
@end
@implementation TGBridgeLocationMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_latitude = [aDecoder decodeDoubleForKey:TGBridgeLocationMediaLatitudeKey];
_longitude = [aDecoder decodeDoubleForKey:TGBridgeLocationMediaLongitudeKey];
_venue = [aDecoder decodeObjectForKey:TGBridgeLocationMediaVenueKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeDouble:self.latitude forKey:TGBridgeLocationMediaLatitudeKey];
[aCoder encodeDouble:self.longitude forKey:TGBridgeLocationMediaLongitudeKey];
[aCoder encodeObject:self.venue forKey:TGBridgeLocationMediaVenueKey];
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return YES;
if (!object || ![object isKindOfClass:[self class]])
return NO;
TGBridgeLocationMediaAttachment *location = (TGBridgeLocationMediaAttachment *)object;
bool equalCoord = (fabs(self.latitude - location.latitude) < DBL_EPSILON && fabs(self.longitude - location.longitude) < DBL_EPSILON);
bool equalVenue = (self.venue == nil && location.venue == nil) || ([self.venue isEqual:location.venue]);
return equalCoord || equalVenue;
}
+ (NSInteger)mediaType
{
return TGBridgeLocationMediaAttachmentType;
}
@end
@@ -0,0 +1,66 @@
#import "TGBridgeLocationVenue.h"
#import "TGBridgeLocationMediaAttachment.h"
NSString *const TGBridgeLocationVenueLatitudeKey = @"lat";
NSString *const TGBridgeLocationVenueLongitudeKey = @"lon";
NSString *const TGBridgeLocationVenueIdentifierKey = @"identifier";
NSString *const TGBridgeLocationVenueProviderKey = @"provider";
NSString *const TGBridgeLocationVenueNameKey = @"name";
NSString *const TGBridgeLocationVenueAddressKey = @"address";
@implementation TGBridgeLocationVenue
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_coordinate = CLLocationCoordinate2DMake([aDecoder decodeDoubleForKey:TGBridgeLocationVenueLatitudeKey], [aDecoder decodeDoubleForKey:TGBridgeLocationVenueLongitudeKey]);
_identifier = [aDecoder decodeObjectForKey:TGBridgeLocationVenueIdentifierKey];
_provider = [aDecoder decodeObjectForKey:TGBridgeLocationVenueProviderKey];
_name = [aDecoder decodeObjectForKey:TGBridgeLocationVenueNameKey];
_address = [aDecoder decodeObjectForKey:TGBridgeLocationVenueAddressKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeDouble:self.coordinate.latitude forKey:TGBridgeLocationVenueLatitudeKey];
[aCoder encodeDouble:self.coordinate.longitude forKey:TGBridgeLocationVenueLongitudeKey];
[aCoder encodeObject:self.identifier forKey:TGBridgeLocationVenueIdentifierKey];
[aCoder encodeObject:self.provider forKey:TGBridgeLocationVenueProviderKey];
[aCoder encodeObject:self.name forKey:TGBridgeLocationVenueNameKey];
[aCoder encodeObject:self.address forKey:TGBridgeLocationVenueAddressKey];
}
- (TGBridgeLocationMediaAttachment *)locationAttachment
{
TGBridgeLocationMediaAttachment *attachment = [[TGBridgeLocationMediaAttachment alloc] init];
attachment.latitude = self.coordinate.latitude;
attachment.longitude = self.coordinate.longitude;
TGBridgeVenueAttachment *venueAttachment = [[TGBridgeVenueAttachment alloc] init];
venueAttachment.title = self.name;
venueAttachment.address = self.address;
venueAttachment.provider = self.provider;
venueAttachment.venueId = self.identifier;
attachment.venue = venueAttachment;
return attachment;
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return YES;
if (!object || ![object isKindOfClass:[self class]])
return NO;
return [self.identifier isEqualToString:((TGBridgeLocationVenue *)object).identifier];
}
@end
@@ -0,0 +1,32 @@
#import "TGBridgeMediaAttachment.h"
NSString *const TGBridgeMediaAttachmentTypeKey = @"type";
@implementation TGBridgeMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)__unused aDecoder
{
self = [super init];
if (self != nil)
{
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)__unused aCoder
{
}
- (NSInteger)mediaType
{
return 0;
}
+ (NSInteger)mediaType
{
return 0;
}
@end
@@ -0,0 +1,242 @@
#import "TGBridgeMessage.h"
//#import "TGWatchCommon.h"
#import "TGBridgePeerIdAdapter.h"
NSString *const TGBridgeMessageIdentifierKey = @"identifier";
NSString *const TGBridgeMessageDateKey = @"date";
NSString *const TGBridgeMessageRandomIdKey = @"randomId";
NSString *const TGBridgeMessageFromUidKey = @"fromUid";
NSString *const TGBridgeMessageCidKey = @"cid";
NSString *const TGBridgeMessageTextKey = @"text";
NSString *const TGBridgeMessageUnreadKey = @"unread";
NSString *const TGBridgeMessageOutgoingKey = @"outgoing";
NSString *const TGBridgeMessageMediaKey = @"media";
NSString *const TGBridgeMessageDeliveryStateKey = @"deliveryState";
NSString *const TGBridgeMessageForceReplyKey = @"forceReply";
NSString *const TGBridgeMessageKey = @"message";
NSString *const TGBridgeMessagesArrayKey = @"messages";
@interface TGBridgeMessage ()
{
NSArray *_textCheckingResults;
}
@end
@implementation TGBridgeMessage
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_identifier = [aDecoder decodeInt32ForKey:TGBridgeMessageIdentifierKey];
_date = [aDecoder decodeDoubleForKey:TGBridgeMessageDateKey];
_randomId = [aDecoder decodeInt64ForKey:TGBridgeMessageRandomIdKey];
_fromUid = [aDecoder decodeInt64ForKey:TGBridgeMessageFromUidKey];
_cid = [aDecoder decodeInt64ForKey:TGBridgeMessageCidKey];
_text = [aDecoder decodeObjectForKey:TGBridgeMessageTextKey];
_outgoing = [aDecoder decodeBoolForKey:TGBridgeMessageOutgoingKey];
_unread = [aDecoder decodeBoolForKey:TGBridgeMessageUnreadKey];
_deliveryState = [aDecoder decodeInt32ForKey:TGBridgeMessageDeliveryStateKey];
_media = [aDecoder decodeObjectForKey:TGBridgeMessageMediaKey];
_forceReply = [aDecoder decodeBoolForKey:TGBridgeMessageForceReplyKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt32:self.identifier forKey:TGBridgeMessageIdentifierKey];
[aCoder encodeDouble:self.date forKey:TGBridgeMessageDateKey];
[aCoder encodeInt64:self.randomId forKey:TGBridgeMessageRandomIdKey];
[aCoder encodeInt64:self.fromUid forKey:TGBridgeMessageFromUidKey];
[aCoder encodeInt64:self.cid forKey:TGBridgeMessageCidKey];
[aCoder encodeObject:self.text forKey:TGBridgeMessageTextKey];
[aCoder encodeBool:self.outgoing forKey:TGBridgeMessageOutgoingKey];
[aCoder encodeBool:self.unread forKey:TGBridgeMessageUnreadKey];
[aCoder encodeInt32:self.deliveryState forKey:TGBridgeMessageDeliveryStateKey];
[aCoder encodeObject:self.media forKey:TGBridgeMessageMediaKey];
[aCoder encodeBool:self.forceReply forKey:TGBridgeMessageForceReplyKey];
}
- (NSArray<NSNumber *> *)involvedUserIds
{
NSMutableSet<NSNumber *> *userIds = [[NSMutableSet alloc] init];
if (!TGPeerIdIsChannel(self.fromUid))
[userIds addObject:[NSNumber numberWithLongLong:self.fromUid]];
for (TGBridgeMediaAttachment *attachment in self.media)
{
if ([attachment isKindOfClass:[TGBridgeContactMediaAttachment class]])
{
TGBridgeContactMediaAttachment *contactAttachment = (TGBridgeContactMediaAttachment *)attachment;
if (contactAttachment.uid != 0)
[userIds addObject:[NSNumber numberWithLongLong:contactAttachment.uid]];
}
else if ([attachment isKindOfClass:[TGBridgeForwardedMessageMediaAttachment class]])
{
TGBridgeForwardedMessageMediaAttachment *forwardAttachment = (TGBridgeForwardedMessageMediaAttachment *)attachment;
if (forwardAttachment.peerId != 0 && !TGPeerIdIsChannel(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 addObject:[NSNumber numberWithLongLong:replyAttachment.message.fromUid]];
}
else if ([attachment isKindOfClass:[TGBridgeActionMediaAttachment class]])
{
TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment;
if (actionAttachment.actionData[@"uid"] != nil)
[userIds addObject:[NSNumber numberWithLongLong:[actionAttachment.actionData[@"uid"] intValue]]];
}
}
NSMutableArray *result = [[NSMutableArray alloc] init];
for (NSNumber *object in userIds) {
[result addObject:object];
}
return result;
}
- (NSArray *)textCheckingResults
{
if (_textCheckingResults == nil)
{
NSMutableArray *results = [[NSMutableArray alloc] init];
NSArray *entities = nil;
for (TGBridgeMediaAttachment *attachment in self.media)
{
if ([attachment isKindOfClass:[TGBridgeMessageEntitiesAttachment class]])
{
entities = ((TGBridgeMessageEntitiesAttachment *)attachment).entities;
break;
}
}
for (TGBridgeMessageEntity *entity in entities)
{
TGBridgeTextCheckingResult *result = [[TGBridgeTextCheckingResult alloc] init];
result.range = entity.range;
if ([entity isKindOfClass:[TGBridgeMessageEntityBold class]])
result.type = TGBridgeTextCheckingResultTypeBold;
else if ([entity isKindOfClass:[TGBridgeMessageEntityItalic class]])
result.type = TGBridgeTextCheckingResultTypeItalic;
else if ([entity isKindOfClass:[TGBridgeMessageEntityCode class]])
result.type = TGBridgeTextCheckingResultTypeCode;
else if ([entity isKindOfClass:[TGBridgeMessageEntityPre class]])
result.type = TGBridgeTextCheckingResultTypePre;
if (result.type != TGBridgeTextCheckingResultTypeUndefined)
[results addObject:result];
}
_textCheckingResults = results;
}
return _textCheckingResults;
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return YES;
if (!object || ![object isKindOfClass:[self class]])
return NO;
TGBridgeMessage *message = (TGBridgeMessage *)object;
if (self.randomId != 0)
return self.randomId == message.randomId;
else
return self.identifier == message.identifier;
}
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId
{
return [self temporaryNewMessageForText:text userId:userId replyToMessage:nil];
}
+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId replyToMessage:(TGBridgeMessage *)replyToMessage
{
int64_t randomId = 0;
arc4random_buf(&randomId, 8);
int32_t messageId = 0;
arc4random_buf(&messageId, 4);
TGBridgeMessage *message = [[TGBridgeMessage alloc] init];
message->_identifier = -abs(messageId);
message->_fromUid = userId;
message->_randomId = randomId;
message->_unread = true;
message->_outgoing = true;
message->_deliveryState = TGBridgeMessageDeliveryStatePending;
message->_text = text;
message->_date = [[NSDate date] timeIntervalSince1970];
if (replyToMessage != nil)
{
TGBridgeReplyMessageMediaAttachment *replyAttachment = [[TGBridgeReplyMessageMediaAttachment alloc] init];
replyAttachment.mid = replyToMessage.identifier;
replyAttachment.message = replyToMessage;
message->_media = @[ replyToMessage ];
}
return message;
}
+ (instancetype)temporaryNewMessageForSticker:(TGBridgeDocumentMediaAttachment *)sticker userId:(int32_t)userId
{
return [self _temporaryNewMessageForMediaAttachment:sticker userId:userId];
}
+ (instancetype)temporaryNewMessageForLocation:(TGBridgeLocationMediaAttachment *)location userId:(int32_t)userId
{
return [self _temporaryNewMessageForMediaAttachment:location userId:userId];
}
+ (instancetype)temporaryNewMessageForAudioWithDuration:(int32_t)duration userId:(int32_t)userId localAudioId:(int64_t)localAudioId
{
TGBridgeDocumentMediaAttachment *document = [[TGBridgeDocumentMediaAttachment alloc] init];
document.isAudio = true;
document.isVoice = true;
document.localDocumentId = localAudioId;
document.duration = duration;
return [self _temporaryNewMessageForMediaAttachment:document userId:userId];
}
+ (instancetype)_temporaryNewMessageForMediaAttachment:(TGBridgeMediaAttachment *)attachment userId:(int32_t)userId
{
int64_t randomId = 0;
arc4random_buf(&randomId, 8);
int32_t messageId = 0;
arc4random_buf(&messageId, 4);
TGBridgeMessage *message = [[TGBridgeMessage alloc] init];
message->_identifier = -abs(messageId);
message->_fromUid = userId;
message->_unread = true;
message->_outgoing = true;
message->_deliveryState = TGBridgeMessageDeliveryStatePending;
message->_date = [[NSDate date] timeIntervalSince1970];
message->_media = @[ attachment ];
return message;
}
@end
@implementation TGBridgeTextCheckingResult
@end
@@ -0,0 +1,83 @@
#import "TGBridgeMessageEntities.h"
NSString *const TGBridgeMessageEntityLocationKey = @"loc";
NSString *const TGBridgeMessageEntityLengthKey = @"len";
@implementation TGBridgeMessageEntity
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
NSUInteger loc = [aDecoder decodeIntegerForKey:TGBridgeMessageEntityLocationKey];
NSUInteger len = [aDecoder decodeIntegerForKey:TGBridgeMessageEntityLengthKey];
_range = NSMakeRange(loc, len);
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInteger:self.range.location forKey:TGBridgeMessageEntityLocationKey];
[aCoder encodeInteger:self.range.length forKey:TGBridgeMessageEntityLengthKey];
}
+ (instancetype)entitityWithRange:(NSRange)range
{
TGBridgeMessageEntity *entity = [[self alloc] init];
entity.range = range;
return entity;
}
@end
@implementation TGBridgeMessageEntityUrl
@end
@implementation TGBridgeMessageEntityEmail
@end
@implementation TGBridgeMessageEntityTextUrl
@end
@implementation TGBridgeMessageEntityMention
@end
@implementation TGBridgeMessageEntityHashtag
@end
@implementation TGBridgeMessageEntityBotCommand
@end
@implementation TGBridgeMessageEntityBold
@end
@implementation TGBridgeMessageEntityItalic
@end
@implementation TGBridgeMessageEntityCode
@end
@implementation TGBridgeMessageEntityPre
@end
@@ -0,0 +1,30 @@
#import "TGBridgeMessageEntitiesAttachment.h"
const NSInteger TGBridgeMessageEntitiesAttachmentType = 0x8c2e3cce;
NSString *const TGBridgeMessageEntitiesKey = @"entities";
@implementation TGBridgeMessageEntitiesAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_entities = [aDecoder decodeObjectForKey:TGBridgeMessageEntitiesKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.entities forKey:TGBridgeMessageEntitiesKey];
}
+ (NSInteger)mediaType
{
return TGBridgeMessageEntitiesAttachmentType;
}
@end
@@ -0,0 +1,22 @@
#import "TGBridgePeerNotificationSettings.h"
NSString *const TGBridgePeerNotificationSettingsMuteForKey = @"muteFor";
@implementation TGBridgePeerNotificationSettings
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_muteFor = [aDecoder decodeInt32ForKey:TGBridgePeerNotificationSettingsMuteForKey];
}
return self;
}
- (void)encodeWithCoder:(nonnull NSCoder *)aCoder
{
[aCoder encodeInt32:self.muteFor forKey:TGBridgePeerNotificationSettingsMuteForKey];
}
@end
@@ -0,0 +1,29 @@
#import "TGBridgeReplyMarkupMediaAttachment.h"
const NSInteger TGBridgeReplyMarkupMediaAttachmentType = 0x5678acc1;
NSString *const TGBridgeReplyMarkupMediaMessageKey = @"replyMarkup";
@implementation TGBridgeReplyMarkupMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_replyMarkup = [aDecoder decodeObjectForKey:TGBridgeReplyMarkupMediaMessageKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.replyMarkup forKey:TGBridgeReplyMarkupMediaMessageKey];
}
+ (NSInteger)mediaType
{
return TGBridgeReplyMarkupMediaAttachmentType;
}
@end
@@ -0,0 +1,33 @@
#import "TGBridgeReplyMessageMediaAttachment.h"
#import "TGBridgeMessage.h"
const NSInteger TGBridgeReplyMessageMediaAttachmentType = 414002169;
NSString *const TGBridgeReplyMessageMediaMidKey = @"mid";
NSString *const TGBridgeReplyMessageMediaMessageKey = @"message";
@implementation TGBridgeReplyMessageMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_mid = [aDecoder decodeInt32ForKey:TGBridgeReplyMessageMediaMidKey];
_message = [aDecoder decodeObjectForKey:TGBridgeReplyMessageMediaMessageKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt32:self.mid forKey:TGBridgeReplyMessageMediaMidKey];
[aCoder encodeObject:self.message forKey:TGBridgeReplyMessageMediaMessageKey];
}
+ (NSInteger)mediaType
{
return TGBridgeReplyMessageMediaAttachmentType;
}
@end
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,35 @@
#import "TGBridgeUnsupportedMediaAttachment.h"
const NSInteger TGBridgeUnsupportedMediaAttachmentType = 0x3837BEF7;
NSString *const TGBridgeUnsupportedMediaCompactTitleKey = @"compactTitle";
NSString *const TGBridgeUnsupportedMediaTitleKey = @"title";
NSString *const TGBridgeUnsupportedMediaSubtitleKey = @"subtitle";
@implementation TGBridgeUnsupportedMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_compactTitle = [aDecoder decodeObjectForKey:TGBridgeUnsupportedMediaCompactTitleKey];
_title = [aDecoder decodeObjectForKey:TGBridgeUnsupportedMediaTitleKey];
_subtitle = [aDecoder decodeObjectForKey:TGBridgeUnsupportedMediaSubtitleKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.compactTitle forKey:TGBridgeUnsupportedMediaCompactTitleKey];
[aCoder encodeObject:self.title forKey:TGBridgeUnsupportedMediaTitleKey];
[aCoder encodeObject:self.subtitle forKey:TGBridgeUnsupportedMediaSubtitleKey];
}
+ (NSInteger)mediaType
{
return TGBridgeUnsupportedMediaAttachmentType;
}
@end
@@ -0,0 +1,286 @@
#import "TGBridgeUser.h"
//#import "TGWatchCommon.h"
#import "TGBridgeBotInfo.h"
//#import "../Extension/TGStringUtils.h"
NSString *const TGBridgeUserIdentifierKey = @"identifier";
NSString *const TGBridgeUserFirstNameKey = @"firstName";
NSString *const TGBridgeUserLastNameKey = @"lastName";
NSString *const TGBridgeUserUserNameKey = @"userName";
NSString *const TGBridgeUserPhoneNumberKey = @"phoneNumber";
NSString *const TGBridgeUserPrettyPhoneNumberKey = @"prettyPhoneNumber";
NSString *const TGBridgeUserOnlineKey = @"online";
NSString *const TGBridgeUserLastSeenKey = @"lastSeen";
NSString *const TGBridgeUserPhotoSmallKey = @"photoSmall";
NSString *const TGBridgeUserPhotoBigKey = @"photoBig";
NSString *const TGBridgeUserKindKey = @"kind";
NSString *const TGBridgeUserBotKindKey = @"botKind";
NSString *const TGBridgeUserBotVersionKey = @"botVersion";
NSString *const TGBridgeUserVerifiedKey = @"verified";
NSString *const TGBridgeUserAboutKey = @"about";
NSString *const TGBridgeUserVersionKey = @"version";
NSString *const TGBridgeUsersDictionaryKey = @"users";
@implementation TGBridgeUser
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_identifier = [aDecoder decodeInt64ForKey:TGBridgeUserIdentifierKey];
_firstName = [aDecoder decodeObjectForKey:TGBridgeUserFirstNameKey];
_lastName = [aDecoder decodeObjectForKey:TGBridgeUserLastNameKey];
_userName = [aDecoder decodeObjectForKey:TGBridgeUserUserNameKey];
_phoneNumber = [aDecoder decodeObjectForKey:TGBridgeUserPhoneNumberKey];
_prettyPhoneNumber = [aDecoder decodeObjectForKey:TGBridgeUserPrettyPhoneNumberKey];
_online = [aDecoder decodeBoolForKey:TGBridgeUserOnlineKey];
_lastSeen = [aDecoder decodeDoubleForKey:TGBridgeUserLastSeenKey];
_photoSmall = [aDecoder decodeObjectForKey:TGBridgeUserPhotoSmallKey];
_photoBig = [aDecoder decodeObjectForKey:TGBridgeUserPhotoBigKey];
_kind = [aDecoder decodeInt32ForKey:TGBridgeUserKindKey];
_botKind = [aDecoder decodeInt32ForKey:TGBridgeUserBotKindKey];
_botVersion = [aDecoder decodeInt32ForKey:TGBridgeUserBotVersionKey];
_verified = [aDecoder decodeBoolForKey:TGBridgeUserVerifiedKey];
_about = [aDecoder decodeObjectForKey:TGBridgeUserAboutKey];
_userVersion = [aDecoder decodeInt32ForKey:TGBridgeUserVersionKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt64:self.identifier forKey:TGBridgeUserIdentifierKey];
[aCoder encodeObject:self.firstName forKey:TGBridgeUserFirstNameKey];
[aCoder encodeObject:self.lastName forKey:TGBridgeUserLastNameKey];
[aCoder encodeObject:self.userName forKey:TGBridgeUserUserNameKey];
[aCoder encodeObject:self.phoneNumber forKey:TGBridgeUserPhoneNumberKey];
[aCoder encodeObject:self.prettyPhoneNumber forKey:TGBridgeUserPrettyPhoneNumberKey];
[aCoder encodeBool:self.online forKey:TGBridgeUserOnlineKey];
[aCoder encodeDouble:self.lastSeen forKey:TGBridgeUserLastSeenKey];
[aCoder encodeObject:self.photoSmall forKey:TGBridgeUserPhotoSmallKey];
[aCoder encodeObject:self.photoBig forKey:TGBridgeUserPhotoBigKey];
[aCoder encodeInt32:self.kind forKey:TGBridgeUserKindKey];
[aCoder encodeInt32:self.botKind forKey:TGBridgeUserBotKindKey];
[aCoder encodeInt32:self.botVersion forKey:TGBridgeUserBotVersionKey];
[aCoder encodeBool:self.verified forKey:TGBridgeUserVerifiedKey];
[aCoder encodeObject:self.about forKey:TGBridgeUserAboutKey];
[aCoder encodeInt32:self.userVersion forKey:TGBridgeUserVersionKey];
}
- (instancetype)copyWithZone:(NSZone *)__unused zone
{
TGBridgeUser *user = [[TGBridgeUser alloc] init];
user->_identifier = self.identifier;
user->_firstName = self.firstName;
user->_lastName = self.lastName;
user->_userName = self.userName;
user->_phoneNumber = self.phoneNumber;
user->_prettyPhoneNumber = self.prettyPhoneNumber;
user->_online = self.online;
user->_lastSeen = self.lastSeen;
user->_photoSmall = self.photoSmall;
user->_photoBig = self.photoBig;
user->_kind = self.kind;
user->_botKind = self.botKind;
user->_botVersion = self.botVersion;
user->_verified = self.verified;
user->_about = self.about;
user->_userVersion = self.userVersion;
return user;
}
- (NSString *)displayName
{
NSString *firstName = self.firstName;
NSString *lastName = self.lastName;
if (firstName != nil && firstName.length != 0 && lastName != nil && lastName.length != 0)
{
return [[NSString alloc] initWithFormat:@"%@ %@", firstName, lastName];
}
else if (firstName != nil && firstName.length != 0)
return firstName;
else if (lastName != nil && lastName.length != 0)
return lastName;
return @"";
}
- (bool)isBot
{
return (self.kind == TGBridgeUserKindBot || self.kind ==TGBridgeUserKindSmartBot);
}
- (TGBridgeUserChange *)changeFromUser:(TGBridgeUser *)user
{
NSMutableDictionary *fields = [[NSMutableDictionary alloc] init];
[self _compareString:self.firstName oldString:user.firstName dict:fields key:TGBridgeUserFirstNameKey];
[self _compareString:self.lastName oldString:user.lastName dict:fields key:TGBridgeUserLastNameKey];
[self _compareString:self.userName oldString:user.userName dict:fields key:TGBridgeUserUserNameKey];
[self _compareString:self.phoneNumber oldString:user.phoneNumber dict:fields key:TGBridgeUserPhoneNumberKey];
[self _compareString:self.prettyPhoneNumber oldString:user.prettyPhoneNumber dict:fields key:TGBridgeUserPrettyPhoneNumberKey];
if (self.online != user.online)
fields[TGBridgeUserOnlineKey] = @(self.online);
if (fabs(self.lastSeen - user.lastSeen) > DBL_EPSILON)
fields[TGBridgeUserLastSeenKey] = @(self.lastSeen);
[self _compareString:self.photoSmall oldString:user.photoSmall dict:fields key:TGBridgeUserPhotoSmallKey];
[self _compareString:self.photoBig oldString:user.photoBig dict:fields key:TGBridgeUserPhotoBigKey];
if (self.kind != user.kind)
fields[TGBridgeUserKindKey] = @(self.kind);
if (self.botKind != user.botKind)
fields[TGBridgeUserBotKindKey] = @(self.botKind);
if (self.botVersion != user.botVersion)
fields[TGBridgeUserBotVersionKey] = @(self.botVersion);
if (self.verified != user.verified)
fields[TGBridgeUserVerifiedKey] = @(self.verified);
if (fields.count == 0)
return nil;
return [[TGBridgeUserChange alloc] initWithUserIdentifier:user.identifier fields:fields];
}
- (void)_compareString:(NSString *)newString oldString:(NSString *)oldString dict:(NSMutableDictionary *)dict key:(NSString *)key
{
if (newString == nil && oldString == nil)
return;
if (![newString isEqualToString:oldString])
{
if (newString == nil)
dict[key] = [NSNull null];
else
dict[key] = newString;
}
}
- (TGBridgeUser *)userByApplyingChange:(TGBridgeUserChange *)change
{
if (change.userIdentifier != self.identifier)
return nil;
TGBridgeUser *user = [self copy];
NSString *firstNameChange = change.fields[TGBridgeUserFirstNameKey];
if (firstNameChange != nil)
user->_firstName = [self _stringForFieldChange:firstNameChange];
NSString *lastNameChange = change.fields[TGBridgeUserLastNameKey];
if (lastNameChange != nil)
user->_lastName = [self _stringForFieldChange:lastNameChange];
NSString *userNameChange = change.fields[TGBridgeUserUserNameKey];
if (userNameChange != nil)
user->_userName = [self _stringForFieldChange:userNameChange];
NSString *phoneNumberChange = change.fields[TGBridgeUserPhoneNumberKey];
if (phoneNumberChange != nil)
user->_phoneNumber = [self _stringForFieldChange:phoneNumberChange];
NSString *prettyPhoneNumberChange = change.fields[TGBridgeUserPrettyPhoneNumberKey];
if (prettyPhoneNumberChange != nil)
user->_prettyPhoneNumber = [self _stringForFieldChange:prettyPhoneNumberChange];
NSNumber *onlineChange = change.fields[TGBridgeUserOnlineKey];
if (onlineChange != nil)
user->_online = [onlineChange boolValue];
NSNumber *lastSeenChange = change.fields[TGBridgeUserLastSeenKey];
if (lastSeenChange != nil)
user->_lastSeen = [lastSeenChange doubleValue];
NSString *photoSmallChange = change.fields[TGBridgeUserPhotoSmallKey];
if (photoSmallChange != nil)
user->_photoSmall = [self _stringForFieldChange:photoSmallChange];
NSString *photoBigChange = change.fields[TGBridgeUserPhotoBigKey];
if (photoBigChange != nil)
user->_photoBig = [self _stringForFieldChange:photoBigChange];
NSNumber *kindChange = change.fields[TGBridgeUserKindKey];
if (kindChange != nil)
user->_kind = (int32_t)[kindChange intValue];
NSNumber *botKindChange = change.fields[TGBridgeUserBotKindKey];
if (botKindChange != nil)
user->_botKind = (int32_t)[botKindChange intValue];
NSNumber *botVersionChange = change.fields[TGBridgeUserBotVersionKey];
if (botVersionChange != nil)
user->_botVersion = (int32_t)[botVersionChange intValue];
NSNumber *verifiedChange = change.fields[TGBridgeUserVerifiedKey];
if (verifiedChange != nil)
user->_verified = [verifiedChange boolValue];
return user;
}
- (NSString *)_stringForFieldChange:(NSString *)fieldChange
{
if ([fieldChange isKindOfClass:[NSNull class]])
return nil;
return fieldChange;
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return YES;
if (!object || ![object isKindOfClass:[self class]])
return NO;
return self.identifier == ((TGBridgeUser *)object).identifier;
}
@end
NSString *const TGBridgeUserChangeIdentifierKey = @"userIdentifier";
NSString *const TGBridgeUserChangeFieldsKey = @"fields";
@implementation TGBridgeUserChange
- (instancetype)initWithUserIdentifier:(int32_t)userIdentifier fields:(NSDictionary *)fields
{
self = [super init];
if (self != nil)
{
_userIdentifier = userIdentifier;
_fields = fields;
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_userIdentifier = [aDecoder decodeInt32ForKey:TGBridgeUserChangeIdentifierKey];
_fields = [aDecoder decodeObjectForKey:TGBridgeUserChangeFieldsKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt32:self.userIdentifier forKey:TGBridgeUserChangeIdentifierKey];
[aCoder encodeObject:self.fields forKey:TGBridgeUserChangeFieldsKey];
}
@end
@@ -0,0 +1,39 @@
#import "TGBridgeVideoMediaAttachment.h"
#import <UIKit/UIKit.h>
const NSInteger TGBridgeVideoMediaAttachmentType = 0x338EAA20;
NSString *const TGBridgeVideoMediaVideoIdKey = @"videoId";
NSString *const TGBridgeVideoMediaDimensionsKey = @"dimensions";
NSString *const TGBridgeVideoMediaDurationKey = @"duration";
NSString *const TGBridgeVideoMediaRoundKey = @"round";
@implementation TGBridgeVideoMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_videoId = [aDecoder decodeInt64ForKey:TGBridgeVideoMediaVideoIdKey];
_dimensions = [aDecoder decodeCGSizeForKey:TGBridgeVideoMediaDimensionsKey];
_duration = [aDecoder decodeInt32ForKey:TGBridgeVideoMediaDurationKey];
_round = [aDecoder decodeBoolForKey:TGBridgeVideoMediaRoundKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt64:self.videoId forKey:TGBridgeVideoMediaVideoIdKey];
[aCoder encodeCGSize:self.dimensions forKey:TGBridgeVideoMediaDimensionsKey];
[aCoder encodeInt32:self.duration forKey:TGBridgeVideoMediaDurationKey];
[aCoder encodeBool:self.round forKey:TGBridgeVideoMediaRoundKey];
}
+ (NSInteger)mediaType
{
return TGBridgeVideoMediaAttachmentType;
}
@end
@@ -0,0 +1,65 @@
#import "TGBridgeWebPageMediaAttachment.h"
#import "TGBridgeImageMediaAttachment.h"
#import <UIKit/UIKit.h>
const NSInteger TGBridgeWebPageMediaAttachmentType = 0x584197af;
NSString *const TGBridgeWebPageMediaWebPageIdKey = @"webPageId";
NSString *const TGBridgeWebPageMediaUrlKey = @"url";
NSString *const TGBridgeWebPageMediaDisplayUrlKey = @"displayUrl";
NSString *const TGBridgeWebPageMediaPageTypeKey = @"pageType";
NSString *const TGBridgeWebPageMediaSiteNameKey = @"siteName";
NSString *const TGBridgeWebPageMediaTitleKey = @"title";
NSString *const TGBridgeWebPageMediaPageDescriptionKey = @"pageDescription";
NSString *const TGBridgeWebPageMediaPhotoKey = @"photo";
NSString *const TGBridgeWebPageMediaEmbedUrlKey = @"embedUrl";
NSString *const TGBridgeWebPageMediaEmbedTypeKey = @"embedType";
NSString *const TGBridgeWebPageMediaEmbedSizeKey = @"embedSize";
NSString *const TGBridgeWebPageMediaDurationKey = @"duration";
NSString *const TGBridgeWebPageMediaAuthorKey = @"author";
@implementation TGBridgeWebPageMediaAttachment
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_webPageId = [aDecoder decodeInt64ForKey:TGBridgeWebPageMediaWebPageIdKey];
_url = [aDecoder decodeObjectForKey:TGBridgeWebPageMediaUrlKey];
_displayUrl = [aDecoder decodeObjectForKey:TGBridgeWebPageMediaDisplayUrlKey];
_pageType = [aDecoder decodeObjectForKey:TGBridgeWebPageMediaPageTypeKey];
_siteName = [aDecoder decodeObjectForKey:TGBridgeWebPageMediaSiteNameKey];
_title = [aDecoder decodeObjectForKey:TGBridgeWebPageMediaTitleKey];
_pageDescription = [aDecoder decodeObjectForKey:TGBridgeWebPageMediaPageDescriptionKey];
_photo = [aDecoder decodeObjectForKey:TGBridgeWebPageMediaPhotoKey];
_embedUrl = [aDecoder decodeObjectForKey:TGBridgeWebPageMediaEmbedUrlKey];
_embedSize = [aDecoder decodeCGSizeForKey:TGBridgeWebPageMediaEmbedSizeKey];
_duration = [aDecoder decodeObjectForKey:TGBridgeWebPageMediaDurationKey];
_author = [aDecoder decodeObjectForKey:TGBridgeWebPageMediaAuthorKey];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInt64:self.webPageId forKey:TGBridgeWebPageMediaWebPageIdKey];
[aCoder encodeObject:self.url forKey:TGBridgeWebPageMediaUrlKey];
[aCoder encodeObject:self.displayUrl forKey:TGBridgeWebPageMediaDisplayUrlKey];
[aCoder encodeObject:self.pageType forKey:TGBridgeWebPageMediaPageTypeKey];
[aCoder encodeObject:self.siteName forKey:TGBridgeWebPageMediaSiteNameKey];
[aCoder encodeObject:self.title forKey:TGBridgeWebPageMediaTitleKey];
[aCoder encodeObject:self.pageDescription forKey:TGBridgeWebPageMediaPageDescriptionKey];
[aCoder encodeObject:self.photo forKey:TGBridgeWebPageMediaPhotoKey];
[aCoder encodeObject:self.embedUrl forKey:TGBridgeWebPageMediaEmbedUrlKey];
[aCoder encodeCGSize:self.embedSize forKey:TGBridgeWebPageMediaEmbedSizeKey];
[aCoder encodeObject:self.duration forKey:TGBridgeWebPageMediaDurationKey];
[aCoder encodeObject:self.author forKey:TGBridgeWebPageMediaAuthorKey];
}
+ (NSInteger)mediaType
{
return TGBridgeWebPageMediaAttachmentType;
}
@end