Merge commit '7621e2f8dec938cf48181c8b10afc9b01f444e68' into beta

This commit is contained in:
Ilya Laktyushin
2025-12-06 02:17:48 +04:00
commit 8344b97e03
28070 changed files with 7995182 additions and 0 deletions
@@ -0,0 +1,250 @@
#import <LegacyDataImportImpl/TGAutoDownloadPreferences.h>
@implementation TGAutoDownloadPreferences
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self != nil)
{
_disabled = [aDecoder decodeBoolForKey:@"disabled"];
_photos = [aDecoder decodeInt32ForKey:@"photos"];
_videos = [aDecoder decodeInt32ForKey:@"videos"];
_maximumVideoSize = [aDecoder decodeInt32ForKey:@"maxVideoSize"];
_documents = [aDecoder decodeInt32ForKey:@"documents"];
_maximumDocumentSize = [aDecoder decodeInt32ForKey:@"maxDocumentSize"];
_voiceMessages = [aDecoder decodeInt32ForKey:@"voiceMessages"];
_videoMessages = [aDecoder decodeInt32ForKey:@"videoMessages"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeBool:_disabled forKey:@"disabled"];
[aCoder encodeInt32:_photos forKey:@"photos"];
[aCoder encodeInt32:_videos forKey:@"videos"];
[aCoder encodeInt32:_maximumVideoSize forKey:@"maxVideoSize"];
[aCoder encodeInt32:_documents forKey:@"documents"];
[aCoder encodeInt32:_maximumDocumentSize forKey:@"maxDocumentSize"];
[aCoder encodeInt32:_voiceMessages forKey:@"voiceMessages"];
[aCoder encodeInt32:_videoMessages forKey:@"videoMessages"];
}
+ (instancetype)defaultPreferences
{
TGAutoDownloadPreferences *preferences = [[TGAutoDownloadPreferences alloc] init];
preferences->_photos = TGAutoDownloadModeAll;
preferences->_videos = TGAutoDownloadModeNone;
preferences->_maximumVideoSize = 10;
preferences->_documents = TGAutoDownloadModeNone;
preferences->_maximumDocumentSize = 10;
preferences->_voiceMessages = TGAutoDownloadModeAll;
preferences->_videoMessages = TGAutoDownloadModeAll;
return preferences;
}
+ (instancetype)preferencesWithLegacyDownloadPrivatePhotos:(bool)privatePhotos groupPhotos:(bool)groupPhotos privateVoiceMessages:(bool)privateVoiceMessages groupVoiceMessages:(bool)groupVoiceMessages privateVideoMessages:(bool)privateVideoMessages groupVideoMessages:(bool)groupVideoMessages
{
TGAutoDownloadPreferences *preferences = [[TGAutoDownloadPreferences alloc] init];
if (privatePhotos)
preferences->_photos |= TGAutoDownloadModeAllPrivateChats;
if (groupPhotos)
preferences->_photos |= TGAutoDownloadModeAllGroups;
if (privateVoiceMessages)
preferences->_voiceMessages |= TGAutoDownloadModeAllPrivateChats;
if (groupVoiceMessages)
preferences->_voiceMessages |= TGAutoDownloadModeAllGroups;
if (privateVideoMessages)
preferences->_videoMessages |= TGAutoDownloadModeAllPrivateChats;
if (groupVideoMessages)
preferences->_videoMessages |= TGAutoDownloadModeAllGroups;
preferences->_maximumVideoSize = 10;
preferences->_maximumDocumentSize = 10;
return preferences;
}
- (instancetype)updateDisabled:(bool)disabled
{
TGAutoDownloadPreferences *preferences = [[TGAutoDownloadPreferences alloc] init];
preferences->_disabled = disabled;
preferences->_photos = _photos;
preferences->_videos = _videos;
preferences->_maximumVideoSize = _maximumVideoSize;
preferences->_documents = _documents;
preferences->_maximumDocumentSize = _maximumDocumentSize;
preferences->_voiceMessages = _voiceMessages;
preferences->_videoMessages = _videoMessages;
return preferences;
}
- (instancetype)updatePhotosMode:(TGAutoDownloadMode)mode
{
TGAutoDownloadPreferences *preferences = [[TGAutoDownloadPreferences alloc] init];
preferences->_photos = mode;
preferences->_videos = _videos;
preferences->_maximumVideoSize = _maximumVideoSize;
preferences->_documents = _documents;
preferences->_maximumDocumentSize = _maximumDocumentSize;
preferences->_voiceMessages = _voiceMessages;
preferences->_videoMessages = _videoMessages;
return preferences;
}
- (instancetype)updateVideosMode:(TGAutoDownloadMode)mode maximumSize:(int32_t)maximumSize
{
TGAutoDownloadPreferences *preferences = [[TGAutoDownloadPreferences alloc] init];
preferences->_photos = _photos;
preferences->_videos = mode;
preferences->_maximumVideoSize = maximumSize;
preferences->_documents = _documents;
preferences->_maximumDocumentSize = _maximumDocumentSize;
preferences->_voiceMessages = _voiceMessages;
preferences->_videoMessages = _videoMessages;
return preferences;
}
- (instancetype)updateDocumentsMode:(TGAutoDownloadMode)mode maximumSize:(int32_t)maximumSize
{
TGAutoDownloadPreferences *preferences = [[TGAutoDownloadPreferences alloc] init];
preferences->_photos = _photos;
preferences->_videos = _videos;
preferences->_maximumVideoSize = _maximumVideoSize;
preferences->_documents = mode;
preferences->_maximumDocumentSize = maximumSize;
preferences->_voiceMessages = _voiceMessages;
preferences->_videoMessages = _videoMessages;
return preferences;
}
- (instancetype)updateVoiceMessagesMode:(TGAutoDownloadMode)mode
{
TGAutoDownloadPreferences *preferences = [[TGAutoDownloadPreferences alloc] init];
preferences->_photos = _photos;
preferences->_videos = _videos;
preferences->_maximumVideoSize = _maximumVideoSize;
preferences->_documents = _documents;
preferences->_maximumDocumentSize = _maximumDocumentSize;
preferences->_voiceMessages = mode;
preferences->_videoMessages = _videoMessages;
return preferences;
}
- (instancetype)updateVideoMessagesMode:(TGAutoDownloadMode)mode
{
TGAutoDownloadPreferences *preferences = [[TGAutoDownloadPreferences alloc] init];
preferences->_photos = _photos;
preferences->_videos = _videos;
preferences->_maximumVideoSize = _maximumVideoSize;
preferences->_documents = _documents;
preferences->_maximumDocumentSize = _maximumDocumentSize;
preferences->_voiceMessages = _voiceMessages;
preferences->_videoMessages = mode;
return preferences;
}
+ (bool)shouldDownload:(TGAutoDownloadMode)mode inChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType
{
bool isWiFi = networkType == TGNetworkTypeWiFi;
bool isCellular = !isWiFi && networkType != TGNetworkTypeNone;
bool shouldDownload = false;
switch (chat)
{
case TGAutoDownloadChatContact:
if (isCellular)
shouldDownload = (mode & TGAutoDownloadModeCellularContacts) != 0;
else if (isWiFi)
shouldDownload = (mode & TGAutoDownloadModeWifiContacts) != 0;
break;
case TGAutoDownloadChatOtherPrivateChat:
if (isCellular)
shouldDownload = (mode & TGAutoDownloadModeCellularPrivateChats) != 0;
else if (isWiFi)
shouldDownload = (mode & TGAutoDownloadModeWifiPrivateChats) != 0;
break;
case TGAutoDownloadChatGroup:
if (isCellular)
shouldDownload = (mode & TGAutoDownloadModeCellularGroups) != 0;
else if (isWiFi)
shouldDownload = (mode & TGAutoDownloadModeWifiGroups) != 0;
break;
case TGAutoDownloadChatChannel:
if (isCellular)
shouldDownload = (mode & TGAutoDownloadModeCellularChannels) != 0;
else if (isWiFi)
shouldDownload = (mode & TGAutoDownloadModeWifiChannels) != 0;
break;
default:
break;
}
return shouldDownload;
}
- (bool)shouldDownloadPhotoInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType
{
if (self.disabled)
return false;
return [TGAutoDownloadPreferences shouldDownload:_photos inChat:chat networkType:networkType];
}
- (bool)shouldDownloadVideoInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType
{
if (self.disabled)
return false;
return [TGAutoDownloadPreferences shouldDownload:_videos inChat:chat networkType:networkType];
}
- (bool)shouldDownloadDocumentInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType
{
if (self.disabled)
return false;
return [TGAutoDownloadPreferences shouldDownload:_documents inChat:chat networkType:networkType];
}
- (bool)shouldDownloadVoiceMessageInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType
{
if (self.disabled)
return false;
return [TGAutoDownloadPreferences shouldDownload:_voiceMessages inChat:chat networkType:networkType];
}
- (bool)shouldDownloadVideoMessageInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType
{
if (self.disabled)
return false;
return [TGAutoDownloadPreferences shouldDownload:_videoMessages inChat:chat networkType:networkType];
}
- (bool)isDefaultPreferences
{
return [self isEqual:[TGAutoDownloadPreferences defaultPreferences]];
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return YES;
if (!object || ![object isKindOfClass:[self class]])
return NO;
TGAutoDownloadPreferences *preferences = (TGAutoDownloadPreferences *)object;
return preferences.photos == _photos && preferences.videos == _videos && preferences.documents == _documents && preferences.voiceMessages == _voiceMessages && preferences.videoMessages == _videoMessages && preferences.maximumVideoSize == _maximumVideoSize && preferences.maximumDocumentSize == _maximumDocumentSize && preferences.disabled == _disabled;
}
@end
@@ -0,0 +1,23 @@
#import <LegacyDataImportImpl/TGPresentationAutoNightPreferences.h>
@implementation TGPresentationAutoNightPreferences
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super init];
if (self != nil) {
_mode = [aDecoder decodeInt32ForKey:@"m"];
_brightnessThreshold = [aDecoder decodeDoubleForKey:@"b"];
_scheduleStart = [aDecoder decodeInt32ForKey:@"ss"];
_scheduleEnd = [aDecoder decodeInt32ForKey:@"se"];
_latitude = [aDecoder decodeDoubleForKey:@"lat"];
_longitude = [aDecoder decodeDoubleForKey:@"lon"];
_cachedLocationName = [aDecoder decodeObjectForKey:@"loc"];
_preferredPalette = [aDecoder decodeInt32ForKey:@"p"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
}
@end
@@ -0,0 +1,73 @@
#import <LegacyDataImportImpl/TGProxyItem.h>
static bool TGObjectCompare(id obj1, id obj2) {
if (obj1 == nil && obj2 == nil)
return true;
return [obj1 isEqual:obj2];
}
@implementation TGProxyItem
- (instancetype)initWithServer:(NSString *)server port:(int16_t)port username:(NSString *)username password:(NSString *)password secret:(NSString *)secret
{
self = [super init];
if (self != nil)
{
_server = server;
_port = port;
_username = username;
_password = password;
_secret = secret;
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
return [self initWithServer:[aDecoder decodeObjectForKey:@"server"] port:(int16_t)[aDecoder decodeInt32ForKey:@"port"] username:[aDecoder decodeObjectForKey:@"user"] password:[aDecoder decodeObjectForKey:@"pass"] secret:[aDecoder decodeObjectForKey:@"secret"]];
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_server forKey:@"server"];
[aCoder encodeInt32:_port forKey:@"port"];
[aCoder encodeObject:_username forKey:@"user"];
[aCoder encodeObject:_password forKey:@"pass"];
[aCoder encodeObject:_secret forKey:@"secret"];
}
- (bool)isMTProxy
{
return _secret.length > 0;
}
- (BOOL)isEqual:(id)object
{
if (object == self)
return true;
if (!object || ![object isKindOfClass:[self class]])
return false;
TGProxyItem *proxy = (TGProxyItem *)object;
if (![_server isEqualToString:proxy.server])
return false;
if (_port != proxy.port)
return false;
if (!TGObjectCompare(_username ?: @"", proxy.username ?: @""))
return false;
if (!TGObjectCompare(_password ?: @"", proxy.password ?: @""))
return false;
if (!TGObjectCompare(_secret ?: @"", proxy.secret ?: @""))
return false;
return true;
}
@end