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
+22
View File
@@ -0,0 +1,22 @@
objc_library(
name = "LegacyDataImportImpl",
enable_modules = True,
module_name = "LegacyDataImportImpl",
srcs = glob([
"Sources/**/*.m",
"Sources/**/*.h",
]),
hdrs = glob([
"PublicHeaders/**/*.h",
]),
includes = [
"PublicHeaders",
],
sdk_frameworks = [
"Foundation",
],
visibility = [
"//visibility:public",
],
)
@@ -0,0 +1,7 @@
#import <UIKit/UIKit.h>
#import <LegacyDataImportImpl/TGProxyItem.h>
#import <LegacyDataImportImpl/TGAutoDownloadPreferences.h>
#import <LegacyDataImportImpl/TGPresentationAutoNightPreferences.h>
@@ -0,0 +1,76 @@
#import <Foundation/Foundation.h>
typedef enum {
TGNetworkTypeUnknown,
TGNetworkTypeNone,
TGNetworkTypeGPRS,
TGNetworkTypeEdge,
TGNetworkType3G,
TGNetworkTypeLTE,
TGNetworkTypeWiFi,
} TGNetworkType;
typedef enum {
TGAutoDownloadModeNone = 0,
TGAutoDownloadModeCellularContacts = 1 << 0,
TGAutoDownloadModeWifiContacts = 1 << 1,
TGAutoDownloadModeCellularPrivateChats = 1 << 2,
TGAutoDownloadModeWifiPrivateChats = 1 << 3,
TGAutoDownloadModeCellularGroups = 1 << 4,
TGAutoDownloadModeWifiGroups = 1 << 5,
TGAutoDownloadModeCellularChannels = 1 << 6,
TGAutoDownloadModeWifiChannels = 1 << 7,
TGAutoDownloadModeAutosavePhotosAll = TGAutoDownloadModeCellularContacts | TGAutoDownloadModeCellularPrivateChats | TGAutoDownloadModeCellularGroups | TGAutoDownloadModeCellularChannels,
TGAutoDownloadModeAllPrivateChats = TGAutoDownloadModeCellularContacts | TGAutoDownloadModeWifiContacts | TGAutoDownloadModeCellularPrivateChats | TGAutoDownloadModeWifiPrivateChats,
TGAutoDownloadModeAllGroups = TGAutoDownloadModeCellularGroups | TGAutoDownloadModeWifiGroups | TGAutoDownloadModeCellularChannels | TGAutoDownloadModeWifiChannels,
TGAutoDownloadModeAll = TGAutoDownloadModeCellularContacts | TGAutoDownloadModeWifiContacts | TGAutoDownloadModeCellularPrivateChats | TGAutoDownloadModeWifiPrivateChats | TGAutoDownloadModeCellularGroups | TGAutoDownloadModeWifiGroups | TGAutoDownloadModeCellularChannels | TGAutoDownloadModeWifiChannels
} TGAutoDownloadMode;
typedef enum {
TGAutoDownloadChatContact,
TGAutoDownloadChatOtherPrivateChat,
TGAutoDownloadChatGroup,
TGAutoDownloadChatChannel
} TGAutoDownloadChat;
@interface TGAutoDownloadPreferences : NSObject <NSCoding>
@property (nonatomic, readonly) bool disabled;
@property (nonatomic, readonly) TGAutoDownloadMode photos;
@property (nonatomic, readonly) TGAutoDownloadMode videos;
@property (nonatomic, readonly) int32_t maximumVideoSize;
@property (nonatomic, readonly) TGAutoDownloadMode documents;
@property (nonatomic, readonly) int32_t maximumDocumentSize;
@property (nonatomic, readonly) TGAutoDownloadMode gifs;
@property (nonatomic, readonly) TGAutoDownloadMode voiceMessages;
@property (nonatomic, readonly) TGAutoDownloadMode videoMessages;
- (instancetype)updateDisabled:(bool)disabled;
- (instancetype)updatePhotosMode:(TGAutoDownloadMode)mode;
- (instancetype)updateVideosMode:(TGAutoDownloadMode)mode maximumSize:(int32_t)maximumSize;
- (instancetype)updateDocumentsMode:(TGAutoDownloadMode)mode maximumSize:(int32_t)maximumSize;
- (instancetype)updateGifsMode:(TGAutoDownloadMode)mode;
- (instancetype)updateVoiceMessagesMode:(TGAutoDownloadMode)mode;
- (instancetype)updateVideoMessagesMode:(TGAutoDownloadMode)mode;
+ (bool)shouldDownload:(TGAutoDownloadMode)mode inChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType;
- (bool)shouldDownloadPhotoInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType;
- (bool)shouldDownloadVideoInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType;
- (bool)shouldDownloadDocumentInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType;
- (bool)shouldDownloadGifInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType;
- (bool)shouldDownloadVoiceMessageInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType;
- (bool)shouldDownloadVideoMessageInChat:(TGAutoDownloadChat)chat networkType:(TGNetworkType)networkType;
- (bool)isDefaultPreferences;
+ (instancetype)defaultPreferences;
+ (instancetype)preferencesWithLegacyDownloadPrivatePhotos:(bool)privatePhotos groupPhotos:(bool)groupPhotos privateVoiceMessages:(bool)privateVoiceMessages groupVoiceMessages:(bool)groupVoiceMessages privateVideoMessages:(bool)privateVideoMessages groupVideoMessages:(bool)groupVideoMessages;
@end
@@ -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,31 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef enum
{
TGPresentationAutoNightModeDisabled,
TGPresentationAutoNightModeBrightness,
TGPresentationAutoNightModeScheduled,
TGPresentationAutoNightModeSunsetSunrise
} TGPresentationAutoNightMode;
@interface TGPresentationAutoNightPreferences : NSObject <NSCoding>
@property (nonatomic, readonly) TGPresentationAutoNightMode mode;
@property (nonatomic, readonly) CGFloat brightnessThreshold;
@property (nonatomic, readonly) int32_t scheduleStart;
@property (nonatomic, readonly) int32_t scheduleEnd;
@property (nonatomic, readonly) CGFloat latitude;
@property (nonatomic, readonly) CGFloat longitude;
@property (nonatomic, readonly) NSString *cachedLocationName;
@property (nonatomic, readonly) int32_t preferredPalette;
@end
NS_ASSUME_NONNULL_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,15 @@
#import <Foundation/Foundation.h>
@interface TGProxyItem : NSObject <NSCoding>
@property (nonatomic, readonly) NSString *server;
@property (nonatomic, readonly) int16_t port;
@property (nonatomic, readonly) NSString *username;
@property (nonatomic, readonly) NSString *password;
@property (nonatomic, readonly) NSString *secret;
@property (nonatomic, readonly) bool isMTProxy;
- (instancetype)initWithServer:(NSString *)server port:(int16_t)port username:(NSString *)username password:(NSString *)password secret:(NSString *)secret;
@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
@@ -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