diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index 4c40bb195f..13770abdf4 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -1343,7 +1343,6 @@ public protocol AccountContext: AnyObject { var downloadedMediaStoreManager: DownloadedMediaStoreManager { get } var peerChannelMemberCategoriesContextsManager: PeerChannelMemberCategoriesContextsManager { get } var wallpaperUploadManager: WallpaperUploadManager? { get } - var watchManager: WatchManager? { get } var inAppPurchaseManager: InAppPurchaseManager? { get } var starsContext: StarsContext? { get } diff --git a/submodules/AccountContext/Sources/WatchManager.swift b/submodules/AccountContext/Sources/WatchManager.swift deleted file mode 100644 index ce2e97c3ef..0000000000 --- a/submodules/AccountContext/Sources/WatchManager.swift +++ /dev/null @@ -1,23 +0,0 @@ -import Foundation -import SwiftSignalKit -import TelegramCore - -public struct WatchRunningTasks: Equatable { - public let running: Bool - public let version: Int32 - - public init(running: Bool, version: Int32) { - self.running = running - self.version = version - } - - public static func ==(lhs: WatchRunningTasks, rhs: WatchRunningTasks) -> Bool { - return lhs.running == rhs.running && lhs.version == rhs.version - } -} - -public protocol WatchManager: AnyObject { - var watchAppInstalled: Signal { get } - var navigateToMessageRequested: Signal { get } - var runningTasks: Signal { get } -} diff --git a/submodules/LottieCpp/BUILD b/submodules/LottieCpp/BUILD index 7569482041..8c4fd461d4 100644 --- a/submodules/LottieCpp/BUILD +++ b/submodules/LottieCpp/BUILD @@ -23,9 +23,7 @@ objc_library( "-I{}/lottiecpp/Sources".format(package_name()), ], cxxopts = [ - "-Werror", "-std=c++17", - "-I{}/lottiecpp/Sources".format(package_name()), ], hdrs = glob([ "lottiecpp/PublicHeaders/**/*.h", diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift index 92ac289279..6e70f69596 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift @@ -895,9 +895,6 @@ private func languageSearchableItems(context: AccountContext, localizations: [Lo } func settingsSearchableItems(context: AccountContext, notificationExceptionsList: Signal, archivedStickerPacks: Signal<[ArchivedStickerPackItem]?, NoError>, privacySettings: Signal, hasTwoStepAuth: Signal, twoStepAuthData: Signal, activeSessionsContext: Signal, webSessionsContext: Signal) -> Signal<[SettingsSearchableItem], NoError> { - let watchAppInstalled = (context.watchManager?.watchAppInstalled ?? .single(false)) - |> take(1) - let canAddAccount = activeAccountsAndPeers(context: context) |> take(1) |> map { accountsAndPeers -> Bool in @@ -991,8 +988,8 @@ func settingsSearchableItems(context: AccountContext, notificationExceptionsList } } - return combineLatest(watchAppInstalled, canAddAccount, localizations, notificationSettings, notificationExceptionsList, archivedStickerPacks, proxyServers, privacySettings, hasTwoStepAuth, twoStepAuthData, activeSessionsContext, activeWebSessionsContext) - |> map { watchAppInstalled, canAddAccount, localizations, notificationSettings, notificationExceptionsList, archivedStickerPacks, proxyServers, privacySettings, hasTwoStepAuth, twoStepAuthData, activeSessionsContext, activeWebSessionsContext in + return combineLatest(canAddAccount, localizations, notificationSettings, notificationExceptionsList, archivedStickerPacks, proxyServers, privacySettings, hasTwoStepAuth, twoStepAuthData, activeSessionsContext, activeWebSessionsContext) + |> map { canAddAccount, localizations, notificationSettings, notificationExceptionsList, archivedStickerPacks, proxyServers, privacySettings, hasTwoStepAuth, twoStepAuthData, activeSessionsContext, activeWebSessionsContext in let strings = context.sharedContext.currentPresentationData.with { $0 }.strings var allItems: [SettingsSearchableItem] = [] @@ -1043,13 +1040,6 @@ func settingsSearchableItems(context: AccountContext, notificationExceptionsList let storiesItems = storiesSearchableItems(context: context) allItems.append(contentsOf: storiesItems) - if watchAppInstalled { - let watch = SettingsSearchableItem(id: .watch(0), title: strings.Settings_AppleWatch, alternate: synonyms(strings.SettingsSearch_Synonyms_Watch), icon: .watch, breadcrumbs: [], present: { context, _, present in - present(.push, watchSettingsController(context: context)) - }) - allItems.append(watch) - } - if let hasTwoStepAuth = hasTwoStepAuth, hasTwoStepAuth { let passport = SettingsSearchableItem(id: .passport(0), title: strings.Settings_Passport, alternate: synonyms(strings.SettingsSearch_Synonyms_Passport), icon: .passport, breadcrumbs: [], present: { context, _, present in present(.modal, SecureIdAuthController(context: context, mode: .list)) diff --git a/submodules/TelegramUI/BUILD b/submodules/TelegramUI/BUILD index 3d7252bf1c..65920d174a 100644 --- a/submodules/TelegramUI/BUILD +++ b/submodules/TelegramUI/BUILD @@ -71,7 +71,6 @@ swift_library( "//submodules/TelegramVoip:TelegramVoip", "//submodules/DeviceAccess:DeviceAccess", "//submodules/Utils/DeviceModel", - "//submodules/WatchCommon/Host:WatchCommon", "//submodules/BuildConfig:BuildConfig", "//submodules/BuildConfigExtra:BuildConfigExtra", "//submodules/rlottie:RLottieBinding", @@ -193,8 +192,6 @@ swift_library( "//submodules/RaiseToListen:RaiseToListen", "//submodules/OpusBinding:OpusBinding", "//third-party/opus:opus", - "//submodules/WatchBridgeAudio:WatchBridgeAudio", - "//submodules/WatchBridge:WatchBridge", "//submodules/ShareItems:ShareItems", "//submodules/ShareItems/Impl:ShareItemsImpl", "//submodules/SettingsUI:SettingsUI", diff --git a/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoData.swift b/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoData.swift index 60a59f702f..a09cd2413b 100644 --- a/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoData.swift +++ b/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoData.swift @@ -864,7 +864,6 @@ func peerInfoScreenSettingsData(context: AccountContext, peerId: EnginePeer.Id, combineLatest(notificationExceptions, notificationsAuthorizationStatus.get(), notificationsWarningSuppressed.get()), combineLatest(context.account.viewTracker.featuredStickerPacks(), archivedStickerPacks), hasPassport, - (context.watchManager?.watchAppInstalled ?? .single(false)), context.account.postbox.preferencesView(keys: [PreferencesKeys.appConfiguration]), context.engine.notices.getServerProvidedSuggestions(), context.engine.data.get( @@ -882,7 +881,7 @@ func peerInfoScreenSettingsData(context: AccountContext, peerId: EnginePeer.Id, peerInfoPersonalOrLinkedChannel(context: context, peerId: peerId, isSettings: true), starsState ) - |> map { peerView, accountsAndPeers, accountSessions, privacySettings, sharedPreferences, notifications, stickerPacks, hasPassport, hasWatchApp, accountPreferences, suggestions, limits, hasPassword, isPowerSavingEnabled, hasStories, bots, personalChannel, starsState -> PeerInfoScreenData in + |> map { peerView, accountsAndPeers, accountSessions, privacySettings, sharedPreferences, notifications, stickerPacks, hasPassport, accountPreferences, suggestions, limits, hasPassword, isPowerSavingEnabled, hasStories, bots, personalChannel, starsState -> PeerInfoScreenData in let (notificationExceptions, notificationsAuthorizationStatus, notificationsWarningSuppressed) = notifications let (featuredStickerPacks, archivedStickerPacks) = stickerPacks @@ -925,7 +924,7 @@ func peerInfoScreenSettingsData(context: AccountContext, peerId: EnginePeer.Id, userLimits: peer?.isPremium == true ? limits.1 : limits.0, bots: bots, hasPassport: hasPassport, - hasWatchApp: hasWatchApp, + hasWatchApp: false, enableQRLogin: enableQRLogin ) diff --git a/submodules/TelegramUI/Sources/AccountContext.swift b/submodules/TelegramUI/Sources/AccountContext.swift index b5fc100555..a4dea6fcd0 100644 --- a/submodules/TelegramUI/Sources/AccountContext.swift +++ b/submodules/TelegramUI/Sources/AccountContext.swift @@ -155,8 +155,6 @@ public final class AccountContextImpl: AccountContext { return self._countriesConfiguration.get() } - public var watchManager: WatchManager? - private var storedPassword: (String, CFAbsoluteTime, SwiftSignalKit.Timer)? private var limitsConfigurationDisposable: Disposable? private var contentSettingsDisposable: Disposable? diff --git a/submodules/TelegramUI/Sources/AppDelegate.swift b/submodules/TelegramUI/Sources/AppDelegate.swift index b9f65b0406..fa814c6142 100644 --- a/submodules/TelegramUI/Sources/AppDelegate.swift +++ b/submodules/TelegramUI/Sources/AppDelegate.swift @@ -19,7 +19,6 @@ import OverlayStatusController import UndoUI import LegacyUI import PassportUI -import WatchBridge import SettingsUI import AppBundle import UrlHandling @@ -1052,26 +1051,7 @@ private func extractAccountManagerState(records: AccountRecordsView mapToSignal { context -> Signal in - if let context = context, let watchManager = context.context.watchManager { - let accountId = context.context.account.id - let runningTasks: Signal = .single(nil) - |> then(watchManager.runningTasks) - return runningTasks - |> distinctUntilChanged - |> map { value -> AccountRecordId? in - if let value = value, value.running { - return accountId - } else { - return nil - } - } - |> distinctUntilChanged - } else { - return .single(nil) - } - }*/ + let wakeupManager = SharedWakeupManager(beginBackgroundTask: { name, expiration in let id = application.beginBackgroundTask(withName: name, expirationHandler: expiration) Logger.shared.log("App \(self.episodeId)", "Begin background task \(name): \(id)") @@ -1101,8 +1081,6 @@ private func extractAccountManagerState(records: AccountRecordsView() self.context.set(self.sharedContextPromise.get() |> deliverOnMainQueue @@ -1141,7 +1119,7 @@ private func extractAccountManagerState(records: AccountRecordsView deliverOnMainQueue |> map { accountAndSettings -> AuthorizedApplicationContext? in return accountAndSettings.flatMap { context, callListSettings in - return AuthorizedApplicationContext(sharedApplicationContext: sharedApplicationContext, mainWindow: self.mainWindow, watchManagerArguments: .single(nil), context: context as! AccountContextImpl, accountManager: sharedApplicationContext.sharedContext.accountManager, showCallsTab: callListSettings.showTab, reinitializedNotificationSettings: { + return AuthorizedApplicationContext(sharedApplicationContext: sharedApplicationContext, mainWindow: self.mainWindow, context: context as! AccountContextImpl, accountManager: sharedApplicationContext.sharedContext.accountManager, showCallsTab: callListSettings.showTab, reinitializedNotificationSettings: { let _ = (self.context.get() |> take(1) |> deliverOnMainQueue).start(next: { context in @@ -1385,20 +1363,6 @@ private func extractAccountManagerState(records: AccountRecordsView flatMap { WatchCommunicationManagerContext(context: $0.context) }, allowBackgroundTimeExtension: { timeout in - let _ = (self.sharedContextPromise.get() - |> take(1)).start(next: { sharedContext in - sharedContext.wakeupManager.allowBackgroundTimeExtension(timeout: timeout) - }) - })) - let _ = self.watchCommunicationManagerPromise.get().start(next: { manager in - if let manager = manager { - watchManagerArgumentsPromise.set(.single(manager.arguments)) - } else { - watchManagerArgumentsPromise.set(.single(nil)) - } - })*/ - self.resetBadge() if #available(iOS 9.1, *) { diff --git a/submodules/TelegramUI/Sources/ApplicationContext.swift b/submodules/TelegramUI/Sources/ApplicationContext.swift index 841b38138f..aec4ca0639 100644 --- a/submodules/TelegramUI/Sources/ApplicationContext.swift +++ b/submodules/TelegramUI/Sources/ApplicationContext.swift @@ -19,7 +19,6 @@ import TelegramPermissionsUI import PasscodeUI import ImageBlur import FastBlur -import WatchBridge import SettingsUI import AppLock import AccountUtils @@ -155,7 +154,7 @@ final class AuthorizedApplicationContext { private var showCallsTabDisposable: Disposable? private var enablePostboxTransactionsDiposable: Disposable? - init(sharedApplicationContext: SharedApplicationContext, mainWindow: Window1, watchManagerArguments: Signal, context: AccountContextImpl, accountManager: AccountManager, showCallsTab: Bool, reinitializedNotificationSettings: @escaping () -> Void) { + init(sharedApplicationContext: SharedApplicationContext, mainWindow: Window1, context: AccountContextImpl, accountManager: AccountManager, showCallsTab: Bool, reinitializedNotificationSettings: @escaping () -> Void) { self.sharedApplicationContext = sharedApplicationContext setupLegacyComponents(context: context) @@ -798,54 +797,6 @@ final class AuthorizedApplicationContext { } }) - let _ = (watchManagerArguments - |> deliverOnMainQueue).start(next: { [weak self] arguments in - guard let strongSelf = self else { - return - } - - let watchManager = WatchManagerImpl(arguments: arguments) - strongSelf.context.watchManager = watchManager - - strongSelf.watchNavigateToMessageDisposable.set((strongSelf.context.sharedContext.applicationBindings.applicationInForeground |> mapToSignal({ applicationInForeground -> Signal<(Bool, MessageId), NoError> in - return watchManager.navigateToMessageRequested - |> map { messageId in - return (applicationInForeground, messageId) - } - |> deliverOnMainQueue - })).start(next: { [weak self] applicationInForeground, messageId in - if let strongSelf = self { - if applicationInForeground { - var chatIsVisible = false - if let controller = strongSelf.rootController.viewControllers.last as? ChatControllerImpl, case .peer(messageId.peerId) = controller.chatLocation { - chatIsVisible = true - } - - let navigateToMessage = { - let _ = (strongSelf.context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: messageId.peerId)) - |> deliverOnMainQueue).start(next: { peer in - guard let peer = peer else { - return - } - - strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: strongSelf.rootController, context: strongSelf.context, chatLocation: .peer(peer), subject: .message(id: .id(messageId), highlight: ChatControllerSubject.MessageHighlight(quote: nil), timecode: nil, setupReply: false))) - }) - } - - if chatIsVisible { - navigateToMessage() - } else { - let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } - let controller = textAlertController(context: strongSelf.context, title: presentationData.strings.WatchRemote_AlertTitle, text: presentationData.strings.WatchRemote_AlertText, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.WatchRemote_AlertOpen, action:navigateToMessage)]) - (strongSelf.rootController.viewControllers.last as? ViewController)?.present(controller, in: .window(.root)) - } - } else { - //strongSelf.notificationManager.presentWatchContinuityNotification(context: strongSelf.context, messageId: messageId) - } - } - })) - }) - self.rootController.setForceInCallStatusBar((self.context.sharedContext as! SharedAccountContextImpl).currentCallStatusBarNode) if let groupCallController = self.context.sharedContext.currentGroupCallController as? VoiceChatController { if let overlayController = groupCallController.currentOverlayController { diff --git a/submodules/TelegramUI/Sources/WatchManager.swift b/submodules/TelegramUI/Sources/WatchManager.swift deleted file mode 100644 index daebf13070..0000000000 --- a/submodules/TelegramUI/Sources/WatchManager.swift +++ /dev/null @@ -1,25 +0,0 @@ -import Foundation -import SwiftSignalKit -import TelegramCore -import AccountContext -import WatchBridge - -public final class WatchManagerImpl: WatchManager { - private let arguments: WatchManagerArguments? - - public init(arguments: WatchManagerArguments?) { - self.arguments = arguments - } - - public var watchAppInstalled: Signal { - return self.arguments?.appInstalled ?? .single(false) - } - - public var navigateToMessageRequested: Signal { - return self.arguments?.navigateToMessageRequested ?? .never() - } - - public var runningTasks: Signal { - return self.arguments?.runningTasks ?? .single(nil) - } -} diff --git a/submodules/WatchBridge/BUILD b/submodules/WatchBridge/BUILD deleted file mode 100644 index 5766afcb8f..0000000000 --- a/submodules/WatchBridge/BUILD +++ /dev/null @@ -1,33 +0,0 @@ -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") - -swift_library( - name = "WatchBridge", - module_name = "WatchBridge", - srcs = glob([ - "Sources/**/*.swift", - ]), - copts = [ - "-warnings-as-errors", - ], - deps = [ - "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit", - "//submodules/SSignalKit/SSignalKit:SSignalKit", - "//submodules/Postbox:Postbox", - "//submodules/TelegramCore:TelegramCore", - "//submodules/WatchCommon/Host:WatchCommon", - "//submodules/WatchBridgeAudio:WatchBridgeAudio", - "//submodules/TelegramPresentationData:TelegramPresentationData", - "//submodules/TelegramUIPreferences:TelegramUIPreferences", - "//submodules/AccountContext:AccountContext", - "//submodules/AvatarNode:AvatarNode", - "//submodules/StickerResources:StickerResources", - "//submodules/PhotoResources:PhotoResources", - "//submodules/LegacyComponents:LegacyComponents", - "//submodules/LegacyUI:LegacyUI", - "//submodules/PhoneNumberFormat:PhoneNumberFormat", - "//submodules/WatchBridge/Impl:WatchBridgeImpl", - ], - visibility = [ - "//visibility:public", - ], -) diff --git a/submodules/WatchBridge/Impl/BUILD b/submodules/WatchBridge/Impl/BUILD deleted file mode 100644 index 764f26875a..0000000000 --- a/submodules/WatchBridge/Impl/BUILD +++ /dev/null @@ -1,27 +0,0 @@ - -objc_library( - name = "WatchBridgeImpl", - enable_modules = True, - module_name = "WatchBridgeImpl", - srcs = glob([ - "Sources/**/*.m", - "Sources/**/*.h", - ], allow_empty=True), - hdrs = glob([ - "PublicHeaders/**/*.h", - ]), - includes = [ - "PublicHeaders", - ], - deps = [ - "//submodules/LegacyComponents:LegacyComponents", - "//submodules/WatchCommon/Host:WatchCommon", - ], - sdk_frameworks = [ - "Foundation", - "WatchConnectivity", - ], - visibility = [ - "//visibility:public", - ], -) diff --git a/submodules/WatchBridge/Impl/PublicHeaders/WatchBridgeImpl/TGBridgeServer.h b/submodules/WatchBridge/Impl/PublicHeaders/WatchBridgeImpl/TGBridgeServer.h deleted file mode 100644 index d28a8b0320..0000000000 --- a/submodules/WatchBridge/Impl/PublicHeaders/WatchBridgeImpl/TGBridgeServer.h +++ /dev/null @@ -1,29 +0,0 @@ -#import -#import - -@class TGBridgeSubscription; - -@interface TGBridgeServer : NSObject - -@property (nonatomic, readonly) NSURL * _Nullable temporaryFilesURL; - -@property (nonatomic, readonly) bool isRunning; - -- (instancetype _Nonnull)initWithHandler:(SSignal * _Nullable (^ _Nonnull)(TGBridgeSubscription * _Nullable))handler fileHandler:(void (^ _Nonnull)(NSString * _Nullable, NSDictionary * _Nullable))fileHandler dispatchOnQueue:(void (^ _Nonnull)(void (^ _Nonnull)(void)))dispatchOnQueue logFunction:(void (^ _Nonnull)(NSString * _Nullable))logFunction allowBackgroundTimeExtension:(void (^ _Nonnull)())allowBackgroundTimeExtension; -- (void)startRunning; - -- (SSignal * _Nonnull)watchAppInstalledSignal; -- (SSignal * _Nonnull)runningRequestsSignal; - -- (void)setAuthorized:(bool)authorized userId:(int64_t)userId; -- (void)setMicAccessAllowed:(bool)allowed; -- (void)setStartupData:(NSDictionary * _Nullable)data; -- (void)pushContext; - -- (void)sendFileWithURL:(NSURL * _Nonnull)url metadata:(NSDictionary * _Nullable)metadata asMessageData:(bool)asMessageData; -- (void)sendFileWithData:(NSData * _Nonnull)data metadata:(NSDictionary * _Nullable)metadata errorHandler:(void (^ _Nullable)(void))errorHandler; - -- (NSInteger)wakeupNetwork; -- (void)suspendNetworkIfReady:(NSInteger)token; - -@end diff --git a/submodules/WatchBridge/Impl/PublicHeaders/WatchBridgeImpl/WatchBridgeImpl.h b/submodules/WatchBridge/Impl/PublicHeaders/WatchBridgeImpl/WatchBridgeImpl.h deleted file mode 100644 index 8ed2f162d1..0000000000 --- a/submodules/WatchBridge/Impl/PublicHeaders/WatchBridgeImpl/WatchBridgeImpl.h +++ /dev/null @@ -1,3 +0,0 @@ -#import - -#import diff --git a/submodules/WatchBridge/Impl/Sources/TGBridgeServer.m b/submodules/WatchBridge/Impl/Sources/TGBridgeServer.m deleted file mode 100644 index 5664ac12af..0000000000 --- a/submodules/WatchBridge/Impl/Sources/TGBridgeServer.m +++ /dev/null @@ -1,770 +0,0 @@ -#import - -#import -#import -#import -#import - -@interface TGBridgeSignalManager : NSObject - -- (bool)startSignalForKey:(NSString *)key producer:(SSignal *(^)())producer; -- (void)haltSignalForKey:(NSString *)key; -- (void)haltAllSignals; - -@end - -@interface TGBridgeServer () -{ - SSignal *(^_handler)(TGBridgeSubscription *); - void (^_fileHandler)(NSString *, NSDictionary *); - void (^_logFunction)(NSString *); - void (^_dispatch)(void (^)(void)); - - bool _pendingStart; - - bool _processingNotification; - - int32_t _sessionId; - volatile int32_t _tasksVersion; - - TGBridgeContext *_activeContext; - - TGBridgeSignalManager *_signalManager; - - os_unfair_lock _incomingQueueLock; - NSMutableArray *_incomingMessageQueue; - - bool _requestSubscriptionList; - NSArray *_initialSubscriptionList; - - os_unfair_lock _outgoingQueueLock; - NSMutableArray *_outgoingMessageQueue; - - os_unfair_lock _replyHandlerMapLock; - NSMutableDictionary *_replyHandlerMap; - - SPipe *_appInstalled; - - NSMutableDictionary *_runningTasks; - SVariable *_hasRunningTasks; - - void (^_allowBackgroundTimeExtension)(); -} - -@property (nonatomic, readonly) WCSession *session; - -@end - -@implementation TGBridgeServer - -- (instancetype)initWithHandler:(SSignal *(^)(TGBridgeSubscription *))handler fileHandler:(void (^)(NSString *, NSDictionary *))fileHandler dispatchOnQueue:(void (^)(void (^)(void)))dispatchOnQueue logFunction:(void (^)(NSString *))logFunction allowBackgroundTimeExtension:(void (^)())allowBackgroundTimeExtension -{ - self = [super init]; - if (self != nil) - { - _handler = [handler copy]; - _fileHandler = [fileHandler copy]; - _dispatch = [dispatchOnQueue copy]; - _logFunction = [logFunction copy]; - _allowBackgroundTimeExtension = [allowBackgroundTimeExtension copy]; - - _runningTasks = [[NSMutableDictionary alloc] init]; - _hasRunningTasks = [[SVariable alloc] init]; - [_hasRunningTasks set:[SSignal single:@false]]; - - _signalManager = [[TGBridgeSignalManager alloc] init]; - _incomingMessageQueue = [[NSMutableArray alloc] init]; - - self.session.delegate = self; - [self.session activateSession]; - - _replyHandlerMap = [[NSMutableDictionary alloc] init]; - - _appInstalled = [[SPipe alloc] init]; - - _activeContext = [[TGBridgeContext alloc] initWithDictionary:[self.session applicationContext]]; - } - return self; -} - -- (void)log:(NSString *)message -{ - _logFunction(message); -} - -- (void)dispatch:(void (^)(void))action -{ - _dispatch(action); -} - -- (void)startRunning -{ - if (self.isRunning) - return; - - os_unfair_lock_lock(&_incomingQueueLock); - _isRunning = true; - - for (id message in _incomingMessageQueue) - [self handleMessage:message replyHandler:nil finishTask:nil completion:nil]; - - [_incomingMessageQueue removeAllObjects]; - os_unfair_lock_unlock(&_incomingQueueLock); - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self dispatch:^{ - _appInstalled.sink(@(self.session.isWatchAppInstalled)); - }]; - }); -} - -- (NSURL *)temporaryFilesURL -{ - return self.session.watchDirectoryURL; -} - -- (SSignal *)watchAppInstalledSignal -{ - return [[SSignal single:@(self.session.watchAppInstalled)] then:_appInstalled.signalProducer()]; -} - -- (SSignal *)runningRequestsSignal -{ - return _hasRunningTasks.signal; -} - -#pragma mark - - -- (void)setAuthorized:(bool)authorized userId:(int64_t)userId -{ - _activeContext = [_activeContext updatedWithAuthorized:authorized peerId:userId]; -} - -- (void)setMicAccessAllowed:(bool)allowed -{ - _activeContext = [_activeContext updatedWithMicAccessAllowed:allowed]; -} - -- (void)setStartupData:(NSDictionary *)data -{ - _activeContext = [_activeContext updatedWithPreheatData:data]; -} - -- (void)pushContext -{ - NSError *error; - [self.session updateApplicationContext:[_activeContext dictionary] error:&error]; - - //if (error != nil) - //TGLog(@"[BridgeServer][ERROR] Failed to push active application context: %@", error.localizedDescription); -} - -#pragma mark - - -- (void)handleMessageData:(NSData *)messageData task:(id)task replyHandler:(void (^)(NSData *))replyHandler completion:(void (^)(void))completion -{ - if (_allowBackgroundTimeExtension) { - _allowBackgroundTimeExtension(); - } - - __block id runningTask = task; - void (^finishTask)(NSTimeInterval) = ^(NSTimeInterval delay) - { - if (runningTask == nil) - return; - - void (^block)(void) = ^ - { - [self dispatch:^{ - [runningTask dispose]; - //TGLog(@"[BridgeServer]: ended taskid: %d", runningTask); - runningTask = nil; - }]; - }; - - if (delay > DBL_EPSILON) - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((delay) * NSEC_PER_SEC)), dispatch_get_main_queue(), block); - else - block(); - }; - - id message = [NSKeyedUnarchiver unarchiveObjectWithData:messageData]; - os_unfair_lock_lock(&_incomingQueueLock); - if (!self.isRunning) - { - [_incomingMessageQueue addObject:message]; - - if (replyHandler != nil) - replyHandler([NSData data]); - - finishTask(4.0); - - os_unfair_lock_unlock(&_incomingQueueLock); - return; - } - os_unfair_lock_unlock(&_incomingQueueLock); - - [self handleMessage:message replyHandler:replyHandler finishTask:finishTask completion:completion]; -} - -- (void)handleMessage:(id)message replyHandler:(void (^)(NSData *))replyHandler finishTask:(void (^)(NSTimeInterval))finishTask completion:(void (^)(void))completion -{ - if ([message isKindOfClass:[TGBridgeSubscription class]]) - { - TGBridgeSubscription *subcription = (TGBridgeSubscription *)message; - [self _createSubscription:subcription replyHandler:replyHandler finishTask:finishTask completion:completion]; - - //TGLog(@"[BridgeServer] Create subscription: %@", subcription); - } - else if ([message isKindOfClass:[TGBridgeDisposal class]]) - { - TGBridgeDisposal *disposal = (TGBridgeDisposal *)message; - [_signalManager haltSignalForKey:[NSString stringWithFormat:@"%lld", disposal.identifier]]; - - if (replyHandler != nil) - replyHandler([NSData data]); - - if (completion != nil) - completion(); - - //TGLog(@"[BridgeServer] Dispose subscription %lld", disposal.identifier); - - if (finishTask != nil) - finishTask(0); - } - else if ([message isKindOfClass:[TGBridgeSubscriptionList class]]) - { - TGBridgeSubscriptionList *list = (TGBridgeSubscriptionList *)message; - for (TGBridgeSubscription *subscription in list.subscriptions) - [self _createSubscription:subscription replyHandler:nil finishTask:nil completion:nil]; - - //TGLog(@"[BridgeServer] Received subscription list, applying"); - - if (replyHandler != nil) - replyHandler([NSData data]); - - if (finishTask != nil) - finishTask(4.0); - - if (completion != nil) - completion(); - } - else if ([message isKindOfClass:[TGBridgePing class]]) - { - TGBridgePing *ping = (TGBridgePing *)message; - if (_sessionId != ping.sessionId) - { - //TGLog(@"[BridgeServer] Session id mismatch"); - - if (_sessionId != 0) - { - //TGLog(@"[BridgeServer] Halt all active subscriptions"); - [_signalManager haltAllSignals]; - - os_unfair_lock_lock(&_outgoingQueueLock); - [_outgoingMessageQueue removeAllObjects]; - os_unfair_lock_unlock(&_outgoingQueueLock); - } - - _sessionId = ping.sessionId; - - if (self.session.isReachable) - [self _requestSubscriptionList]; - else - _requestSubscriptionList = true; - } - else - { - if (_requestSubscriptionList) - { - _requestSubscriptionList = false; - [self _requestSubscriptionList]; - } - - [self _sendQueuedResponses]; - - if (replyHandler != nil) - replyHandler([NSData data]); - } - - if (completion != nil) - completion(); - - if (finishTask != nil) - finishTask(4.0); - } - else - { - if (completion != nil) - completion(); - if (finishTask != nil) - finishTask(1.0); - } -} - -- (void)_createSubscription:(TGBridgeSubscription *)subscription replyHandler:(void (^)(NSData *))replyHandler finishTask:(void (^)(NSTimeInterval))finishTask completion:(void (^)(void))completion -{ - SSignal *subscriptionHandler = _handler(subscription); - if (replyHandler != nil) - { - os_unfair_lock_lock(&_replyHandlerMapLock); - _replyHandlerMap[@(subscription.identifier)] = replyHandler; - os_unfair_lock_unlock(&_replyHandlerMapLock); - } - - if (subscriptionHandler != nil) - { - [_signalManager startSignalForKey:[NSString stringWithFormat:@"%lld", subscription.identifier] producer:^SSignal * - { - STimer *timer = [[STimer alloc] initWithTimeout:2.0 repeat:false completion:^(__unused STimer *timer) - { - os_unfair_lock_lock(&_replyHandlerMapLock); - void (^reply)(NSData *) = _replyHandlerMap[@(subscription.identifier)]; - if (reply == nil) - { - os_unfair_lock_unlock(&_replyHandlerMapLock); - - if (finishTask != nil) - finishTask(2.0); - return; - } - - reply([NSData data]); - [_replyHandlerMap removeObjectForKey:@(subscription.identifier)]; - os_unfair_lock_unlock(&_replyHandlerMapLock); - - if (finishTask != nil) - finishTask(4.0); - - //TGLog(@"[BridgeServer]: subscription 0x%x hit 2.0s timeout, releasing reply handler", subscription.identifier); - } queue:[SQueue mainQueue]]; - [timer start]; - - return [[SSignal alloc] initWithGenerator:^id(__unused SSubscriber *subscriber) - { - return [subscriptionHandler startWithNext:^(id next) - { - [timer invalidate]; - [self _responseToSubscription:subscription message:next type:TGBridgeResponseTypeNext completion:completion]; - - if (finishTask != nil) - finishTask(4.0); - } error:^(id error) - { - [timer invalidate]; - [self _responseToSubscription:subscription message:error type:TGBridgeResponseTypeFailed completion:completion]; - - if (finishTask != nil) - finishTask(4.0); - } completed:^ - { - [timer invalidate]; - [self _responseToSubscription:subscription message:nil type:TGBridgeResponseTypeCompleted completion:completion]; - - if (finishTask != nil) - finishTask(4.0); - }]; - }]; - }]; - } - else - { - os_unfair_lock_lock(&_replyHandlerMapLock); - void (^reply)(NSData *) = _replyHandlerMap[@(subscription.identifier)]; - if (reply == nil) - { - os_unfair_lock_unlock(&_replyHandlerMapLock); - - if (finishTask != nil) - finishTask(2.0); - return; - } - - reply([NSData data]); - [_replyHandlerMap removeObjectForKey:@(subscription.identifier)]; - os_unfair_lock_unlock(&_replyHandlerMapLock); - - if (finishTask != nil) - finishTask(2.0); - } -} - -- (void)_responseToSubscription:(TGBridgeSubscription *)subscription message:(id)message type:(TGBridgeResponseType)type completion:(void (^)(void))completion -{ - TGBridgeResponse *response = nil; - switch (type) - { - case TGBridgeResponseTypeNext: - response = [TGBridgeResponse single:message forSubscription:subscription]; - break; - - case TGBridgeResponseTypeFailed: - response = [TGBridgeResponse fail:message forSubscription:subscription]; - break; - - case TGBridgeResponseTypeCompleted: - response = [TGBridgeResponse completeForSubscription:subscription]; - break; - - default: - break; - } - - os_unfair_lock_lock(&_replyHandlerMapLock); - void (^reply)(NSData *) = _replyHandlerMap[@(subscription.identifier)]; - if (reply != nil) - [_replyHandlerMap removeObjectForKey:@(subscription.identifier)]; - os_unfair_lock_unlock(&_replyHandlerMapLock); - - if (_processingNotification) - { - [self _enqueueResponse:response forSubscription:subscription]; - - if (completion != nil) - completion(); - - return; - } - - NSData *messageData = [NSKeyedArchiver archivedDataWithRootObject:response]; - if (reply != nil && messageData.length < 64000) - { - reply(messageData); - - if (completion != nil) - completion(); - } - else - { - if (reply != nil) - reply([NSData data]); - - if (self.session.isReachable) - { - [self.session sendMessageData:messageData replyHandler:nil errorHandler:^(NSError *error) - { - //if (error != nil) - // TGLog(@"[BridgeServer]: send response for subscription %lld failed with error %@", subscription.identifier, error); - }]; - } - else - { - //TGLog(@"[BridgeServer]: client out of reach, queueing response for subscription %lld", subscription.identifier); - [self _enqueueResponse:response forSubscription:subscription]; - } - - if (completion != nil) - completion(); - } -} - -- (void)_enqueueResponse:(TGBridgeResponse *)response forSubscription:(TGBridgeSubscription *)subscription -{ - os_unfair_lock_lock(&_outgoingQueueLock); - NSMutableArray *updatedResponses = (_outgoingMessageQueue != nil) ? [_outgoingMessageQueue mutableCopy] : [[NSMutableArray alloc] init]; - - if (subscription.dropPreviouslyQueued) - { - NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc] init]; - - [updatedResponses enumerateObjectsUsingBlock:^(TGBridgeResponse *queuedResponse, NSUInteger index, __unused BOOL *stop) - { - if (queuedResponse.subscriptionIdentifier == subscription.identifier) - [indexSet addIndex:index]; - }]; - - [updatedResponses removeObjectsAtIndexes:indexSet]; - } - - [updatedResponses addObject:response]; - - _outgoingMessageQueue = updatedResponses; - os_unfair_lock_unlock(&_outgoingQueueLock); -} - -- (void)_sendQueuedResponses -{ - if (_processingNotification) - return; - - os_unfair_lock_lock(&_outgoingQueueLock); - - if (_outgoingMessageQueue.count > 0) - { - //TGLog(@"[BridgeServer] Sending queued responses"); - - for (TGBridgeResponse *response in _outgoingMessageQueue) - { - NSData *messageData = [NSKeyedArchiver archivedDataWithRootObject:response]; - [self.session sendMessageData:messageData replyHandler:nil errorHandler:nil]; - } - - [_outgoingMessageQueue removeAllObjects]; - } - os_unfair_lock_unlock(&_outgoingQueueLock); -} - -- (void)_requestSubscriptionList -{ - TGBridgeSubscriptionListRequest *request = [[TGBridgeSubscriptionListRequest alloc] initWithSessionId:_sessionId]; - NSData *messageData = [NSKeyedArchiver archivedDataWithRootObject:request]; - [self.session sendMessageData:messageData replyHandler:nil errorHandler:nil]; -} - -- (void)sendFileWithURL:(NSURL *)url metadata:(NSDictionary *)metadata asMessageData:(bool)asMessageData -{ - //TGLog(@"[BridgeServer] Sent file with metadata %@", metadata); - if (asMessageData && self.session.isReachable) { - NSData *data = [NSData dataWithContentsOfURL:url]; - [self sendFileWithData:data metadata:metadata errorHandler:^{ - [self.session transferFile:url metadata:metadata]; - }]; - } else { - [self.session transferFile:url metadata:metadata]; - } -} - -- (void)sendFileWithData:(NSData *)data metadata:(NSDictionary *)metadata errorHandler:(void (^)(void))errorHandler -{ - TGBridgeFile *file = [[TGBridgeFile alloc] initWithData:data metadata:metadata]; - NSData *messageData = [NSKeyedArchiver archivedDataWithRootObject:file]; - [self.session sendMessageData:messageData replyHandler:nil errorHandler:^(NSError *error) { - if (errorHandler != nil) - errorHandler(); - }]; -} - -#pragma mark - Tasks - -- (id)beginTask -{ - int64_t randomId = 0; - arc4random_buf(&randomId, 8); - NSNumber *taskId = @(randomId); - - _runningTasks[taskId] = @true; - [_hasRunningTasks set:[SSignal single:@{@"version": @(_tasksVersion++), @"running": @true}]]; - - SBlockDisposable *taskDisposable = [[SBlockDisposable alloc] initWithBlock:^{ - [_runningTasks removeObjectForKey:taskId]; - [_hasRunningTasks set:[SSignal single:@{@"version": @(_tasksVersion++), @"running": @(_runningTasks.count > 0)}]]; - }]; - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((4.0) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self dispatch:^{ - [taskDisposable dispose]; - }]; - }); - - return taskDisposable; -} - -#pragma mark - Session Delegate - -- (void)handleReceivedData:(NSData *)messageData replyHandler:(void (^)(NSData *))replyHandler -{ - if (messageData.length == 0) - { - if (replyHandler != nil) - replyHandler([NSData data]); - return; - } - -// __block UIBackgroundTaskIdentifier backgroundTask; -// backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^ -// { -// if (replyHandler != nil) -// replyHandler([NSData data]); -// [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; -// }]; -// - - [self handleMessageData:messageData task:[self beginTask] replyHandler:replyHandler completion:^{}]; -} - -- (void)session:(WCSession *)__unused session didReceiveMessageData:(NSData *)messageData -{ - [self dispatch:^{ - [self handleReceivedData:messageData replyHandler:nil]; - }]; -} - -- (void)session:(WCSession *)__unused session didReceiveMessageData:(NSData *)messageData replyHandler:(void (^)(NSData *))replyHandler -{ - [self dispatch:^{ - [self handleReceivedData:messageData replyHandler:replyHandler]; - }]; -} - -- (void)session:(WCSession *)__unused session didReceiveFile:(WCSessionFile *)file -{ - NSDictionary *metadata = file.metadata; - if (metadata == nil || ![metadata[TGBridgeIncomingFileTypeKey] isEqualToString:TGBridgeIncomingFileTypeAudio]) - return; - - NSError *error; - NSURL *tempURL = [NSURL URLWithString:file.fileURL.lastPathComponent relativeToURL:self.temporaryFilesURL]; - [[NSFileManager defaultManager] createDirectoryAtPath:self.temporaryFilesURL.path withIntermediateDirectories:true attributes:nil error:&error]; - [[NSFileManager defaultManager] moveItemAtURL:file.fileURL toURL:tempURL error:&error]; - - [self dispatch:^{ - _fileHandler(tempURL.path, file.metadata); - }]; -} - -- (void)session:(WCSession *)__unused session didFinishFileTransfer:(WCSessionFileTransfer *)__unused fileTransfer error:(NSError *)__unused error -{ - -} - -- (void)session:(nonnull WCSession *)session activationDidCompleteWithState:(WCSessionActivationState)activationState error:(nullable NSError *)error { - -} - - -- (void)sessionDidBecomeInactive:(nonnull WCSession *)session { - -} - - -- (void)sessionDidDeactivate:(nonnull WCSession *)session { - -} - -- (void)sessionWatchStateDidChange:(WCSession *)session -{ - [self dispatch:^{ - if (session.isWatchAppInstalled) - [self pushContext]; - - _appInstalled.sink(@(session.isWatchAppInstalled)); - }]; -} - -- (void)sessionReachabilityDidChange:(WCSession *)session -{ - NSLog(@"[TGBridgeServer] Reachability changed: %d", session.isReachable); -} - -#pragma mark - - -- (NSInteger)wakeupNetwork -{ - return 0; -} - -- (void)suspendNetworkIfReady:(NSInteger)token -{ -} - -#pragma mark - - -- (WCSession *)session -{ - return [WCSession defaultSession]; -} - -@end - - -@interface TGBridgeSignalManager() -{ - os_unfair_lock _lock; - NSMutableDictionary *_disposables; -} -@end - -@implementation TGBridgeSignalManager - -- (instancetype)init -{ - self = [super init]; - if (self != nil) - { - _disposables = [[NSMutableDictionary alloc] init]; - } - return self; -} - -- (void)dealloc -{ - NSArray *disposables = nil; - os_unfair_lock_lock(&_lock); - disposables = [_disposables allValues]; - os_unfair_lock_unlock(&_lock); - - for (id disposable in disposables) - { - [disposable dispose]; - } -} - -- (bool)startSignalForKey:(NSString *)key producer:(SSignal *(^)())producer -{ - if (key == nil) - return false; - - bool produce = false; - os_unfair_lock_lock(&_lock); - if (_disposables[key] == nil) - { - _disposables[key] = [[SMetaDisposable alloc] init]; - produce = true; - } - os_unfair_lock_unlock(&_lock); - - if (produce) - { - __weak TGBridgeSignalManager *weakSelf = self; - id disposable = [producer() startWithNext:nil error:^(__unused id error) - { - __strong TGBridgeSignalManager *strongSelf = weakSelf; - if (strongSelf != nil) - { - os_unfair_lock_lock(&strongSelf->_lock); - [strongSelf->_disposables removeObjectForKey:key]; - os_unfair_lock_unlock(&strongSelf->_lock); - } - } completed:^ - { - __strong TGBridgeSignalManager *strongSelf = weakSelf; - if (strongSelf != nil) - { - os_unfair_lock_lock(&strongSelf->_lock); - [strongSelf->_disposables removeObjectForKey:key]; - os_unfair_lock_unlock(&strongSelf->_lock); - } - }]; - - os_unfair_lock_lock(&_lock); - [(SMetaDisposable *)_disposables[key] setDisposable:disposable]; - os_unfair_lock_unlock(&_lock); - } - - return produce; -} - -- (void)haltSignalForKey:(NSString *)key -{ - if (key == nil) - return; - - os_unfair_lock_lock(&_lock); - if (_disposables[key] != nil) - { - [_disposables[key] dispose]; - [_disposables removeObjectForKey:key]; - } - os_unfair_lock_unlock(&_lock); -} - -- (void)haltAllSignals -{ - os_unfair_lock_lock(&_lock); - for (NSObject *disposable in _disposables.allValues) - [disposable dispose]; - [_disposables removeAllObjects]; - os_unfair_lock_unlock(&_lock); -} - -@end diff --git a/submodules/WatchBridge/Sources/WatchBridge.swift b/submodules/WatchBridge/Sources/WatchBridge.swift deleted file mode 100644 index 8f88b40ff7..0000000000 --- a/submodules/WatchBridge/Sources/WatchBridge.swift +++ /dev/null @@ -1,551 +0,0 @@ -import Foundation -import Postbox -import TelegramCore -import WatchCommon -import TelegramPresentationData -import LegacyUI -import PhoneNumberFormat - -private func legacyImageLocationUri(resource: MediaResource) -> String? { - if let resource = resource as? CloudPeerPhotoSizeMediaResource { - return resource.id.stringRepresentation - } - return nil -} - -func makePeerIdFromBridgeIdentifier(_ identifier: Int64) -> PeerId? { - if identifier < 0 && identifier > Int32.min { - return PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(-identifier)) - } else if identifier < Int64(Int32.min) * 2 && identifier > Int64(Int32.min) * 3 { - return PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(Int64(Int32.min) &* 2 &- identifier)) - } else if identifier > 0 && identifier < Int32.max { - return PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(identifier)) - } else { - return nil - } -} - -func makeBridgeIdentifier(_ peerId: PeerId) -> Int64 { - switch peerId.namespace { - case Namespaces.Peer.CloudGroup: - return -Int64(peerId.id._internalGetInt64Value()) - case Namespaces.Peer.CloudChannel: - return Int64(Int32.min) * 2 - Int64(peerId.id._internalGetInt64Value()) - default: - return Int64(peerId.id._internalGetInt64Value()) - } -} - -func makeBridgeDeliveryState(_ message: Message?) -> TGBridgeMessageDeliveryState { - if let message = message { - if message.flags.contains(.Failed) { - return .failed - } - else if message.flags.contains(.Sending) { - return .pending - } - } - return .delivered -} - -private func makeBridgeImage(_ image: TelegramMediaImage?) -> TGBridgeImageMediaAttachment? { - if let image = image, let representation = largestImageRepresentation(image.representations) { - let bridgeImage = TGBridgeImageMediaAttachment() - bridgeImage.imageId = image.imageId.id - bridgeImage.dimensions = representation.dimensions.cgSize - return bridgeImage - } else { - return nil - } -} - -func makeBridgeDocument(_ file: TelegramMediaFile?) -> TGBridgeDocumentMediaAttachment? { - if let file = file { - let bridgeDocument = TGBridgeDocumentMediaAttachment() - bridgeDocument.documentId = file.fileId.id - bridgeDocument.fileSize = Int32(file.size ?? 0) - for attribute in file.attributes { - switch attribute { - case let .FileName(fileName): - bridgeDocument.fileName = fileName - case .Animated: - bridgeDocument.isAnimated = true - case let .ImageSize(size): - bridgeDocument.imageSize = NSValue(cgSize: size.cgSize) - case let .Sticker(displayText, packReference, _): - bridgeDocument.isSticker = true - bridgeDocument.stickerAlt = displayText - if let packReference = packReference, case let .id(id, accessHash) = packReference { - bridgeDocument.stickerPackId = id - bridgeDocument.stickerPackAccessHash = accessHash - } - case let .Audio(_, duration, title, performer, _): - bridgeDocument.duration = Int32(clamping: duration) - bridgeDocument.title = title - bridgeDocument.performer = performer - default: - break - } - } - return bridgeDocument - } - return nil -} - -func makeBridgeMedia(message: Message, strings: PresentationStrings, chatPeer: Peer? = nil, filterUnsupportedActions: Bool = true) -> [TGBridgeMediaAttachment] { - var bridgeMedia: [TGBridgeMediaAttachment] = [] - - if let forward = message.forwardInfo { - let bridgeForward = TGBridgeForwardedMessageMediaAttachment() - bridgeForward.peerId = forward.author.flatMap({ makeBridgeIdentifier($0.id) }) ?? 0 - if let sourceMessageId = forward.sourceMessageId { - bridgeForward.mid = sourceMessageId.id - } - bridgeForward.date = forward.date - bridgeMedia.append(bridgeForward) - } - - for attribute in message.attributes { - if let reply = attribute as? ReplyMessageAttribute, let replyMessage = message.associatedMessages[reply.messageId] { - let bridgeReply = TGBridgeReplyMessageMediaAttachment() - bridgeReply.mid = reply.messageId.id - bridgeReply.message = makeBridgeMessage(replyMessage, strings: strings) - bridgeMedia.append(bridgeReply) - } else if let entities = attribute as? TextEntitiesMessageAttribute { - var bridgeEntities: [Any] = [] - for entity in entities.entities { - var bridgeEntity: TGBridgeMessageEntity? = nil - switch entity.type { - case .Url: - bridgeEntity = TGBridgeMessageEntityUrl() - bridgeEntity?.range = NSRange(entity.range) - case .TextUrl: - bridgeEntity = TGBridgeMessageEntityTextUrl() - bridgeEntity?.range = NSRange(entity.range) - case .Email: - bridgeEntity = TGBridgeMessageEntityEmail() - bridgeEntity?.range = NSRange(entity.range) - case .Mention: - bridgeEntity = TGBridgeMessageEntityMention() - bridgeEntity?.range = NSRange(entity.range) - case .Hashtag: - bridgeEntity = TGBridgeMessageEntityHashtag() - bridgeEntity?.range = NSRange(entity.range) - case .BotCommand: - bridgeEntity = TGBridgeMessageEntityBotCommand() - bridgeEntity?.range = NSRange(entity.range) - case .Bold: - bridgeEntity = TGBridgeMessageEntityBold() - bridgeEntity?.range = NSRange(entity.range) - case .Italic: - bridgeEntity = TGBridgeMessageEntityItalic() - bridgeEntity?.range = NSRange(entity.range) - case .Code: - bridgeEntity = TGBridgeMessageEntityCode() - bridgeEntity?.range = NSRange(entity.range) - case .Pre: - bridgeEntity = TGBridgeMessageEntityPre() - bridgeEntity?.range = NSRange(entity.range) - default: - break - } - if let bridgeEntity = bridgeEntity { - bridgeEntities.append(bridgeEntity) - } - } - if !bridgeEntities.isEmpty { - let attachment = TGBridgeMessageEntitiesAttachment() - attachment.entities = bridgeEntities - bridgeMedia.append(attachment) - } - } - } - - for m in message.media { - if let image = m as? TelegramMediaImage, let bridgeImage = makeBridgeImage(image) { - bridgeMedia.append(bridgeImage) - } - else if let file = m as? TelegramMediaFile { - if file.isVideo { - let bridgeVideo = TGBridgeVideoMediaAttachment() - bridgeVideo.videoId = file.fileId.id - - for attribute in file.attributes { - switch attribute { - case let .Video(duration, size, flags, _, _, _): - bridgeVideo.duration = Int32(duration) - bridgeVideo.dimensions = size.cgSize - bridgeVideo.round = flags.contains(.instantRoundVideo) - default: - break - } - } - - bridgeMedia.append(bridgeVideo) - } else if file.isVoice { - let bridgeAudio = TGBridgeAudioMediaAttachment() - bridgeAudio.audioId = file.fileId.id - bridgeAudio.fileSize = Int32(clamping: file.size ?? 0) - - for attribute in file.attributes { - switch attribute { - case let .Audio(_, duration, _, _, _): - bridgeAudio.duration = Int32(clamping: duration) - default: - break - } - } - - bridgeMedia.append(bridgeAudio) - } else if let bridgeDocument = makeBridgeDocument(file) { - bridgeMedia.append(bridgeDocument) - } - } else if let action = m as? TelegramMediaAction { - var bridgeAction: TGBridgeActionMediaAttachment? = nil - var consumed = false - switch action.action { - case let .groupCreated(title): - bridgeAction = TGBridgeActionMediaAttachment() - if chatPeer is TelegramGroup { - bridgeAction?.actionType = .createChat - bridgeAction?.actionData = ["title": title] - } else if let channel = chatPeer as? TelegramChannel { - if case .group = channel.info { - bridgeAction?.actionType = .createChat - bridgeAction?.actionData = ["title": title] - } else { - bridgeAction?.actionType = .channelCreated - } - } - case let .phoneCall(_, discardReason, _, _): - let bridgeAttachment = TGBridgeUnsupportedMediaAttachment() - let incoming = message.flags.contains(.Incoming) - var compactTitle: String = "" - var subTitle: String = "" - if let discardReason = discardReason { - switch discardReason { - case .busy, .disconnect: - compactTitle = strings.Notification_CallCanceled - subTitle = strings.Notification_CallCanceledShort - case .missed: - compactTitle = incoming ? strings.Notification_CallMissed : strings.Notification_CallCanceled - subTitle = incoming ? strings.Notification_CallMissedShort : strings.Notification_CallCanceledShort - case .hangup: - break - } - } - if compactTitle.isEmpty { - compactTitle = incoming ? strings.Notification_CallIncoming : strings.Notification_CallOutgoing - subTitle = incoming ? strings.Notification_CallIncomingShort : strings.Notification_CallOutgoingShort - } - bridgeAttachment.compactTitle = compactTitle - bridgeAttachment.title = strings.Watch_Message_Call - bridgeAttachment.subtitle = subTitle - bridgeMedia.append(bridgeAttachment) - consumed = true - default: - break - } - if let bridgeAction = bridgeAction { - bridgeMedia.append(bridgeAction) - } else if !consumed && !filterUnsupportedActions { - let bridgeAttachment = TGBridgeUnsupportedMediaAttachment() - bridgeAttachment.compactTitle = "" - bridgeAttachment.title = "" - bridgeMedia.append(bridgeAttachment) - } - } else if let poll = m as? TelegramMediaPoll { - let bridgeAttachment = TGBridgeUnsupportedMediaAttachment() - bridgeAttachment.compactTitle = strings.Watch_Message_Poll - bridgeAttachment.title = strings.Watch_Message_Poll - bridgeAttachment.subtitle = poll.text - bridgeMedia.append(bridgeAttachment) - } else if let contact = m as? TelegramMediaContact { - let bridgeContact = TGBridgeContactMediaAttachment() - if let peerId = contact.peerId { - bridgeContact.uid = Int32(clamping: makeBridgeIdentifier(peerId)) - } - bridgeContact.firstName = contact.firstName - bridgeContact.lastName = contact.lastName - bridgeContact.phoneNumber = contact.phoneNumber - bridgeContact.prettyPhoneNumber = formatPhoneNumber(contact.phoneNumber) - bridgeMedia.append(bridgeContact) - } else if let map = m as? TelegramMediaMap { - let bridgeLocation = TGBridgeLocationMediaAttachment() - bridgeLocation.latitude = map.latitude - bridgeLocation.longitude = map.longitude - if let venue = map.venue { - let bridgeVenue = TGBridgeVenueAttachment() - bridgeVenue.title = venue.title - bridgeVenue.address = venue.address - bridgeVenue.provider = venue.provider - bridgeVenue.venueId = venue.id - bridgeLocation.venue = bridgeVenue - } - bridgeMedia.append(bridgeLocation) - } else if let webpage = m as? TelegramMediaWebpage { - if case let .Loaded(content) = webpage.content { - let bridgeWebpage = TGBridgeWebPageMediaAttachment() - bridgeWebpage.webPageId = webpage.id?.id ?? 0 - bridgeWebpage.url = content.url - bridgeWebpage.displayUrl = content.displayUrl - bridgeWebpage.pageType = content.type - bridgeWebpage.siteName = content.websiteName - bridgeWebpage.title = content.title - bridgeWebpage.pageDescription = content.text - bridgeWebpage.photo = makeBridgeImage(content.image) - bridgeWebpage.embedUrl = content.embedUrl - bridgeWebpage.embedType = content.embedType - bridgeWebpage.embedSize = content.embedSize?.cgSize ?? CGSize() - bridgeWebpage.duration = NSNumber(integerLiteral: content.duration ?? 0) - bridgeWebpage.author = content.author - bridgeMedia.append(bridgeWebpage) - } - } else if let game = m as? TelegramMediaGame { - let bridgeAttachment = TGBridgeUnsupportedMediaAttachment() - bridgeAttachment.compactTitle = game.title - bridgeAttachment.title = strings.Watch_Message_Game - bridgeAttachment.subtitle = game.title - bridgeMedia.append(bridgeAttachment) - } else if let invoice = m as? TelegramMediaInvoice { - let bridgeAttachment = TGBridgeUnsupportedMediaAttachment() - bridgeAttachment.compactTitle = invoice.title - bridgeAttachment.title = strings.Watch_Message_Invoice - bridgeAttachment.subtitle = invoice.title - bridgeMedia.append(bridgeAttachment) - } else if let _ = m as? TelegramMediaUnsupported { - let bridgeAttachment = TGBridgeUnsupportedMediaAttachment() - bridgeAttachment.compactTitle = strings.Watch_Message_Unsupported - bridgeAttachment.title = strings.Watch_Message_Unsupported - bridgeAttachment.subtitle = "" - bridgeMedia.append(bridgeAttachment) - } - } - return bridgeMedia -} - -func makeBridgeChat(_ entry: ChatListEntry, strings: PresentationStrings) -> (TGBridgeChat, [Int64 : TGBridgeUser])? { - if case let .MessageEntry(entryData) = entry { - let index = entryData.index - let messages = entryData.messages - let readState = entryData.readState - let renderedPeer = entryData.renderedPeer - let hasFailed = entryData.hasFailed - - guard index.messageIndex.id.peerId.namespace != Namespaces.Peer.SecretChat else { - return nil - } - let message = messages.last - let (bridgeChat, participants) = makeBridgeChat(renderedPeer.peer) - bridgeChat.date = TimeInterval(index.messageIndex.timestamp) - if let message = message { - if let author = message.author { - bridgeChat.fromUid = Int32(clamping: makeBridgeIdentifier(author.id)) - } - bridgeChat.text = message.text - bridgeChat.outgoing = !message.flags.contains(.Incoming) - bridgeChat.deliveryState = makeBridgeDeliveryState(message) - bridgeChat.deliveryError = hasFailed - bridgeChat.media = makeBridgeMedia(message: message, strings: strings, filterUnsupportedActions: false) - } - bridgeChat.unread = readState?.state.isUnread ?? false - bridgeChat.unreadCount = readState?.state.count ?? 0 - - var bridgeUsers: [Int64 : TGBridgeUser] = participants - if let bridgeUser = makeBridgeUser(message?.author, presence: nil) { - bridgeUsers[bridgeUser.identifier] = bridgeUser - } - if let user = renderedPeer.peer as? TelegramUser, user.id != message?.author?.id, let bridgeUser = makeBridgeUser(user, presence: nil) { - bridgeUsers[bridgeUser.identifier] = bridgeUser - } - - return (bridgeChat, bridgeUsers) - } - return nil -} - -func makeBridgeChat(_ peer: Peer?, view: PeerView? = nil) -> (TGBridgeChat, [Int64 : TGBridgeUser]) { - let bridgeChat = TGBridgeChat() - var bridgeUsers: [Int64 : TGBridgeUser] = [:] - if let peer = peer { - bridgeChat.identifier = makeBridgeIdentifier(peer.id) - bridgeChat.userName = peer.addressName - } - if let group = peer as? TelegramGroup { - bridgeChat.isGroup = true - bridgeChat.groupTitle = group.title - bridgeChat.participantsCount = Int32(clamping: group.participantCount) - - if let representation = smallestImageRepresentation(group.photo) { - bridgeChat.groupPhotoSmall = legacyImageLocationUri(resource: representation.resource) - } - if let representation = largestImageRepresentation(group.photo) { - bridgeChat.groupPhotoBig = legacyImageLocationUri(resource: representation.resource) - } - if let view = view, let cachedData = view.cachedData as? CachedGroupData, let participants = cachedData.participants { - bridgeChat.participantsCount = Int32(clamping: participants.participants.count) - var bridgeParticipants: [Int64] = [] - for participant in participants.participants { - if let user = view.peers[participant.peerId], let bridgeUser = makeBridgeUser(user, presence: view.peerPresences[user.id]) { - bridgeParticipants.append(bridgeUser.identifier) - bridgeUsers[bridgeUser.identifier] = bridgeUser - } - } - bridgeChat.participants = bridgeParticipants - } - } else if let channel = peer as? TelegramChannel { - bridgeChat.isChannel = true - bridgeChat.groupTitle = channel.title - if case .group = channel.info { - bridgeChat.isChannelGroup = true - } - bridgeChat.verified = channel.flags.contains(.isVerified) - - if let representation = smallestImageRepresentation(channel.photo) { - bridgeChat.groupPhotoSmall = legacyImageLocationUri(resource: representation.resource) - } - if let representation = largestImageRepresentation(channel.photo) { - bridgeChat.groupPhotoBig = legacyImageLocationUri(resource: representation.resource) - } - if let view = view, let cachedData = view.cachedData as? CachedChannelData { - bridgeChat.about = cachedData.about - } - } - - // _hasLeftGroup = [aDecoder decodeBoolForKey:TGBridgeChatHasLeftGroupKey]; - // _isKickedFromGroup = [aDecoder decodeBoolForKey:TGBridgeChatIsKickedFromGroupKey]; - return (bridgeChat, bridgeUsers) -} - -func makeBridgeUser(_ peer: Peer?, presence: PeerPresence? = nil, cachedData: CachedPeerData? = nil) -> TGBridgeUser? { - if let user = peer as? TelegramUser { - let bridgeUser = TGBridgeUser() - bridgeUser.identifier = makeBridgeIdentifier(user.id) - bridgeUser.firstName = user.firstName - bridgeUser.lastName = user.lastName - bridgeUser.userName = user.addressName - bridgeUser.phoneNumber = user.phone - if let phone = user.phone { - bridgeUser.prettyPhoneNumber = formatPhoneNumber(phone) - } - if let presence = presence as? TelegramUserPresence { - let timestamp = 0 - switch presence.status { - case .recently: - bridgeUser.lastSeen = -2 - case .lastWeek: - bridgeUser.lastSeen = -3 - case .lastMonth: - bridgeUser.lastSeen = -4 - case .none: - bridgeUser.lastSeen = -5 - case let .present(statusTimestamp): - if statusTimestamp > timestamp { - bridgeUser.online = true - } - bridgeUser.lastSeen = TimeInterval(statusTimestamp) - } - } - if let cachedData = cachedData as? CachedUserData { - bridgeUser.about = cachedData.about - } - if let representation = smallestImageRepresentation(user.photo) { - bridgeUser.photoSmall = legacyImageLocationUri(resource: representation.resource) - } - if let representation = largestImageRepresentation(user.photo) { - bridgeUser.photoBig = legacyImageLocationUri(resource: representation.resource) - } - if user.botInfo != nil { - bridgeUser.kind = .bot - bridgeUser.botKind = .generic - } - bridgeUser.verified = user.flags.contains(.isVerified) - return bridgeUser - } else { - return nil - } -} - -func makeBridgePeers(_ message: Message) -> [Int64 : Any] { - var bridgeUsers: [Int64 : Any] = [:] - for (_, peer) in message.peers { - if peer is TelegramUser, let bridgeUser = makeBridgeUser(peer, presence: nil) { - bridgeUsers[bridgeUser.identifier] = bridgeUser - } else if peer is TelegramGroup || peer is TelegramChannel { - let bridgeChat = makeBridgeChat(peer) - bridgeUsers[bridgeChat.0.identifier] = bridgeChat.0 - } - } - if let author = message.author, let bridgeUser = makeBridgeUser(author) { - bridgeUsers[bridgeUser.identifier] = bridgeUser - } - return bridgeUsers -} - -func makeBridgeMessage(_ entry: MessageHistoryEntry, strings: PresentationStrings) -> (TGBridgeMessage, [Int64 : TGBridgeUser])? { - guard let bridgeMessage = makeBridgeMessage(entry.message, strings: strings) else { - return nil - } - if entry.message.id.namespace == Namespaces.Message.Local && !entry.message.flags.contains(.Failed) { - return nil - } - - bridgeMessage.unread = !entry.isRead - - var bridgeUsers: [Int64 : TGBridgeUser] = [:] - if let bridgeUser = makeBridgeUser(entry.message.author, presence: nil) { - bridgeUsers[bridgeUser.identifier] = bridgeUser - } - for (_, peer) in entry.message.peers { - if let bridgeUser = makeBridgeUser(peer, presence: nil) { - bridgeUsers[bridgeUser.identifier] = bridgeUser - } - } - - return (bridgeMessage, bridgeUsers) -} - -func makeBridgeMessage(_ message: Message, strings: PresentationStrings, chatPeer: Peer? = nil) -> TGBridgeMessage? { - var chatPeer = chatPeer - if chatPeer == nil { - chatPeer = message.peers[message.id.peerId] - } - - let bridgeMessage = TGBridgeMessage() - bridgeMessage.identifier = message.id.id - bridgeMessage.date = TimeInterval(message.timestamp) - bridgeMessage.randomId = message.globallyUniqueId ?? 0 -// bridgeMessage.unread = false - bridgeMessage.outgoing = !message.flags.contains(.Incoming) - if let author = message.author { - bridgeMessage.fromUid = makeBridgeIdentifier(author.id) - } - bridgeMessage.toUid = makeBridgeIdentifier(message.id.peerId) - bridgeMessage.cid = makeBridgeIdentifier(message.id.peerId) - bridgeMessage.text = message.text - bridgeMessage.deliveryState = makeBridgeDeliveryState(message) - bridgeMessage.media = makeBridgeMedia(message: message, strings: strings, chatPeer: chatPeer) - return bridgeMessage -} - -func makeVenue(from bridgeVenue: TGBridgeVenueAttachment?) -> MapVenue? { - if let bridgeVenue = bridgeVenue { - return MapVenue(title: bridgeVenue.title, address: bridgeVenue.address, provider: bridgeVenue.provider, id: bridgeVenue.venueId, type: "") - } - return nil -} - -func makeBridgeLocationVenue(_ contextResult: ChatContextResultMessage) -> TGBridgeLocationVenue? { - if case let .mapLocation(mapMedia, _) = contextResult { - let bridgeVenue = TGBridgeLocationVenue() - bridgeVenue.coordinate = CLLocationCoordinate2D(latitude: mapMedia.latitude, longitude: mapMedia.longitude) - if let venue = mapMedia.venue { - bridgeVenue.name = venue.title - bridgeVenue.address = venue.address - bridgeVenue.provider = venue.provider - bridgeVenue.identifier = venue.id - } - return bridgeVenue - } - return nil -} diff --git a/submodules/WatchBridge/Sources/WatchCommunicationManager.swift b/submodules/WatchBridge/Sources/WatchCommunicationManager.swift deleted file mode 100644 index 1c69d158e5..0000000000 --- a/submodules/WatchBridge/Sources/WatchCommunicationManager.swift +++ /dev/null @@ -1,219 +0,0 @@ -import Foundation -import SwiftSignalKit -import Postbox -import TelegramCore -import WatchCommon -import SSignalKit -import TelegramUIPreferences -import AccountContext -import WatchBridgeImpl - -public final class WatchCommunicationManagerContext { - public let context: AccountContext - - public init(context: AccountContext) { - self.context = context - } -} - -public final class WatchManagerArguments { - public let appInstalled: Signal - public let navigateToMessageRequested: Signal - public let runningTasks: Signal - - public init(appInstalled: Signal, navigateToMessageRequested: Signal, runningTasks: Signal) { - self.appInstalled = appInstalled - self.navigateToMessageRequested = navigateToMessageRequested - self.runningTasks = runningTasks - } -} - -public final class WatchCommunicationManager { - private let queue: Queue - private let allowBackgroundTimeExtension: (Double) -> Void - - private var server: TGBridgeServer! - - private let contextDisposable = MetaDisposable() - private let presetsDisposable = MetaDisposable() - - let accountContext = Promise(nil) - private let presets = Promise(nil) - private let navigateToMessagePipe = ValuePipe() - - public init(queue: Queue, context: Signal, allowBackgroundTimeExtension: @escaping (Double) -> Void) { - self.queue = queue - self.allowBackgroundTimeExtension = allowBackgroundTimeExtension - - let handlers = allWatchRequestHandlers.reduce([String : AnyClass]()) { (map, handler) -> [String : AnyClass] in - var map = map - if let handler = handler as? WatchRequestHandler.Type { - for case let subscription as TGBridgeSubscription.Type in handler.handledSubscriptions { - if let name = subscription.subscriptionName() { - map[name] = handler - } - } - } - return map - } - - self.server = TGBridgeServer(handler: { [weak self] subscription -> SSignal? in - guard let strongSelf = self, let subscription = subscription, let handler = handlers[subscription.name] as? WatchRequestHandler.Type else { - return nil - } - return handler.handle(subscription: subscription, manager: strongSelf) - }, fileHandler: { [weak self] path, metadata in - guard let strongSelf = self, let path = path, let metadata = metadata as? [String : Any] else { - return - } - if metadata[TGBridgeIncomingFileTypeKey] as? String == TGBridgeIncomingFileTypeAudio { - let _ = WatchAudioHandler.handleFile(path: path, metadata: metadata, manager: strongSelf).start() - } - }, dispatchOnQueue: { [weak self] block in - if let strongSelf = self { - strongSelf.queue.justDispatch(block) - } - }, logFunction: { value in - if let value = value { - Logger.shared.log("WatchBridge", value) - } - }, allowBackgroundTimeExtension: { - allowBackgroundTimeExtension(4.0) - }) - self.server.startRunning() - - self.contextDisposable.set((combineLatest(self.watchAppInstalled, context |> deliverOn(self.queue))).start(next: { [weak self] appInstalled, appContext in - guard let strongSelf = self, appInstalled else { - return - } - if let context = appContext { - strongSelf.accountContext.set(.single(context.context)) - strongSelf.server.setAuthorized(true, userId: context.context.account.peerId.id._internalGetInt64Value()) - strongSelf.server.setMicAccessAllowed(false) - strongSelf.server.pushContext() - strongSelf.server.setMicAccessAllowed(true) - strongSelf.server.pushContext() - - strongSelf.presets.set(context.context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.watchPresetSettings]) - |> map({ sharedData -> WatchPresetSettings in - return sharedData.entries[ApplicationSpecificSharedDataKeys.watchPresetSettings]?.get(WatchPresetSettings.self) ?? WatchPresetSettings.defaultSettings - })) - } else { - strongSelf.accountContext.set(.single(nil)) - strongSelf.server.setAuthorized(false, userId: 0) - strongSelf.server.pushContext() - - strongSelf.presets.set(.single(nil)) - } - })) - - self.presetsDisposable.set((combineLatest(self.watchAppInstalled, self.presets.get() |> distinctUntilChanged |> deliverOn(self.queue), context |> deliverOn(self.queue))).start(next: { [weak self] appInstalled, presets, appContext in - guard let strongSelf = self, let presets = presets, let context = appContext, appInstalled, let tempPath = strongSelf.watchTemporaryStorePath else { - return - } - let presentationData = context.context.sharedContext.currentPresentationData.with { $0 } - let defaultSuggestions: [String : String] = [ - "OK": presentationData.strings.Watch_Suggestion_OK, - "Thanks": presentationData.strings.Watch_Suggestion_Thanks, - "WhatsUp": presentationData.strings.Watch_Suggestion_WhatsUp, - "TalkLater": presentationData.strings.Watch_Suggestion_TalkLater, - "CantTalk": presentationData.strings.Watch_Suggestion_CantTalk, - "HoldOn": presentationData.strings.Watch_Suggestion_HoldOn, - "BRB": presentationData.strings.Watch_Suggestion_BRB, - "OnMyWay": presentationData.strings.Watch_Suggestion_OnMyWay - ] - - var suggestions: [String : String] = [:] - for (key, defaultValue) in defaultSuggestions { - suggestions[key] = presets.customPresets[key] ?? defaultValue - } - - let fileManager = FileManager.default - let presetsFileUrl = URL(fileURLWithPath: tempPath + "/presets.dat") - - if fileManager.fileExists(atPath: presetsFileUrl.path) { - try? fileManager.removeItem(atPath: presetsFileUrl.path) - } - let data = try? NSKeyedArchiver.archivedData(withRootObject: suggestions, requiringSecureCoding: false) - try? data?.write(to: presetsFileUrl) - - let _ = strongSelf.sendFile(url: presetsFileUrl, metadata: [TGBridgeIncomingFileIdentifierKey: "presets"]).start() - })) - } - - deinit { - self.contextDisposable.dispose() - self.presetsDisposable.dispose() - } - - public var arguments: WatchManagerArguments { - return WatchManagerArguments(appInstalled: self.watchAppInstalled, navigateToMessageRequested: self.navigateToMessagePipe.signal(), runningTasks: self.runningTasks) - } - - public func requestNavigateToMessage(messageId: MessageId) { - self.navigateToMessagePipe.putNext(messageId) - } - - private var watchAppInstalled: Signal { - return Signal { subscriber in - let disposable = self.server.watchAppInstalledSignal().start(next: { value in - if let value = value as? NSNumber { - subscriber.putNext(value.boolValue) - } - }) - return ActionDisposable { - disposable?.dispose() - } - } |> deliverOn(self.queue) - } - - private var runningTasks: Signal { - return Signal { subscriber in - let disposable = self.server.runningRequestsSignal().start(next: { value in - if let value = value as? Dictionary { - if let running = value["running"] as? Bool, let version = value["version"] as? Int32 { - subscriber.putNext(WatchRunningTasks(running: running, version: version)) - } - } - }) - return ActionDisposable { - disposable?.dispose() - } - } |> deliverOn(self.queue) - } - - public var watchTemporaryStorePath: String? { - return self.server.temporaryFilesURL?.path - } - - public func sendFile(url: URL, metadata: Dictionary, asMessageData: Bool = false) -> Signal { - return Signal { subscriber in - self.server.sendFile(with: url, metadata: metadata, asMessageData: asMessageData) - subscriber.putCompletion() - return EmptyDisposable - } |> runOn(self.queue) - } - - public func sendFile(data: Data, metadata: Dictionary) -> Signal { - return Signal { subscriber in - self.server.sendFile(with: data, metadata: metadata, errorHandler: {}) - subscriber.putCompletion() - return EmptyDisposable - } |> runOn(self.queue) - } -} - -public func watchCommunicationManager(context: Signal, allowBackgroundTimeExtension: @escaping (Double) -> Void) -> Signal { - return Signal { subscriber in - let queue = Queue() - queue.async { - if #available(iOSApplicationExtension 9.0, *) { - subscriber.putNext(WatchCommunicationManager(queue: queue, context: context, allowBackgroundTimeExtension: allowBackgroundTimeExtension)) - } else { - subscriber.putNext(nil) - } - subscriber.putCompletion() - } - return EmptyDisposable - } -} diff --git a/submodules/WatchBridge/Sources/WatchRequestHandlers.swift b/submodules/WatchBridge/Sources/WatchRequestHandlers.swift deleted file mode 100644 index 2292d590eb..0000000000 --- a/submodules/WatchBridge/Sources/WatchRequestHandlers.swift +++ /dev/null @@ -1,884 +0,0 @@ -import Foundation -import SwiftSignalKit -import Postbox -import Display -import TelegramCore -import LegacyComponents -import WatchCommon -import TelegramPresentationData -import AvatarNode -import StickerResources -import PhotoResources -import AccountContext -import WatchBridgeAudio - -let allWatchRequestHandlers: [AnyClass] = [ - WatchChatListHandler.self, - WatchChatMessagesHandler.self, - WatchSendMessageHandler.self, - WatchPeerInfoHandler.self, - WatchMediaHandler.self, - WatchStickersHandler.self, - WatchAudioHandler.self, - WatchLocationHandler.self, - WatchPeerSettingsHandler.self, - WatchContinuationHandler.self, -] - -protocol WatchRequestHandler: AnyObject { - static var handledSubscriptions: [Any] { get } - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal -} - -final class WatchChatListHandler: WatchRequestHandler { - static var handledSubscriptions: [Any] { - return [TGBridgeChatListSubscription.self] - } - - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal { - if let args = subscription as? TGBridgeChatListSubscription { - let limit = Int(args.limit) - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal<(ChatListView, PresentationData), NoError> in - if let context = context { - return context.account.viewTracker.tailChatListView(groupId: .root, count: limit) - |> map { chatListView, _ -> (ChatListView, PresentationData) in - return (chatListView, context.sharedContext.currentPresentationData.with { $0 }) - } - } else { - return .complete() - } - }) - let disposable = signal.start(next: { chatListView, presentationData in - var chats: [TGBridgeChat] = [] - var users: [Int64 : TGBridgeUser] = [:] - for entry in chatListView.entries.reversed() { - if let (chat, chatUsers) = makeBridgeChat(entry, strings: presentationData.strings) { - chats.append(chat) - users = users.merging(chatUsers, uniquingKeysWith: { (_, last) in last }) - } - } - subscriber.putNext([ TGBridgeChatsArrayKey: chats, TGBridgeUsersDictionaryKey: users ] as [String: Any]) - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } else { - return SSignal.fail(nil) - } - } -} - - -final class WatchChatMessagesHandler: WatchRequestHandler { - static var handledSubscriptions: [Any] { - return [ - TGBridgeChatMessageListSubscription.self, - TGBridgeChatMessageSubscription.self, - TGBridgeReadChatMessageListSubscription.self - ] - } - - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal { - if let args = subscription as? TGBridgeChatMessageListSubscription, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - return SSignal { subscriber in - let limit = Int(args.rangeMessageCount) - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal<(MessageHistoryView, Bool, PresentationData), NoError> in - if let context = context { - return context.account.viewTracker.aroundMessageHistoryViewForLocation(.peer(peerId: peerId, threadId: nil), index: .upperBound, anchorIndex: .upperBound, count: limit, fixedCombinedReadStates: nil) - |> map { messageHistoryView, _, _ -> (MessageHistoryView, Bool, PresentationData) in - return (messageHistoryView, peerId == context.account.peerId, context.sharedContext.currentPresentationData.with { $0 }) - } - } else { - return .complete() - } - }) - let disposable = signal.start(next: { messageHistoryView, savedMessages, presentationData in - var messages: [TGBridgeMessage] = [] - var users: [Int64 : TGBridgeUser] = [:] - for entry in messageHistoryView.entries.reversed() { - if let (message, messageUsers) = makeBridgeMessage(entry, strings: presentationData.strings) { - messages.append(message) - users = users.merging(messageUsers, uniquingKeysWith: { (_, last) in last }) - } - } - subscriber.putNext([ TGBridgeMessagesArrayKey: messages, TGBridgeUsersDictionaryKey: users ] as [String: Any]) - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } else if let args = subscription as? TGBridgeReadChatMessageListSubscription, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal in - if let context = context { - let messageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: args.messageId) - return context.engine.messages.applyMaxReadIndexInteractively(index: MessageIndex(id: messageId, timestamp: 0)) - } else { - return .complete() - } - }) - let disposable = signal.start(next: { _ in - subscriber.putNext(true) - }, completed: { - subscriber.putCompletion() - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } else if let args = subscription as? TGBridgeChatMessageSubscription, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal<(Message, PresentationData)?, NoError> in - if let context = context { - let messageSignal = context.engine.messages.downloadMessage(messageId: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: args.messageId)) - |> map { message -> (Message, PresentationData)? in - if let message = message { - return (message, context.sharedContext.currentPresentationData.with { $0 }) - } else { - return nil - } - } - return messageSignal |> timeout(3.5, queue: Queue.concurrentDefaultQueue(), alternate: .single(nil)) - } else { - return .single(nil) - } - }) - let disposable = signal.start(next: { messageAndPresentationData in - if let (message, presentationData) = messageAndPresentationData, let bridgeMessage = makeBridgeMessage(message, strings: presentationData.strings) { - let peers = makeBridgePeers(message) - var response: [String : Any] = [TGBridgeMessageKey: bridgeMessage, TGBridgeUsersDictionaryKey: peers] - if peerId.namespace != Namespaces.Peer.CloudUser { - response[TGBridgeChatKey] = peers[makeBridgeIdentifier(peerId)] - } - subscriber.putNext(response) - } - subscriber.putCompletion() - }) - return SBlockDisposable { - disposable.dispose() - } - } - } - return SSignal.fail(nil) - } -} - -final class WatchSendMessageHandler: WatchRequestHandler { - static var handledSubscriptions: [Any] { - return [ - TGBridgeSendTextMessageSubscription.self, - TGBridgeSendLocationMessageSubscription.self, - TGBridgeSendStickerMessageSubscription.self, - TGBridgeSendForwardedMessageSubscription.self - ] - } - - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal { - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal in - if let context = context { - var messageSignal: Signal<(EnqueueMessage?, PeerId?), NoError>? - if let args = subscription as? TGBridgeSendTextMessageSubscription { - let peerId = makePeerIdFromBridgeIdentifier(args.peerId) - var replyMessageId: MessageId? - if args.replyToMid != 0, let peerId = peerId { - replyMessageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: args.replyToMid) - } - messageSignal = .single((.message(text: args.text, attributes: [], inlineStickers: [:], mediaReference: nil, threadId: nil, replyToMessageId: replyMessageId.flatMap { EngineMessageReplySubject(messageId: $0, quote: nil) }, replyToStoryId: nil, localGroupingKey: nil, correlationId: nil, bubbleUpEmojiOrStickersets: []), peerId)) - } else if let args = subscription as? TGBridgeSendLocationMessageSubscription, let location = args.location { - let peerId = makePeerIdFromBridgeIdentifier(args.peerId) - let map = TelegramMediaMap(latitude: location.latitude, longitude: location.longitude, heading: nil, accuracyRadius: nil, venue: makeVenue(from: location.venue), liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil) - messageSignal = .single((.message(text: "", attributes: [], inlineStickers: [:], mediaReference: .standalone(media: map), threadId: nil, replyToMessageId: nil, replyToStoryId: nil, localGroupingKey: nil, correlationId: nil, bubbleUpEmojiOrStickersets: []), peerId)) - } else if let args = subscription as? TGBridgeSendStickerMessageSubscription { - let peerId = makePeerIdFromBridgeIdentifier(args.peerId) - messageSignal = mediaForSticker(documentId: args.document.documentId, account: context.account) - |> map({ media -> (EnqueueMessage?, PeerId?) in - if let media = media { - return (.message(text: "", attributes: [], inlineStickers: [:], mediaReference: .standalone(media: media), threadId: nil, replyToMessageId: nil, replyToStoryId: nil, localGroupingKey: nil, correlationId: nil, bubbleUpEmojiOrStickersets: []), peerId) - } else { - return (nil, nil) - } - }) - } else if let args = subscription as? TGBridgeSendForwardedMessageSubscription { - let peerId = makePeerIdFromBridgeIdentifier(args.targetPeerId) - if let forwardPeerId = makePeerIdFromBridgeIdentifier(args.peerId) { - messageSignal = .single((.forward(source: MessageId(peerId: forwardPeerId, namespace: Namespaces.Message.Cloud, id: args.messageId), threadId: nil, grouping: .none, attributes: [], correlationId: nil), peerId)) - } - } - - if let messageSignal = messageSignal { - return messageSignal |> mapToSignal({ message, peerId -> Signal in - if let message = message, let peerId = peerId { - return enqueueMessages(account: context.account, peerId: peerId, messages: [message]) |> mapToSignal({ _ in - return .single(true) - }) - } else { - return .complete() - } - }) - } - } - return .complete() - }) - - let disposable = signal.start(next: { _ in - subscriber.putNext(true) - }, completed: { - subscriber.putCompletion() - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } -} - -final class WatchPeerInfoHandler: WatchRequestHandler { - static var handledSubscriptions: [Any] { - return [ - TGBridgeUserInfoSubscription.self, - TGBridgeUserBotInfoSubscription.self, - TGBridgeConversationSubscription.self - ] - } - - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal { - if let args = subscription as? TGBridgeUserInfoSubscription { - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal in - if let context = context, let userId = args.userIds.first as? Int64, let peerId = makePeerIdFromBridgeIdentifier(userId) { - return context.account.viewTracker.peerView(peerId) - } else { - return .complete() - } - }) - let disposable = signal.start(next: { view in - if let user = makeBridgeUser(peerViewMainPeer(view), presence: view.peerPresences[view.peerId], cachedData: view.cachedData) { - subscriber.putNext([user.identifier: user]) - } else { - subscriber.putCompletion() - } - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } else if let _ = subscription as? TGBridgeUserBotInfoSubscription { - return SSignal.complete() - } else if let args = subscription as? TGBridgeConversationSubscription { - return SSignal { subscriber in - let signal = manager.accountContext.get() |> take(1) |> mapToSignal({ context -> Signal in - if let context = context, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - return context.account.viewTracker.peerView(peerId) - } else { - return .complete() - } - }) - let disposable = signal.start(next: { view in - let (chat, users) = makeBridgeChat(peerViewMainPeer(view), view: view) - subscriber.putNext([ TGBridgeChatKey: chat, TGBridgeUsersDictionaryKey: users ] as [String: Any]) - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } - return SSignal.fail(nil) - } -} - -private func mediaForSticker(documentId: Int64, account: Account) -> Signal { - return account.postbox.itemCollectionsView(orderedItemListCollectionIds: [Namespaces.OrderedItemList.CloudSavedStickers, Namespaces.OrderedItemList.CloudRecentStickers], namespaces: [Namespaces.ItemCollection.CloudStickerPacks], aroundIndex: nil, count: 50) - |> take(1) - |> map { view -> TelegramMediaFile? in - for view in view.orderedItemListsViews { - for entry in view.items { - if let file = entry.contents.get(SavedStickerItem.self)?.file { - if file.id.id == documentId { - return file._parse() - } - } else if let file = entry.contents.get(RecentMediaItem.self)?.media { - if file.id.id == documentId { - return file._parse() - } - } - } - } - return nil - } -} - -private let roundCorners = { () -> UIImage in - let diameter: CGFloat = 44.0 - UIGraphicsBeginImageContextWithOptions(CGSize(width: diameter, height: diameter), false, 0.0) - let context = UIGraphicsGetCurrentContext()! - context.setBlendMode(.copy) - context.setFillColor(UIColor.black.cgColor) - context.fill(CGRect(origin: CGPoint(), size: CGSize(width: diameter, height: diameter))) - context.setBlendMode(.clear) - context.setFillColor(UIColor.clear.cgColor) - context.fillEllipse(in: CGRect(origin: CGPoint(), size: CGSize(width: diameter, height: diameter))) - let image = UIGraphicsGetImageFromCurrentImageContext()!.stretchableImage(withLeftCapWidth: Int(diameter / 2.0), topCapHeight: Int(diameter / 2.0)) - UIGraphicsEndImageContext() - return image -}() - -private func sendData(manager: WatchCommunicationManager, data: Data, key: String, ext: String, type: String, forceAsData: Bool = false) { - if let tempPath = manager.watchTemporaryStorePath, !forceAsData { - let tempFileUrl = URL(fileURLWithPath: tempPath + "/\(key)\(ext)") - let _ = try? data.write(to: tempFileUrl) - let _ = manager.sendFile(url: tempFileUrl, metadata: [TGBridgeIncomingFileTypeKey: type, TGBridgeIncomingFileIdentifierKey: key]).start() - } else { - let _ = manager.sendFile(data: data, metadata: [TGBridgeIncomingFileTypeKey: type, TGBridgeIncomingFileIdentifierKey: key]).start() - } -} - -final class WatchMediaHandler: WatchRequestHandler { - static var handledSubscriptions: [Any] { - return [ - TGBridgeMediaThumbnailSubscription.self, - TGBridgeMediaAvatarSubscription.self, - TGBridgeMediaStickerSubscription.self - ] - } - - static private let disposable = DisposableSet() - - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal { - if let args = subscription as? TGBridgeMediaAvatarSubscription, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - let key = "\(args.url!)_\(args.type.rawValue)" - let targetSize: CGSize - var compressionRate: CGFloat = 0.5 - var round = false - switch args.type { - case .small: - targetSize = CGSize(width: 19, height: 19); - compressionRate = 0.5 - case .profile: - targetSize = CGSize(width: 44, height: 44); - round = true - case .large: - targetSize = CGSize(width: 150, height: 150); - @unknown default: - fatalError() - } - - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal in - if let context = context { - return context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) - |> mapToSignal { peer -> Signal in - if let peer = peer, case let .secretChat(secretChat) = peer { - return context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: secretChat.regularPeerId)) - } else { - return .single(peer) - } - } - |> mapToSignal({ peer -> Signal in - if let peer = peer, let representation = peer.smallProfileImage { - let imageData = peerAvatarImageData(account: context.account, peerReference: PeerReference(peer._asPeer()), authorOfMessage: nil, representation: representation, synchronousLoad: false) - if let imageData = imageData { - return imageData - |> map { data -> UIImage? in - if let (data, _) = data, let image = generateImage(targetSize, contextGenerator: { size, context -> Void in - if let imageSource = CGImageSourceCreateWithData(data as CFData, nil), let dataImage = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) { - context.setBlendMode(.copy) - context.draw(dataImage, in: CGRect(origin: CGPoint(), size: targetSize)) - if round { - context.setBlendMode(.normal) - context.draw(roundCorners.cgImage!, in: CGRect(origin: CGPoint(), size: targetSize)) - } - } - }, scale: 2.0) { - return image - } - return nil - } - } - } - return .single(nil) - }) - } else { - return .complete() - } - }) - - let disposable = signal.start(next: { image in - if let image = image, let imageData = image.jpegData(compressionQuality: compressionRate) { - sendData(manager: manager, data: imageData, key: key, ext: ".jpg", type: TGBridgeIncomingFileTypeImage, forceAsData: true) - } - subscriber.putNext(key) - }, completed: { - subscriber.putCompletion() - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } else if let args = subscription as? TGBridgeMediaStickerSubscription { - let key = "sticker_\(args.documentId)_\(Int(args.size.width))x\(Int(args.size.height))_\(args.notification ? 1 : 0)" - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal in - if let context = context { - var mediaSignal: Signal<(TelegramMediaFile, FileMediaReference)?, NoError>? = nil - if args.stickerPackId != 0 { - mediaSignal = mediaForSticker(documentId: args.documentId, account: context.account) - |> map { media -> (TelegramMediaFile, FileMediaReference)? in - if let media = media { - return (media, .standalone(media: media)) - } else { - return nil - } - } - } else if args.stickerPeerId != 0, let peerId = makePeerIdFromBridgeIdentifier(args.stickerPeerId) { - mediaSignal = context.engine.data.get(TelegramEngine.EngineData.Item.Messages.Message(id: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: args.stickerMessageId))) - |> map { message -> (TelegramMediaFile, FileMediaReference)? in - if let message = message { - for media in message.media { - if let media = media as? TelegramMediaFile { - return (media, .message(message: MessageReference(message._asMessage()), media: media)) - } - } - } - return nil - } - } - var size: CGSize = args.size - if let mediaSignal = mediaSignal { - return mediaSignal - |> mapToSignal { mediaAndFileReference -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> in - if let (media, fileReference) = mediaAndFileReference { - if let dimensions = media.dimensions { - size = dimensions.cgSize - } - self.disposable.add(freeMediaFileInteractiveFetched(account: context.account, userLocation: .other, fileReference: fileReference).start()) - return chatMessageSticker(account: context.account, userLocation: .other, file: media, small: false, fetched: true, onlyFullSize: true) - } - return .complete() - } - |> map{ f -> UIImage? in - let context = f(TransformImageArguments(corners: ImageCorners(), imageSize: size.fitted(args.size), boundingSize: args.size, intrinsicInsets: UIEdgeInsets(), emptyColor: args.notification ? UIColor(rgb: 0xe5e5ea) : .black, scale: 2.0)) - return context?.generateImage() - } - } - } - return .complete() - }) - - let disposable = signal.start(next: { image in - if let image = image, let imageData = image.jpegData(compressionQuality: 0.2) { - sendData(manager: manager, data: imageData, key: key, ext: ".jpg", type: TGBridgeIncomingFileTypeImage, forceAsData: args.notification) - } - subscriber.putNext(key) - }, completed: { - subscriber.putCompletion() - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } else if let args = subscription as? TGBridgeMediaThumbnailSubscription { - let key = "\(args.peerId)_\(args.messageId)" - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal in - if let context = context, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - var roundVideo = false - return context.engine.data.get(TelegramEngine.EngineData.Item.Messages.Message(id: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: args.messageId))) - |> mapToSignal { message -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> in - if let message = message, !message._asMessage().containsSecretMedia { - var imageSignal: Signal<(TransformImageArguments) -> DrawingContext?, NoError>? - var updatedMediaReference: AnyMediaReference? - var candidateMediaReference: AnyMediaReference? - var imageDimensions: CGSize? - for media in message.media { - if let image = media as? TelegramMediaImage, let resource = largestImageRepresentation(image.representations)?.resource { - self.disposable.add(messageMediaImageInteractiveFetched(context: context, message: message._asMessage(), image: image, resource: resource, storeToDownloadsPeerId: nil).start()) - candidateMediaReference = .message(message: MessageReference(message._asMessage()), media: media) - break - } else if let _ = media as? TelegramMediaFile { - candidateMediaReference = .message(message: MessageReference(message._asMessage()), media: media) - break - } else if let webPage = media as? TelegramMediaWebpage, case let .Loaded(content) = webPage.content, let image = content.image, let resource = largestImageRepresentation(image.representations)?.resource { - self.disposable.add(messageMediaImageInteractiveFetched(context: context, message: message._asMessage(), image: image, resource: resource, storeToDownloadsPeerId: nil).start()) - candidateMediaReference = .webPage(webPage: WebpageReference(webPage), media: image) - break - } - } - if let imageReference = candidateMediaReference?.concrete(TelegramMediaImage.self) { - updatedMediaReference = imageReference.abstract - if let representation = largestRepresentationForPhoto(imageReference.media) { - imageDimensions = representation.dimensions.cgSize - } - } else if let fileReference = candidateMediaReference?.concrete(TelegramMediaFile.self) { - updatedMediaReference = fileReference.abstract - if let representation = largestImageRepresentation(fileReference.media.previewRepresentations), !fileReference.media.isSticker { - imageDimensions = representation.dimensions.cgSize - } - } - if let updatedMediaReference = updatedMediaReference, imageDimensions != nil { - if let imageReference = updatedMediaReference.concrete(TelegramMediaImage.self) { - imageSignal = chatMessagePhotoThumbnail(account: context.account, userLocation: .other, photoReference: imageReference, onlyFullSize: true) - } else if let fileReference = updatedMediaReference.concrete(TelegramMediaFile.self) { - if fileReference.media.isVideo { - imageSignal = chatMessageVideoThumbnail(account: context.account, userLocation: .other, fileReference: fileReference) - roundVideo = fileReference.media.isInstantVideo - } else if let iconImageRepresentation = smallestImageRepresentation(fileReference.media.previewRepresentations) { - imageSignal = chatWebpageSnippetFile(account: context.account, userLocation: .other, mediaReference: fileReference.abstract, representation: iconImageRepresentation) - } - } - } - if let signal = imageSignal { - return signal - } - } - return .complete() - } |> map{ f -> UIImage? in - var insets = UIEdgeInsets() - if roundVideo { - insets = UIEdgeInsets(top: -2, left: -2, bottom: -2, right: -2) - } - let context = f(TransformImageArguments(corners: ImageCorners(), imageSize: args.size, boundingSize: args.size, intrinsicInsets: insets, scale: 2.0)) - return context?.generateImage() - } - } else { - return .complete() - } - }) - - let disposable = signal.start(next: { image in - if let image = image, let imageData = image.jpegData(compressionQuality: 0.5) { - sendData(manager: manager, data: imageData, key: key, ext: ".jpg", type: TGBridgeIncomingFileTypeImage, forceAsData: args.notification) - } - subscriber.putNext(key) - }, completed: { - subscriber.putCompletion() - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } - return SSignal.fail(nil) - } -} - -final class WatchStickersHandler: WatchRequestHandler { - static var handledSubscriptions: [Any] { - return [TGBridgeRecentStickersSubscription.self] - } - - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal { - if let args = subscription as? TGBridgeRecentStickersSubscription { - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal in - if let context = context { - return context.account.postbox.itemCollectionsView(orderedItemListCollectionIds: [Namespaces.OrderedItemList.CloudSavedStickers, Namespaces.OrderedItemList.CloudRecentStickers], namespaces: [Namespaces.ItemCollection.CloudStickerPacks], aroundIndex: nil, count: 50) |> take(1) - } else { - return .complete() - } - }) - let disposable = signal.start(next: { view in - var stickers: [TGBridgeDocumentMediaAttachment] = [] - var added: Set = [] - outer: for view in view.orderedItemListsViews { - for entry in view.items { - if let file = entry.contents.get(SavedStickerItem.self)?.file { - if let sticker = makeBridgeDocument(file._parse()), !added.contains(sticker.documentId) { - stickers.append(sticker) - added.insert(sticker.documentId) - } - } else if let file = entry.contents.get(RecentMediaItem.self)?.media { - if let sticker = makeBridgeDocument(file._parse()), !added.contains(sticker.documentId) { - stickers.append(sticker) - added.insert(sticker.documentId) - } - } - if stickers.count == args.limit { - break outer - } - } - } - subscriber.putNext(stickers) - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } - return SSignal.fail(nil) - } -} - -final class WatchAudioHandler: WatchRequestHandler { - static var handledSubscriptions: [Any] { - return [ - TGBridgeAudioSubscription.self, - TGBridgeAudioSentSubscription.self - ] - } - - static private let disposable = DisposableSet() - - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal { - if let args = subscription as? TGBridgeAudioSubscription { - let key = "audio_\(args.peerId)_\(args.messageId)" - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal in - if let context = context, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - return context.engine.data.get(TelegramEngine.EngineData.Item.Messages.Message(id: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: args.messageId))) - |> mapToSignal { message -> Signal in - if let message = message { - for media in message.media { - if let file = media as? TelegramMediaFile { - self.disposable.add(messageMediaFileInteractiveFetched(context: context, message: message._asMessage(), file: file, userInitiated: true).start()) - return context.account.postbox.mediaBox.resourceData(file.resource) - |> mapToSignal({ data -> Signal in - if let tempPath = manager.watchTemporaryStorePath, data.complete { - let outputPath = tempPath + "/\(key).m4a" - return legacyDecodeOpusAudio(path: data.path, outputPath: outputPath) - } else { - return .complete() - } - }) - } - } - } - return .complete() - } - } else { - return .complete() - } - }) - - let disposable = signal.start(next: { path in - let _ = manager.sendFile(url: URL(fileURLWithPath: path), metadata: [TGBridgeIncomingFileTypeKey: TGBridgeIncomingFileTypeAudio, TGBridgeIncomingFileIdentifierKey: key]).start() - subscriber.putNext(key) - }, completed: { - subscriber.putCompletion() - }) - - return SBlockDisposable { - disposable.dispose() - } - } - //let outputPath = manager.watchTemporaryStorePath + "/\(key).opus" - } else if let _ = subscription as? TGBridgeAudioSentSubscription { - - } - return SSignal.fail(nil) - } - - static func handleFile(path: String, metadata: Dictionary, manager: WatchCommunicationManager) -> Signal { - let randomId = metadata[TGBridgeIncomingFileRandomIdKey] as? Int64 - let peerId = metadata[TGBridgeIncomingFilePeerIdKey] as? Int64 - let replyToMid = metadata[TGBridgeIncomingFileReplyToMidKey] as? Int32 - - if let randomId = randomId, let id = peerId, let peerId = makePeerIdFromBridgeIdentifier(id) { - return combineLatest(manager.accountContext.get() |> take(1), legacyEncodeOpusAudio(path: path)) - |> map({ context, pathAndDuration -> Void in - let (path, duration) = pathAndDuration - if let context = context, let path = path, let data = try? Data(contentsOf: URL(fileURLWithPath: path)) { - let resource = LocalFileMediaResource(fileId: randomId) - context.account.postbox.mediaBox.storeResourceData(resource.id, data: data) - - var replyMessageId: MessageId? = nil - if let replyToMid = replyToMid, replyToMid != 0 { - replyMessageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: replyToMid) - } - - let _ = enqueueMessages(account: context.account, peerId: peerId, messages: [.message(text: "", attributes: [], inlineStickers: [:], mediaReference: .standalone(media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: randomId), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: Int64(data.count), attributes: [.Audio(isVoice: true, duration: Int(duration), title: nil, performer: nil, waveform: nil)], alternativeRepresentations: [])), threadId: nil, replyToMessageId: replyMessageId.flatMap { EngineMessageReplySubject(messageId: $0, quote: nil) }, replyToStoryId: nil, localGroupingKey: nil, correlationId: nil, bubbleUpEmojiOrStickersets: [])]).start() - } - }) - } else { - return .complete() - } - } -} - -final class WatchLocationHandler: WatchRequestHandler { - static var handledSubscriptions: [Any] { - return [TGBridgeNearbyVenuesSubscription.self] - } - - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal { - if let args = subscription as? TGBridgeNearbyVenuesSubscription { - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal<[ChatContextResultMessage], NoError> in - if let context = context { - return context.engine.peers.resolvePeerByName(name: "foursquare", referrer: nil) - |> mapToSignal { result -> Signal in - guard case let .result(result) = result else { - return .complete() - } - return .single(result) - } - |> take(1) - |> mapToSignal { peer -> Signal in - guard let peer = peer?._asPeer() else { - return .single(nil) - } - return context.engine.messages.requestChatContextResults(botId: peer.id, peerId: context.account.peerId, query: "", location: .single((args.coordinate.latitude, args.coordinate.longitude)), offset: "") - |> map { results -> ChatContextResultCollection? in - return results?.results - } - |> `catch` { error -> Signal in - return .single(nil) - } - } - |> mapToSignal { contextResult -> Signal<[ChatContextResultMessage], NoError> in - guard let contextResult = contextResult else { - return .single([]) - } - return .single(contextResult.results.map { $0.message }) - } - } else { - return .complete() - } - }) - - let disposable = signal.start(next: { results in - var venues: [TGBridgeLocationVenue] = [] - for result in results { - if let venue = makeBridgeLocationVenue(result) { - venues.append(venue) - } - } - subscriber.putNext(venues) - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } - return SSignal.fail(nil) - } -} - -final class WatchPeerSettingsHandler: WatchRequestHandler { - static var handledSubscriptions: [Any] { - return [ - TGBridgePeerSettingsSubscription.self, - TGBridgePeerUpdateNotificationSettingsSubscription.self, - TGBridgePeerUpdateBlockStatusSubscription.self - ] - } - - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal { - if let args = subscription as? TGBridgePeerSettingsSubscription { - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal in - if let context = context, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - return context.account.viewTracker.peerView(peerId) - } else { - return .complete() - } - }) - let disposable = signal.start(next: { view in - var muted = false - var blocked = false - - if let notificationSettings = view.notificationSettings as? TelegramPeerNotificationSettings, case let .muted(until) = notificationSettings.muteState, until >= Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) { - muted = true - } - if let cachedData = view.cachedData as? CachedUserData { - blocked = cachedData.isBlocked - } - - subscriber.putNext([ "muted": muted, "blocked": blocked ]) - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } else { - return SSignal { subscriber in - let signal = manager.accountContext.get() - |> take(1) - |> mapToSignal({ context -> Signal in - if let context = context { - var signal: Signal? - - if let args = subscription as? TGBridgePeerUpdateNotificationSettingsSubscription, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - signal = context.engine.peers.togglePeerMuted(peerId: peerId, threadId: nil) - } else if let args = subscription as? TGBridgePeerUpdateBlockStatusSubscription, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - signal = context.engine.privacy.requestUpdatePeerIsBlocked(peerId: peerId, isBlocked: args.blocked) - } - - if let signal = signal { - return signal |> mapToSignal({ _ in - return .single(true) - }) - } else { - return .complete() - } - } else { - return .complete() - } - }) - - let disposable = signal.start(next: { _ in - subscriber.putNext(true) - }, completed: { - subscriber.putCompletion() - }) - - return SBlockDisposable { - disposable.dispose() - } - } - } - } -} - -final class WatchContinuationHandler: WatchRequestHandler { - static var handledSubscriptions: [Any] { - return [TGBridgeRemoteSubscription.self] - } - - static func handle(subscription: TGBridgeSubscription, manager: WatchCommunicationManager) -> SSignal { - if let args = subscription as? TGBridgeRemoteSubscription, let peerId = makePeerIdFromBridgeIdentifier(args.peerId) { - manager.requestNavigateToMessage(messageId: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: args.messageId)) - } - return SSignal.fail(nil) - } -} diff --git a/submodules/WatchBridgeAudio/BUILD b/submodules/WatchBridgeAudio/BUILD deleted file mode 100644 index e3994dc62d..0000000000 --- a/submodules/WatchBridgeAudio/BUILD +++ /dev/null @@ -1,19 +0,0 @@ -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") - -swift_library( - name = "WatchBridgeAudio", - module_name = "WatchBridgeAudio", - srcs = glob([ - "Sources/**/*.swift", - ]), - copts = [ - "-warnings-as-errors", - ], - deps = [ - "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit", - "//submodules/WatchBridgeAudio/Impl:WatchBridgeAudioImpl", - ], - visibility = [ - "//visibility:public", - ], -) diff --git a/submodules/WatchBridgeAudio/Impl/BUILD b/submodules/WatchBridgeAudio/Impl/BUILD deleted file mode 100644 index b1290acaa1..0000000000 --- a/submodules/WatchBridgeAudio/Impl/BUILD +++ /dev/null @@ -1,27 +0,0 @@ - -objc_library( - name = "WatchBridgeAudioImpl", - enable_modules = True, - module_name = "WatchBridgeAudioImpl", - srcs = glob([ - "Sources/**/*.m", - "Sources/**/*.mm", - "Sources/**/*.h", - ], allow_empty=True), - hdrs = glob([ - "PublicHeaders/**/*.h", - ]), - includes = [ - "PublicHeaders", - ], - deps = [ - "//submodules/SSignalKit/SSignalKit:SSignalKit", - "//submodules/OpusBinding:OpusBinding", - ], - sdk_frameworks = [ - "Foundation", - ], - visibility = [ - "//visibility:public", - ], -) diff --git a/submodules/WatchBridgeAudio/Impl/PublicHeaders/WatchBridgeAudioImpl/TGBridgeAudioDecoder.h b/submodules/WatchBridgeAudio/Impl/PublicHeaders/WatchBridgeAudioImpl/TGBridgeAudioDecoder.h deleted file mode 100644 index 9332bf611b..0000000000 --- a/submodules/WatchBridgeAudio/Impl/PublicHeaders/WatchBridgeAudioImpl/TGBridgeAudioDecoder.h +++ /dev/null @@ -1,8 +0,0 @@ -#import - -@interface TGBridgeAudioDecoder : NSObject - -- (instancetype)initWithURL:(NSURL *)url outputUrl:(NSURL *)outputURL; -- (void)startWithCompletion:(void (^)(void))completion; - -@end diff --git a/submodules/WatchBridgeAudio/Impl/PublicHeaders/WatchBridgeAudioImpl/TGBridgeAudioEncoder.h b/submodules/WatchBridgeAudio/Impl/PublicHeaders/WatchBridgeAudioImpl/TGBridgeAudioEncoder.h deleted file mode 100644 index 7c186daff4..0000000000 --- a/submodules/WatchBridgeAudio/Impl/PublicHeaders/WatchBridgeAudioImpl/TGBridgeAudioEncoder.h +++ /dev/null @@ -1,8 +0,0 @@ -#import - -@interface TGBridgeAudioEncoder : NSObject - -- (instancetype)initWithURL:(NSURL *)url; -- (void)startWithCompletion:(void (^)(NSString *, int32_t))completion; - -@end diff --git a/submodules/WatchBridgeAudio/Impl/PublicHeaders/WatchBridgeAudioImpl/WatchBridgeAudioImpl.h b/submodules/WatchBridgeAudio/Impl/PublicHeaders/WatchBridgeAudioImpl/WatchBridgeAudioImpl.h deleted file mode 100644 index 03950d978a..0000000000 --- a/submodules/WatchBridgeAudio/Impl/PublicHeaders/WatchBridgeAudioImpl/WatchBridgeAudioImpl.h +++ /dev/null @@ -1,6 +0,0 @@ -#import - -#import -#import - - diff --git a/submodules/WatchBridgeAudio/Impl/Sources/TGBridgeAudioDecoder.mm b/submodules/WatchBridgeAudio/Impl/Sources/TGBridgeAudioDecoder.mm deleted file mode 100644 index c1d30b80f1..0000000000 --- a/submodules/WatchBridgeAudio/Impl/Sources/TGBridgeAudioDecoder.mm +++ /dev/null @@ -1,197 +0,0 @@ -#import - -#import -#import - -#import - -#import - -const NSInteger TGBridgeAudioDecoderInputSampleRate = 48000; -const NSInteger TGBridgeAudioDecoderResultSampleRate = 24000; -const NSUInteger TGBridgeAudioDecoderBufferSize = 32768; - -#define checkResult(result,operation) (_checkResultLite((result),(operation),__FILE__,__LINE__)) - -struct TGAudioBuffer -{ - NSUInteger capacity; - uint8_t *data; - NSUInteger size; - int64_t pcmOffset; -}; - -inline TGAudioBuffer *TGAudioBufferWithCapacity(NSUInteger capacity) -{ - TGAudioBuffer *audioBuffer = (TGAudioBuffer *)malloc(sizeof(TGAudioBuffer)); - audioBuffer->capacity = capacity; - audioBuffer->data = (uint8_t *)malloc(capacity); - audioBuffer->size = 0; - audioBuffer->pcmOffset = 0; - return audioBuffer; -} - -inline void TGAudioBufferDispose(TGAudioBuffer *audioBuffer) -{ - if (audioBuffer != NULL) - { - free(audioBuffer->data); - free(audioBuffer); - } -} - -static inline bool _checkResultLite(OSStatus result, const char *operation, const char* file, int line) -{ - if ( result != noErr ) - { - NSLog(@"%s:%d: %s result %d %08X %4.4s\n", file, line, operation, (int)result, (int)result, (char*)&result); - return NO; - } - return YES; -} - -@interface TGBridgeAudioDecoder () -{ - NSURL *_url; - NSURL *_resultURL; - - OggOpusReader *_opusReader; - - bool _finished; - bool _cancelled; -} -@end - -@implementation TGBridgeAudioDecoder - -- (instancetype)initWithURL:(NSURL *)url outputUrl:(NSURL *)outputUrl -{ - self = [super init]; - if (self != nil) - { - _url = url; - - int64_t randomId = 0; - arc4random_buf(&randomId, 8); - _resultURL = outputUrl; - } - return self; -} - -- (void)startWithCompletion:(void (^)(void))completion -{ - [[TGBridgeAudioDecoder processingQueue] dispatch:^ - { - _opusReader = [[OggOpusReader alloc] initWithPath:_url.path]; - if (_opusReader == NULL) { - return; - } - - AudioStreamBasicDescription sourceFormat; - sourceFormat.mSampleRate = TGBridgeAudioDecoderInputSampleRate; - sourceFormat.mFormatID = kAudioFormatLinearPCM; - sourceFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; - sourceFormat.mFramesPerPacket = 1; - sourceFormat.mChannelsPerFrame = 1; - sourceFormat.mBitsPerChannel = 16; - sourceFormat.mBytesPerPacket = 2; - sourceFormat.mBytesPerFrame = 2; - - AudioStreamBasicDescription destFormat; - memset(&destFormat, 0, sizeof(destFormat)); - destFormat.mChannelsPerFrame = sourceFormat.mChannelsPerFrame; - destFormat.mFormatID = kAudioFormatMPEG4AAC; - destFormat.mSampleRate = TGBridgeAudioDecoderResultSampleRate; - UInt32 size = sizeof(destFormat); - if (!checkResult(AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, &size, &destFormat), - "AudioFormatGetProperty(kAudioFormatProperty_FormatInfo)")) - { - return; - } - - ExtAudioFileRef destinationFile; - if (!checkResult(ExtAudioFileCreateWithURL((__bridge CFURLRef)_resultURL, kAudioFileM4AType, &destFormat, NULL, kAudioFileFlags_EraseFile, &destinationFile), "ExtAudioFileCreateWithURL")) - { - return; - } - - if (!checkResult(ExtAudioFileSetProperty(destinationFile, kExtAudioFileProperty_ClientDataFormat, size, &sourceFormat), - "ExtAudioFileSetProperty(destinationFile, kExtAudioFileProperty_ClientDataFormat")) - { - return; - } - - bool canResumeAfterInterruption = false; - AudioConverterRef converter; - size = sizeof(converter); - if (checkResult(ExtAudioFileGetProperty(destinationFile, kExtAudioFileProperty_AudioConverter, &size, &converter), - "ExtAudioFileGetProperty(kExtAudioFileProperty_AudioConverter;)")) - { - UInt32 canResume = 0; - size = sizeof(canResume); - if (AudioConverterGetProperty(converter, kAudioConverterPropertyCanResumeFromInterruption, &size, &canResume) == noErr) - canResumeAfterInterruption = canResume; - } - - uint8_t srcBuffer[TGBridgeAudioDecoderBufferSize]; - while (!_cancelled) - { - AudioBufferList bufferList; - bufferList.mNumberBuffers = 1; - bufferList.mBuffers[0].mNumberChannels = sourceFormat.mChannelsPerFrame; - bufferList.mBuffers[0].mDataByteSize = TGBridgeAudioDecoderBufferSize; - bufferList.mBuffers[0].mData = srcBuffer; - - uint32_t writtenOutputBytes = 0; - while (writtenOutputBytes < TGBridgeAudioDecoderBufferSize) - { - int32_t readSamples = [_opusReader read:(uint16_t *)(srcBuffer + writtenOutputBytes) bufSize:(TGBridgeAudioDecoderBufferSize - writtenOutputBytes) / sourceFormat.mBytesPerFrame]; - - if (readSamples > 0) - writtenOutputBytes += readSamples * sourceFormat.mBytesPerFrame; - else - break; - } - bufferList.mBuffers[0].mDataByteSize = writtenOutputBytes; - int32_t nFrames = writtenOutputBytes / sourceFormat.mBytesPerFrame; - - if (nFrames == 0) - break; - - OSStatus status = ExtAudioFileWrite(destinationFile, nFrames, &bufferList); - if (status == kExtAudioFileError_CodecUnavailableInputConsumed) - { - //TGLog(@"1"); - } - else if (status == kExtAudioFileError_CodecUnavailableInputNotConsumed) - { - //TGLog(@"2"); - } - else if (!checkResult(status, "ExtAudioFileWrite")) - { - //TGLog(@"3"); - } - } - - ExtAudioFileDispose(destinationFile); - - if (completion != nil) - completion(); - }]; -} - -+ (SQueue *)processingQueue -{ - static SQueue *queue = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^ - { - static const char *queueSpecific = "org.telegram.opusAudioDecoderQueue"; - dispatch_queue_t dispatchQueue = dispatch_queue_create("org.telegram.opusAudioDecoderQueue", DISPATCH_QUEUE_SERIAL); - dispatch_queue_set_specific(dispatchQueue, queueSpecific, (void *)queueSpecific, NULL); - queue = [SQueue wrapConcurrentNativeQueue:dispatchQueue]; - }); - return queue; -} - -@end diff --git a/submodules/WatchBridgeAudio/Impl/Sources/TGBridgeAudioEncoder.m b/submodules/WatchBridgeAudio/Impl/Sources/TGBridgeAudioEncoder.m deleted file mode 100644 index 2bf80914d3..0000000000 --- a/submodules/WatchBridgeAudio/Impl/Sources/TGBridgeAudioEncoder.m +++ /dev/null @@ -1,564 +0,0 @@ -#import -#import - -#import - -static const char *AMQueueSpecific = "AMQueueSpecific"; - -const NSInteger TGBridgeAudioEncoderSampleRate = 48000; - -typedef enum { - ATQueuePriorityLow, - ATQueuePriorityDefault, - ATQueuePriorityHigh -} ATQueuePriority; - -@interface ATQueue : NSObject - -+ (ATQueue *)mainQueue; -+ (ATQueue *)concurrentDefaultQueue; -+ (ATQueue *)concurrentBackgroundQueue; - -- (instancetype)init; -- (instancetype)initWithName:(NSString *)name; -- (instancetype)initWithPriority:(ATQueuePriority)priority; - -- (void)dispatch:(dispatch_block_t)block; -- (void)dispatch:(dispatch_block_t)block synchronous:(bool)synchronous; -- (void)dispatchAfter:(NSTimeInterval)seconds block:(dispatch_block_t)block; - -- (dispatch_queue_t)nativeQueue; - -@end - -@interface TGFileDataItem : TGDataItem - -- (instancetype)initWithTempFile; - -- (void)appendData:(NSData *)data; -- (NSData *)readDataAtOffset:(NSUInteger)offset length:(NSUInteger)length; -- (NSUInteger)length; - -- (NSString *)path; - -@end - -@interface TGBridgeAudioEncoder () -{ - AVAssetReader *_assetReader; - AVAssetReaderOutput *_readerOutput; - - NSMutableData *_audioBuffer; - TGFileDataItem *_tempFileItem; - TGOggOpusWriter *_oggWriter; - - int _tailLength; -} -@end - -@implementation TGBridgeAudioEncoder - -- (instancetype)initWithURL:(NSURL *)url -{ - self = [super init]; - if (self != nil) - { - AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil]; - if (asset == nil || asset.tracks.count == 0) - { - return nil; - } - - NSError *error; - _assetReader = [[AVAssetReader alloc] initWithAsset:asset error:&error]; - - NSDictionary *outputSettings = @ - { - AVFormatIDKey: @(kAudioFormatLinearPCM), - AVSampleRateKey: @(TGBridgeAudioEncoderSampleRate), - AVNumberOfChannelsKey: @1, - AVLinearPCMBitDepthKey: @16, - AVLinearPCMIsFloatKey: @false, - AVLinearPCMIsBigEndianKey: @false, - AVLinearPCMIsNonInterleaved: @false - }; - - _readerOutput = [AVAssetReaderAudioMixOutput assetReaderAudioMixOutputWithAudioTracks:asset.tracks audioSettings:outputSettings]; - - [_assetReader addOutput:_readerOutput]; - - _tempFileItem = [[TGFileDataItem alloc] initWithTempFile]; - } - return self; -} - -- (void)dealloc -{ - [self cleanup]; -} - -- (void)cleanup -{ - _oggWriter = nil; -} - -+ (ATQueue *)processingQueue -{ - static ATQueue *queue = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^ - { - queue = [[ATQueue alloc] initWithName:@"org.telegram.opusAudioEncoderQueue"]; - }); - - return queue; -} - -static const int encoderPacketSizeInBytes = 16000 / 1000 * 60 * 2; - -- (void)startWithCompletion:(void (^)(NSString *, int32_t))completion -{ - [[TGBridgeAudioEncoder processingQueue] dispatch:^ - { - _oggWriter = [[TGOggOpusWriter alloc] init]; - if (![_oggWriter beginWithDataItem:_tempFileItem]) - { - [self cleanup]; - return; - } - - [_assetReader startReading]; - - while (_assetReader.status != AVAssetReaderStatusCompleted) - { - if (_assetReader.status == AVAssetReaderStatusReading) - { - CMSampleBufferRef nextBuffer = [_readerOutput copyNextSampleBuffer]; - if (nextBuffer) - { - AudioBufferList abl; - CMBlockBufferRef blockBuffer; - CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(nextBuffer, NULL, &abl, sizeof(abl), NULL, NULL, kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, &blockBuffer); - - [[TGBridgeAudioEncoder processingQueue] dispatch:^ - { - [self _processBuffer:&abl.mBuffers[0]]; - - CFRelease(nextBuffer); - CFRelease(blockBuffer); - }]; - } - else - { - [[TGBridgeAudioEncoder processingQueue] dispatch:^ - { - if (_tailLength > 0) { - [_oggWriter writeFrame:(uint8_t *)_audioBuffer.bytes frameByteCount:(NSUInteger)_tailLength]; - } - }]; - break; - } - } - } - - [[TGBridgeAudioEncoder processingQueue] dispatch:^ - { - TGFileDataItem *dataItemResult = nil; - NSTimeInterval durationResult = 0.0; - - NSUInteger totalBytes = 0; - - if (_assetReader.status == AVAssetReaderStatusCompleted) - { - NSLog(@"finished"); - if (_oggWriter != nil && [_oggWriter writeFrame:NULL frameByteCount:0]) - { - dataItemResult = _tempFileItem; - durationResult = [_oggWriter encodedDuration]; - totalBytes = [_oggWriter encodedBytes]; - } - - [self cleanup]; - } - - //TGLog(@"[TGBridgeAudioEncoder#%x convert time: %f ms]", self, (CFAbsoluteTimeGetCurrent() - startTime) * 1000.0); - - if (completion != nil) - completion(dataItemResult.path, (int32_t)durationResult); - }]; - }]; -} - -- (void)_processBuffer:(AudioBuffer const *)buffer -{ - @autoreleasepool - { - if (_oggWriter == nil) - return; - - unsigned char currentEncoderPacket[encoderPacketSizeInBytes]; - - int bufferOffset = 0; - - while (true) - { - int currentEncoderPacketSize = 0; - - while (currentEncoderPacketSize < encoderPacketSizeInBytes) - { - if (_audioBuffer.length != 0) - { - int takenBytes = MIN((int)_audioBuffer.length, encoderPacketSizeInBytes - currentEncoderPacketSize); - if (takenBytes != 0) - { - memcpy(currentEncoderPacket + currentEncoderPacketSize, _audioBuffer.bytes, takenBytes); - [_audioBuffer replaceBytesInRange:NSMakeRange(0, takenBytes) withBytes:NULL length:0]; - currentEncoderPacketSize += takenBytes; - } - } - else if (bufferOffset < (int)buffer->mDataByteSize) - { - int takenBytes = MIN((int)buffer->mDataByteSize - bufferOffset, encoderPacketSizeInBytes - currentEncoderPacketSize); - if (takenBytes != 0) - { - memcpy(currentEncoderPacket + currentEncoderPacketSize, ((const char *)buffer->mData) + bufferOffset, takenBytes); - bufferOffset += takenBytes; - currentEncoderPacketSize += takenBytes; - } - } - else { - break; - } - } - _tailLength = currentEncoderPacketSize; - if (currentEncoderPacketSize < encoderPacketSizeInBytes) - { - if (_audioBuffer == nil) - _audioBuffer = [[NSMutableData alloc] initWithCapacity:encoderPacketSizeInBytes]; - [_audioBuffer appendBytes:currentEncoderPacket length:currentEncoderPacketSize]; - break; - } - else - { - [_oggWriter writeFrame:currentEncoderPacket frameByteCount:(NSUInteger)currentEncoderPacketSize]; - _tailLength = 0; - } - } - } -} - -@end - -@interface TGFileDataItem () -{ - NSUInteger _length; - - NSString *_fileName; - bool _fileExists; - - NSMutableData *_data; -} - -@end - -@implementation TGFileDataItem -{ - ATQueue *_queue; -} - -- (void)_commonInit -{ - _queue = [[ATQueue alloc] initWithPriority:ATQueuePriorityLow]; - _data = [[NSMutableData alloc] init]; -} - -- (instancetype)initWithTempFile -{ - self = [super init]; - if (self != nil) - { - [self _commonInit]; - - [_queue dispatch:^ - { - int64_t randomId = 0; - arc4random_buf(&randomId, 8); - _fileName = [NSTemporaryDirectory() stringByAppendingPathComponent:[[NSString alloc] initWithFormat:@"%" PRIx64 "", randomId]]; - _fileExists = false; - }]; - } - return self; -} - -- (instancetype)initWithFilePath:(NSString *)filePath -{ - self = [super init]; - if (self != nil) - { - [self _commonInit]; - - - [_queue dispatch:^ - { - _fileName = filePath; - _length = [[[NSFileManager defaultManager] attributesOfItemAtPath:_fileName error:nil][NSFileSize] unsignedIntegerValue]; - _fileExists = [[NSFileManager defaultManager] fileExistsAtPath:_fileName]; - }]; - } - return self; -} - -- (void)noop -{ -} - -- (void)moveToPath:(NSString *)path -{ - [_queue dispatch:^ - { - [[NSFileManager defaultManager] moveItemAtPath:_fileName toPath:path error:nil]; - _fileName = path; - }]; -} - -- (void)remove -{ - [_queue dispatch:^ - { - [[NSFileManager defaultManager] removeItemAtPath:_fileName error:nil]; - }]; -} - -- (void)appendData:(NSData *)data -{ - [_queue dispatch:^ - { - if (!_fileExists) - { - [[NSFileManager defaultManager] createFileAtPath:_fileName contents:nil attributes:nil]; - _fileExists = true; - } - NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath:_fileName]; - [file seekToEndOfFile]; - [file writeData:data]; - [file synchronizeFile]; - [file closeFile]; - _length += data.length; - - [_data appendData:data]; - }]; -} - -- (NSData *)readDataAtOffset:(NSUInteger)offset length:(NSUInteger)length -{ - __block NSData *data = nil; - - [_queue dispatch:^ - { - NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath:_fileName]; - [file seekToFileOffset:(unsigned long long)offset]; - data = [file readDataOfLength:length]; - if (data.length != length) - //TGLog(@"Read data length mismatch"); - [file closeFile]; - } synchronous:true]; - - return data; -} - -- (NSUInteger)length -{ - __block NSUInteger result = 0; - [_queue dispatch:^ - { - result = _length; - } synchronous:true]; - - return result; -} - -- (NSString *)path { - return _fileName; -} - -@end - - -@interface ATQueue () -{ - dispatch_queue_t _nativeQueue; - bool _isMainQueue; - - int32_t _noop; -} - -@end - -@implementation ATQueue - -+ (NSString *)applicationPrefix -{ - static NSString *prefix = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^ - { - prefix = [[NSBundle mainBundle] bundleIdentifier]; - }); - - return prefix; -} - -+ (ATQueue *)mainQueue -{ - static ATQueue *queue = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^ - { - queue = [[ATQueue alloc] init]; - queue->_nativeQueue = dispatch_get_main_queue(); - queue->_isMainQueue = true; - }); - - return queue; -} - -+ (ATQueue *)concurrentDefaultQueue -{ - static ATQueue *queue = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^ - { - queue = [[ATQueue alloc] initWithNativeQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; - }); - - return queue; -} - -+ (ATQueue *)concurrentBackgroundQueue -{ - static ATQueue *queue = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^ - { - queue = [[ATQueue alloc] initWithNativeQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)]; - }); - - return queue; -} - -- (instancetype)init -{ - return [self initWithName:[[ATQueue applicationPrefix] stringByAppendingFormat:@".%ld", lrand48()]]; -} - -- (instancetype)initWithName:(NSString *)name -{ - self = [super init]; - if (self != nil) - { - _nativeQueue = dispatch_queue_create([name UTF8String], DISPATCH_QUEUE_SERIAL); - dispatch_queue_set_specific(_nativeQueue, AMQueueSpecific, (__bridge void *)self, NULL); - } - return self; -} - -- (instancetype)initWithPriority:(ATQueuePriority)priority -{ - self = [super init]; - if (self != nil) - { - _nativeQueue = dispatch_queue_create([[[ATQueue applicationPrefix] stringByAppendingFormat:@".%ld", lrand48()] UTF8String], DISPATCH_QUEUE_SERIAL); - long targetQueueIdentifier = DISPATCH_QUEUE_PRIORITY_DEFAULT; - switch (priority) - { - case ATQueuePriorityLow: - targetQueueIdentifier = DISPATCH_QUEUE_PRIORITY_LOW; - break; - case ATQueuePriorityDefault: - targetQueueIdentifier = DISPATCH_QUEUE_PRIORITY_DEFAULT; - break; - case ATQueuePriorityHigh: - targetQueueIdentifier = DISPATCH_QUEUE_PRIORITY_HIGH; - break; - } - dispatch_set_target_queue(_nativeQueue, dispatch_get_global_queue(targetQueueIdentifier, 0)); - dispatch_queue_set_specific(_nativeQueue, AMQueueSpecific, (__bridge void *)self, NULL); - } - return self; -} - -- (instancetype)initWithNativeQueue:(dispatch_queue_t)queue -{ - self = [super init]; - if (self != nil) - { -#if !OS_OBJECT_USE_OBJC - _nativeQueue = dispatch_retain(queue); -#else - _nativeQueue = queue; -#endif - } - return self; -} - -- (void)dealloc -{ - if (_nativeQueue != nil) - { -#if !OS_OBJECT_USE_OBJC - dispatch_release(_nativeQueue); -#endif - _nativeQueue = nil; - } -} - -- (void)dispatch:(dispatch_block_t)block -{ - [self dispatch:block synchronous:false]; -} - -- (void)dispatch:(dispatch_block_t)block synchronous:(bool)synchronous -{ - __block ATQueue *strongSelf = self; - dispatch_block_t blockWithSelf = ^ - { - block(); - [strongSelf noop]; - strongSelf = nil; - }; - - if (_isMainQueue) - { - if ([NSThread isMainThread]) - blockWithSelf(); - else if (synchronous) - dispatch_sync(_nativeQueue, blockWithSelf); - else - dispatch_async(_nativeQueue, blockWithSelf); - } - else - { - if (dispatch_get_specific(AMQueueSpecific) == (__bridge void *)self) - block(); - else if (synchronous) - dispatch_sync(_nativeQueue, blockWithSelf); - else - dispatch_async(_nativeQueue, blockWithSelf); - } -} - -- (void)dispatchAfter:(NSTimeInterval)seconds block:(dispatch_block_t)block -{ - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC)), _nativeQueue, block); -} - -- (dispatch_queue_t)nativeQueue -{ - return _nativeQueue; -} - -- (void)noop -{ -} - -@end diff --git a/submodules/WatchBridgeAudio/Sources/LegacyBridgeAudio.swift b/submodules/WatchBridgeAudio/Sources/LegacyBridgeAudio.swift deleted file mode 100644 index ab80d4f2a0..0000000000 --- a/submodules/WatchBridgeAudio/Sources/LegacyBridgeAudio.swift +++ /dev/null @@ -1,25 +0,0 @@ -import Foundation -import SwiftSignalKit -import WatchBridgeAudioImpl - -public func legacyDecodeOpusAudio(path: String, outputPath: String) -> Signal { - return Signal { subscriber in - let decoder = TGBridgeAudioDecoder(url: URL(fileURLWithPath: path), outputUrl: URL(fileURLWithPath: outputPath)) - decoder?.start(completion: { - subscriber.putNext(outputPath) - subscriber.putCompletion() - }) - return EmptyDisposable - } -} - -public func legacyEncodeOpusAudio(path: String) -> Signal<(String?, Int32), NoError> { - return Signal { subscriber in - let encoder = TGBridgeAudioEncoder(url: URL(fileURLWithPath: path)) - encoder?.start(completion: { (path, duration) in - subscriber.putNext((path, duration)) - subscriber.putCompletion() - }) - return EmptyDisposable - } -} diff --git a/submodules/WatchCommon/BUILD b/submodules/WatchCommon/BUILD deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/submodules/WatchCommon/Host/BUILD b/submodules/WatchCommon/Host/BUILD deleted file mode 100644 index 043309a973..0000000000 --- a/submodules/WatchCommon/Host/BUILD +++ /dev/null @@ -1,25 +0,0 @@ - -objc_library( - name = "WatchCommon", - enable_modules = True, - module_name = "WatchCommon", - srcs = glob([ - "Sources/**/*.m", - "Sources/**/*.h", - ], allow_empty=True), - hdrs = glob([ - "PublicHeaders/**/*.h", - ]), - copts = [ - "-I{}/PublicHeaders/WatchCommon".format(package_name()), - ], - includes = [ - "PublicHeaders", - ], - sdk_frameworks = [ - "Foundation", - ], - visibility = [ - "//visibility:public", - ], -) diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeActionMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeActionMediaAttachment.h deleted file mode 100644 index bb18757fc6..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeActionMediaAttachment.h +++ /dev/null @@ -1,36 +0,0 @@ -#import - -typedef NS_ENUM(NSUInteger, TGBridgeMessageAction) { - TGBridgeMessageActionNone = 0, - TGBridgeMessageActionChatEditTitle = 1, - TGBridgeMessageActionChatAddMember = 2, - TGBridgeMessageActionChatDeleteMember = 3, - TGBridgeMessageActionCreateChat = 4, - TGBridgeMessageActionChatEditPhoto = 5, - TGBridgeMessageActionContactRequest = 6, - TGBridgeMessageActionAcceptContactRequest = 7, - TGBridgeMessageActionContactRegistered = 8, - TGBridgeMessageActionUserChangedPhoto = 9, - TGBridgeMessageActionEncryptedChatRequest = 10, - TGBridgeMessageActionEncryptedChatAccept = 11, - TGBridgeMessageActionEncryptedChatDecline = 12, - TGBridgeMessageActionEncryptedChatMessageLifetime = 13, - TGBridgeMessageActionEncryptedChatScreenshot = 14, - TGBridgeMessageActionEncryptedChatMessageScreenshot = 15, - TGBridgeMessageActionCreateBroadcastList = 16, - TGBridgeMessageActionJoinedByLink = 17, - TGBridgeMessageActionChannelCreated = 18, - TGBridgeMessageActionChannelCommentsStatusChanged = 19, - TGBridgeMessageActionChannelInviter = 20, - TGBridgeMessageActionGroupMigratedTo = 21, - TGBridgeMessageActionGroupDeactivated = 22, - TGBridgeMessageActionGroupActivated = 23, - TGBridgeMessageActionChannelMigratedFrom = 24 -}; - -@interface TGBridgeActionMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) TGBridgeMessageAction actionType; -@property (nonatomic, strong) NSDictionary *actionData; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeAudioMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeAudioMediaAttachment.h deleted file mode 100644 index ffdb864568..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeAudioMediaAttachment.h +++ /dev/null @@ -1,16 +0,0 @@ -#import - -@interface TGBridgeAudioMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t audioId; -@property (nonatomic, assign) int64_t accessHash; -@property (nonatomic, assign) int32_t datacenterId; - -@property (nonatomic, assign) int64_t localAudioId; - -@property (nonatomic, assign) int32_t duration; -@property (nonatomic, assign) int32_t fileSize; - -- (int64_t)identifier; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeBotCommandInfo.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeBotCommandInfo.h deleted file mode 100644 index fe6f72e1a0..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeBotCommandInfo.h +++ /dev/null @@ -1,12 +0,0 @@ -#import - -@interface TGBridgeBotCommandInfo : NSObject -{ - NSString *_command; - NSString *_commandDescription; -} - -@property (nonatomic, readonly) NSString *command; -@property (nonatomic, readonly) NSString *commandDescription; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeBotInfo.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeBotInfo.h deleted file mode 100644 index 0dafae5cef..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeBotInfo.h +++ /dev/null @@ -1,12 +0,0 @@ -#import - -@interface TGBridgeBotInfo : NSObject -{ - NSString *_shortDescription; - NSArray *_commandList; -} - -@property (nonatomic, readonly) NSString *shortDescription; -@property (nonatomic, readonly) NSArray *commandList; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeChat.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeChat.h deleted file mode 100644 index fa56be05f2..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeChat.h +++ /dev/null @@ -1,46 +0,0 @@ -#import -#import - -@interface TGBridgeChat : NSObject - -@property (nonatomic) int64_t identifier; -@property (nonatomic) NSTimeInterval date; -@property (nonatomic) int32_t fromUid; -@property (nonatomic, strong) NSString *text; - -@property (nonatomic, strong) NSArray *media; - -@property (nonatomic) bool outgoing; -@property (nonatomic) bool unread; -@property (nonatomic) bool deliveryError; -@property (nonatomic) TGBridgeMessageDeliveryState deliveryState; - -@property (nonatomic) int32_t unreadCount; - -@property (nonatomic) bool isBroadcast; - -@property (nonatomic, strong) NSString *groupTitle; -@property (nonatomic, strong) NSString *groupPhotoSmall; -@property (nonatomic, strong) NSString *groupPhotoBig; - -@property (nonatomic) bool isGroup; -@property (nonatomic) bool hasLeftGroup; -@property (nonatomic) bool isKickedFromGroup; - -@property (nonatomic) bool isChannel; -@property (nonatomic) bool isChannelGroup; - -@property (nonatomic, strong) NSString *userName; -@property (nonatomic, strong) NSString *about; -@property (nonatomic) bool verified; - -@property (nonatomic) int32_t participantsCount; -@property (nonatomic, strong) NSArray *participants; - -- (NSArray *)involvedUserIds; -- (NSArray *)participantsUserIds; - -@end - -extern NSString *const TGBridgeChatKey; -extern NSString *const TGBridgeChatsArrayKey; diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeChatMessages.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeChatMessages.h deleted file mode 100644 index 9c539758d4..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeChatMessages.h +++ /dev/null @@ -1,14 +0,0 @@ -#import - -@class SSignal; - -@interface TGBridgeChatMessages : NSObject -{ - NSArray *_messages; -} - -@property (nonatomic, readonly) NSArray *messages; - -@end - -extern NSString *const TGBridgeChatMessageListViewKey; diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeCommon.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeCommon.h deleted file mode 100644 index fe0510c041..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeCommon.h +++ /dev/null @@ -1,95 +0,0 @@ -#import - -extern NSString *const TGBridgeIncomingFileTypeKey; -extern NSString *const TGBridgeIncomingFileIdentifierKey; -extern NSString *const TGBridgeIncomingFileRandomIdKey; -extern NSString *const TGBridgeIncomingFilePeerIdKey; -extern NSString *const TGBridgeIncomingFileReplyToMidKey; - -extern NSString *const TGBridgeIncomingFileTypeAudio; -extern NSString *const TGBridgeIncomingFileTypeImage; - -@interface TGBridgeSubscription : NSObject - -@property (nonatomic, readonly) int64_t identifier; -@property (nonatomic, readonly, strong) NSString *name; - -@property (nonatomic, readonly) bool isOneTime; -@property (nonatomic, readonly) bool renewable; -@property (nonatomic, readonly) bool dropPreviouslyQueued; -@property (nonatomic, readonly) bool synchronous; - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder; -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder; - -+ (NSString *)subscriptionName; - -@end - - -@interface TGBridgeDisposal : NSObject - -@property (nonatomic, readonly) int64_t identifier; - -- (instancetype)initWithIdentifier:(int64_t)identifier; - -@end - - -@interface TGBridgeFile : NSObject - -@property (nonatomic, readonly, strong) NSData *data; -@property (nonatomic, readonly, strong) NSDictionary *metadata; - -- (instancetype)initWithData:(NSData *)data metadata:(NSDictionary *)metadata; - -@end - - -@interface TGBridgePing : NSObject - -@property (nonatomic, readonly) int32_t sessionId; - -- (instancetype)initWithSessionId:(int32_t)sessionId; - -@end - - -@interface TGBridgeSubscriptionListRequest : NSObject - -@property (nonatomic, readonly) int32_t sessionId; - -- (instancetype)initWithSessionId:(int32_t)sessionId; - -@end - - -@interface TGBridgeSubscriptionList : NSObject - -@property (nonatomic, readonly, strong) NSArray *subscriptions; - -- (instancetype)initWithArray:(NSArray *)array; - -@end - - -typedef NS_ENUM(int32_t, TGBridgeResponseType) { - TGBridgeResponseTypeUndefined, - TGBridgeResponseTypeNext, - TGBridgeResponseTypeFailed, - TGBridgeResponseTypeCompleted -}; - -@interface TGBridgeResponse : NSObject - -@property (nonatomic, readonly) int64_t subscriptionIdentifier; - -@property (nonatomic, readonly) TGBridgeResponseType type; -@property (nonatomic, readonly, strong) id next; -@property (nonatomic, readonly, strong) NSString *error; - -+ (TGBridgeResponse *)single:(id)next forSubscription:(TGBridgeSubscription *)subscription; -+ (TGBridgeResponse *)fail:(id)error forSubscription:(TGBridgeSubscription *)subscription; -+ (TGBridgeResponse *)completeForSubscription:(TGBridgeSubscription *)subscription; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeContactMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeContactMediaAttachment.h deleted file mode 100644 index 052293134a..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeContactMediaAttachment.h +++ /dev/null @@ -1,13 +0,0 @@ -#import - -@interface TGBridgeContactMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int32_t uid; -@property (nonatomic, strong) NSString *firstName; -@property (nonatomic, strong) NSString *lastName; -@property (nonatomic, strong) NSString *phoneNumber; -@property (nonatomic, strong) NSString *prettyPhoneNumber; - -- (NSString *)displayName; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeContext.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeContext.h deleted file mode 100644 index 45225a04f6..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeContext.h +++ /dev/null @@ -1,18 +0,0 @@ -#import - -@interface TGBridgeContext : NSObject - -@property (nonatomic, readonly) bool authorized; -@property (nonatomic, readonly) int32_t userId; -@property (nonatomic, readonly) bool micAccessAllowed; -@property (nonatomic, readonly) NSDictionary *preheatData; -@property (nonatomic, readonly) NSInteger preheatVersion; - -- (instancetype)initWithDictionary:(NSDictionary *)dictionary; -- (NSDictionary *)dictionary; - -- (TGBridgeContext *)updatedWithAuthorized:(bool)authorized peerId:(int32_t)peerId; -- (TGBridgeContext *)updatedWithPreheatData:(NSDictionary *)data; -- (TGBridgeContext *)updatedWithMicAccessAllowed:(bool)allowed; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeDocumentMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeDocumentMediaAttachment.h deleted file mode 100644 index 020a50fa47..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeDocumentMediaAttachment.h +++ /dev/null @@ -1,23 +0,0 @@ -#import - -@interface TGBridgeDocumentMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t documentId; -@property (nonatomic, assign) int64_t localDocumentId; -@property (nonatomic, assign) int32_t fileSize; - -@property (nonatomic, strong) NSString *fileName; -@property (nonatomic, strong) NSValue *imageSize; -@property (nonatomic, assign) bool isAnimated; -@property (nonatomic, assign) bool isSticker; -@property (nonatomic, strong) NSString *stickerAlt; -@property (nonatomic, assign) int64_t stickerPackId; -@property (nonatomic, assign) int64_t stickerPackAccessHash; - -@property (nonatomic, assign) bool isVoice; -@property (nonatomic, assign) bool isAudio; -@property (nonatomic, strong) NSString *title; -@property (nonatomic, strong) NSString *performer; -@property (nonatomic, assign) int32_t duration; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeForwardedMessageMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeForwardedMessageMediaAttachment.h deleted file mode 100644 index f57651e4e7..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeForwardedMessageMediaAttachment.h +++ /dev/null @@ -1,9 +0,0 @@ -#import - -@interface TGBridgeForwardedMessageMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t peerId; -@property (nonatomic, assign) int32_t mid; -@property (nonatomic, assign) int32_t date; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeImageMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeImageMediaAttachment.h deleted file mode 100644 index f35b6623d3..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeImageMediaAttachment.h +++ /dev/null @@ -1,10 +0,0 @@ -#import - -#import - -@interface TGBridgeImageMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t imageId; -@property (nonatomic, assign) CGSize dimensions; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeLocationMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeLocationMediaAttachment.h deleted file mode 100644 index 0108154651..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeLocationMediaAttachment.h +++ /dev/null @@ -1,19 +0,0 @@ -#import - -@interface TGBridgeVenueAttachment : NSObject - -@property (nonatomic, strong) NSString *title; -@property (nonatomic, strong) NSString *address; -@property (nonatomic, strong) NSString *provider; -@property (nonatomic, strong) NSString *venueId; - -@end - -@interface TGBridgeLocationMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) double latitude; -@property (nonatomic, assign) double longitude; - -@property (nonatomic, strong) TGBridgeVenueAttachment *venue; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeLocationVenue.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeLocationVenue.h deleted file mode 100644 index c626f76f9c..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeLocationVenue.h +++ /dev/null @@ -1,15 +0,0 @@ -#import - -@class TGBridgeLocationMediaAttachment; - -@interface TGBridgeLocationVenue : NSObject - -@property (nonatomic) CLLocationCoordinate2D coordinate; -@property (nonatomic, strong) NSString *identifier; -@property (nonatomic, strong) NSString *provider; -@property (nonatomic, strong) NSString *name; -@property (nonatomic, strong) NSString *address; - -- (TGBridgeLocationMediaAttachment *)locationAttachment; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMediaAttachment.h deleted file mode 100644 index a814ea5008..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMediaAttachment.h +++ /dev/null @@ -1,11 +0,0 @@ -#import - -@interface TGBridgeMediaAttachment : NSObject - -@property (nonatomic, readonly) NSInteger mediaType; - -+ (NSInteger)mediaType; - -@end - -extern NSString *const TGBridgeMediaAttachmentTypeKey; diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessage.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessage.h deleted file mode 100644 index a55e149121..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessage.h +++ /dev/null @@ -1,65 +0,0 @@ -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import - -typedef enum { - TGBridgeTextCheckingResultTypeUndefined, - TGBridgeTextCheckingResultTypeBold, - TGBridgeTextCheckingResultTypeItalic, - TGBridgeTextCheckingResultTypeCode, - TGBridgeTextCheckingResultTypePre -} TGBridgeTextCheckingResultType; - -@interface TGBridgeTextCheckingResult : NSObject - -@property (nonatomic, assign) TGBridgeTextCheckingResultType type; -@property (nonatomic, assign) NSRange range; - -@end - - -typedef NS_ENUM(NSUInteger, TGBridgeMessageDeliveryState) { - TGBridgeMessageDeliveryStateDelivered = 0, - TGBridgeMessageDeliveryStatePending = 1, - TGBridgeMessageDeliveryStateFailed = 2 -}; - -@interface TGBridgeMessage : NSObject - -@property (nonatomic) int32_t identifier; -@property (nonatomic) NSTimeInterval date; -@property (nonatomic) int64_t randomId; -@property (nonatomic) bool unread; -@property (nonatomic) bool deliveryError; -@property (nonatomic) TGBridgeMessageDeliveryState deliveryState; -@property (nonatomic) bool outgoing; -@property (nonatomic) int64_t fromUid; -@property (nonatomic) int64_t toUid; -@property (nonatomic) int64_t cid; -@property (nonatomic, strong) NSString *text; -@property (nonatomic, strong) NSArray *media; -@property (nonatomic) bool forceReply; - -- (NSArray *)involvedUserIds; -- (NSArray *)textCheckingResults; - -+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId; -+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId replyToMessage:(TGBridgeMessage *)replyToMessage; -+ (instancetype)temporaryNewMessageForSticker:(TGBridgeDocumentMediaAttachment *)sticker userId:(int32_t)userId; -+ (instancetype)temporaryNewMessageForLocation:(TGBridgeLocationMediaAttachment *)location userId:(int32_t)userId; -+ (instancetype)temporaryNewMessageForAudioWithDuration:(int32_t)duration userId:(int32_t)userId localAudioId:(int64_t)localAudioId; - -@end - -extern NSString *const TGBridgeMessageKey; -extern NSString *const TGBridgeMessagesArrayKey; diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessageEntities.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessageEntities.h deleted file mode 100644 index 669ff3b21d..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessageEntities.h +++ /dev/null @@ -1,59 +0,0 @@ -#import - -@interface TGBridgeMessageEntity : NSObject - -@property (nonatomic, assign) NSRange range; - -+ (instancetype)entitityWithRange:(NSRange)range; - -@end - - -@interface TGBridgeMessageEntityUrl : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityEmail : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityTextUrl : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityMention : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityHashtag : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityBotCommand : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityBold : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityItalic : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityCode : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityPre : TGBridgeMessageEntity - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessageEntitiesAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessageEntitiesAttachment.h deleted file mode 100644 index 8f32fd038c..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeMessageEntitiesAttachment.h +++ /dev/null @@ -1,8 +0,0 @@ -#import -#import - -@interface TGBridgeMessageEntitiesAttachment : TGBridgeMediaAttachment - -@property (nonatomic, strong) NSArray *entities; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgePeerIdAdapter.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgePeerIdAdapter.h deleted file mode 100644 index c5f0ac92fc..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgePeerIdAdapter.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef Telegraph_TGPeerIdAdapter_h -#define Telegraph_TGPeerIdAdapter_h - -static inline bool TGPeerIdIsGroup(int64_t peerId) { - return peerId < 0 && peerId > INT32_MIN; -} - -static inline bool TGPeerIdIsUser(int64_t peerId) { - return peerId > 0 && peerId < INT32_MAX; -} - -static inline bool TGPeerIdIsChannel(int64_t peerId) { - return peerId <= ((int64_t)INT32_MIN) * 2 && peerId > ((int64_t)INT32_MIN) * 3; -} - -static inline bool TGPeerIdIsAdminLog(int64_t peerId) { - return peerId <= ((int64_t)INT32_MIN) * 3 && peerId > ((int64_t)INT32_MIN) * 4; -} - -static inline int32_t TGChannelIdFromPeerId(int64_t peerId) { - if (TGPeerIdIsChannel(peerId)) { - return (int32_t)(((int64_t)INT32_MIN) * 2 - peerId); - } else { - return 0; - } -} - -static inline int64_t TGPeerIdFromChannelId(int32_t channelId) { - return ((int64_t)INT32_MIN) * 2 - ((int64_t)channelId); -} - -static inline int64_t TGPeerIdFromAdminLogId(int32_t channelId) { - return ((int64_t)INT32_MIN) * 3 - ((int64_t)channelId); -} - -static inline int64_t TGPeerIdFromGroupId(int32_t groupId) { - return -groupId; -} - -static inline int32_t TGGroupIdFromPeerId(int64_t peerId) { - if (TGPeerIdIsGroup(peerId)) { - return (int32_t)-peerId; - } else { - return 0; - } -} - -static inline bool TGPeerIdIsSecretChat(int64_t peerId) { - return peerId <= ((int64_t)INT32_MIN) && peerId > ((int64_t)INT32_MIN) * 2; -} - -#endif diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgePeerNotificationSettings.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgePeerNotificationSettings.h deleted file mode 100644 index fce723cecb..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgePeerNotificationSettings.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface TGBridgePeerNotificationSettings : NSObject - -@property (nonatomic, assign) int32_t muteFor; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeReplyMarkupMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeReplyMarkupMediaAttachment.h deleted file mode 100644 index ef8a600aee..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeReplyMarkupMediaAttachment.h +++ /dev/null @@ -1,9 +0,0 @@ -#import - -@class TGBridgeBotReplyMarkup; - -@interface TGBridgeReplyMarkupMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, strong) TGBridgeBotReplyMarkup *replyMarkup; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeReplyMessageMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeReplyMessageMediaAttachment.h deleted file mode 100644 index 50353e214d..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeReplyMessageMediaAttachment.h +++ /dev/null @@ -1,10 +0,0 @@ -#import - -@class TGBridgeMessage; - -@interface TGBridgeReplyMessageMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int32_t mid; -@property (nonatomic, strong) TGBridgeMessage *message; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeSubscriptions.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeSubscriptions.h deleted file mode 100644 index 609c2d019d..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeSubscriptions.h +++ /dev/null @@ -1,268 +0,0 @@ -#import - -#import -#import - -@class TGBridgeMediaAttachment; -@class TGBridgeImageMediaAttachment; -@class TGBridgeVideoMediaAttachment; -@class TGBridgeDocumentMediaAttachment; -@class TGBridgeLocationMediaAttachment; -@class TGBridgePeerNotificationSettings; - -@interface TGBridgeAudioSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) TGBridgeMediaAttachment *attachment; -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; - -- (instancetype)initWithAttachment:(TGBridgeMediaAttachment *)attachment peerId:(int64_t)peerId messageId:(int32_t)messageId; - -@end - - -@interface TGBridgeAudioSentSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t conversationId; - -- (instancetype)initWithConversationId:(int64_t)conversationId; - -@end - - -@interface TGBridgeChatListSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int32_t limit; - -- (instancetype)initWithLimit:(int32_t)limit; - -@end - - -@interface TGBridgeChatMessageListSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t atMessageId; -@property (nonatomic, readonly) NSUInteger rangeMessageCount; - -- (instancetype)initWithPeerId:(int64_t)peerId atMessageId:(int32_t)messageId rangeMessageCount:(NSUInteger)rangeMessageCount; - -@end - - -@interface TGBridgeChatMessageSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId; - -@end - - -@interface TGBridgeReadChatMessageListSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId; - -@end - - -@interface TGBridgeContactsSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) NSString *query; - -- (instancetype)initWithQuery:(NSString *)query; - -@end - - -@interface TGBridgeConversationSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; - -- (instancetype)initWithPeerId:(int64_t)peerId; - -@end - - -@interface TGBridgeNearbyVenuesSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; -@property (nonatomic, readonly) int32_t limit; - -- (instancetype)initWithCoordinate:(CLLocationCoordinate2D)coordinate limit:(int32_t)limit; - -@end - - -@interface TGBridgeMediaThumbnailSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; -@property (nonatomic, readonly) CGSize size; -@property (nonatomic, readonly) bool notification; - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId size:(CGSize)size notification:(bool)notification; - -@end - - -typedef NS_ENUM(NSUInteger, TGBridgeMediaAvatarType) { - TGBridgeMediaAvatarTypeSmall, - TGBridgeMediaAvatarTypeProfile, - TGBridgeMediaAvatarTypeLarge -}; - -@interface TGBridgeMediaAvatarSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) NSString *url; -@property (nonatomic, readonly) TGBridgeMediaAvatarType type; - -- (instancetype)initWithPeerId:(int64_t)peerId url:(NSString *)url type:(TGBridgeMediaAvatarType)type; - -@end - -@interface TGBridgeMediaStickerSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t documentId; -@property (nonatomic, readonly) int64_t stickerPackId; -@property (nonatomic, readonly) int64_t stickerPackAccessHash; -@property (nonatomic, readonly) int64_t stickerPeerId; -@property (nonatomic, readonly) int32_t stickerMessageId; -@property (nonatomic, readonly) bool notification; -@property (nonatomic, readonly) CGSize size; - -- (instancetype)initWithDocumentId:(int64_t)documentId stickerPackId:(int64_t)stickerPackId stickerPackAccessHash:(int64_t)stickerPackAccessHash stickerPeerId:(int64_t)stickerPeerId stickerMessageId:(int32_t)stickerMessageId notification:(bool)notification size:(CGSize)size; - -@end - - -@interface TGBridgePeerSettingsSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; - -- (instancetype)initWithPeerId:(int64_t)peerId; - -@end - -@interface TGBridgePeerUpdateNotificationSettingsSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; - -- (instancetype)initWithPeerId:(int64_t)peerId; - -@end - -@interface TGBridgePeerUpdateBlockStatusSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) bool blocked; - -- (instancetype)initWithPeerId:(int64_t)peerId blocked:(bool)blocked; - -@end - - -@interface TGBridgeRemoteSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; -@property (nonatomic, readonly) int32_t type; -@property (nonatomic, readonly) bool autoPlay; - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId type:(int32_t)type autoPlay:(bool)autoPlay; - -@end - - -@interface TGBridgeSendTextMessageSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) NSString *text; -@property (nonatomic, readonly) int32_t replyToMid; - -- (instancetype)initWithPeerId:(int64_t)peerId text:(NSString *)text replyToMid:(int32_t)replyToMid; - -@end - - -@interface TGBridgeSendStickerMessageSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) TGBridgeDocumentMediaAttachment *document; -@property (nonatomic, readonly) int32_t replyToMid; - -- (instancetype)initWithPeerId:(int64_t)peerId document:(TGBridgeDocumentMediaAttachment *)document replyToMid:(int32_t)replyToMid; - -@end - - -@interface TGBridgeSendLocationMessageSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) TGBridgeLocationMediaAttachment *location; -@property (nonatomic, readonly) int32_t replyToMid; - -- (instancetype)initWithPeerId:(int64_t)peerId location:(TGBridgeLocationMediaAttachment *)location replyToMid:(int32_t)replyToMid; - -@end - - -@interface TGBridgeSendForwardedMessageSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; -@property (nonatomic, readonly) int64_t targetPeerId; - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId targetPeerId:(int64_t)targetPeerId; - -@end - - -@interface TGBridgeStateSubscription : TGBridgeSubscription - -@end - - -@interface TGBridgeStickerPacksSubscription : TGBridgeSubscription - -@end - - -@interface TGBridgeRecentStickersSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int32_t limit; - -- (instancetype)initWithLimit:(int32_t)limit; - -@end - - -@interface TGBridgeUserInfoSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) NSArray *userIds; - -- (instancetype)initWithUserIds:(NSArray *)userIds; - -@end - - -@interface TGBridgeUserBotInfoSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) NSArray *userIds; - -- (instancetype)initWithUserIds:(NSArray *)userIds; - -@end - -@interface TGBridgeBotReplyMarkupSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; - -- (instancetype)initWithPeerId:(int64_t)peerId; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeUnsupportedMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeUnsupportedMediaAttachment.h deleted file mode 100644 index 5b81ed1f57..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeUnsupportedMediaAttachment.h +++ /dev/null @@ -1,9 +0,0 @@ -#import - -@interface TGBridgeUnsupportedMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, strong) NSString *compactTitle; -@property (nonatomic, strong) NSString *title; -@property (nonatomic, strong) NSString *subtitle; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeUser.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeUser.h deleted file mode 100644 index 632d934db4..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeUser.h +++ /dev/null @@ -1,59 +0,0 @@ -#import - -@class TGBridgeBotInfo; -@class TGBridgeUserChange; - -typedef NS_ENUM(NSUInteger, TGBridgeUserKind) { - TGBridgeUserKindGeneric, - TGBridgeUserKindBot, - TGBridgeUserKindSmartBot -}; - -typedef NS_ENUM(NSUInteger, TGBridgeBotKind) { - TGBridgeBotKindGeneric, - TGBridgeBotKindPrivate -}; - -@interface TGBridgeUser : NSObject - -@property (nonatomic) int64_t identifier; -@property (nonatomic, strong) NSString *firstName; -@property (nonatomic, strong) NSString *lastName; -@property (nonatomic, strong) NSString *userName; -@property (nonatomic, strong) NSString *phoneNumber; -@property (nonatomic, strong) NSString *prettyPhoneNumber; -@property (nonatomic, strong) NSString *about; - -@property (nonatomic) bool online; -@property (nonatomic) NSTimeInterval lastSeen; - -@property (nonatomic, strong) NSString *photoSmall; -@property (nonatomic, strong) NSString *photoBig; - -@property (nonatomic) TGBridgeUserKind kind; -@property (nonatomic) TGBridgeBotKind botKind; -@property (nonatomic) int32_t botVersion; - -@property (nonatomic) bool verified; - -@property (nonatomic) int32_t userVersion; - -- (NSString *)displayName; -- (TGBridgeUserChange *)changeFromUser:(TGBridgeUser *)user; -- (TGBridgeUser *)userByApplyingChange:(TGBridgeUserChange *)change; - -- (bool)isBot; - -@end - - -@interface TGBridgeUserChange : NSObject - -@property (nonatomic, readonly) int32_t userIdentifier; -@property (nonatomic, readonly) NSDictionary *fields; - -- (instancetype)initWithUserIdentifier:(int32_t)userIdentifier fields:(NSDictionary *)fields; - -@end - -extern NSString *const TGBridgeUsersDictionaryKey; diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeVideoMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeVideoMediaAttachment.h deleted file mode 100644 index 8d54027ce4..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeVideoMediaAttachment.h +++ /dev/null @@ -1,12 +0,0 @@ -#import - -#import - -@interface TGBridgeVideoMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t videoId; -@property (nonatomic, assign) int32_t duration; -@property (nonatomic, assign) CGSize dimensions; -@property (nonatomic, assign) bool round; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeWebPageMediaAttachment.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeWebPageMediaAttachment.h deleted file mode 100644 index 6e20ee3f96..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/TGBridgeWebPageMediaAttachment.h +++ /dev/null @@ -1,23 +0,0 @@ -#import - -#import - -@class TGBridgeImageMediaAttachment; - -@interface TGBridgeWebPageMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t webPageId; -@property (nonatomic, strong) NSString *url; -@property (nonatomic, strong) NSString *displayUrl; -@property (nonatomic, strong) NSString *pageType; -@property (nonatomic, strong) NSString *siteName; -@property (nonatomic, strong) NSString *title; -@property (nonatomic, strong) NSString *pageDescription; -@property (nonatomic, strong) TGBridgeImageMediaAttachment *photo; -@property (nonatomic, strong) NSString *embedUrl; -@property (nonatomic, strong) NSString *embedType; -@property (nonatomic, assign) CGSize embedSize; -@property (nonatomic, strong) NSNumber *duration; -@property (nonatomic, strong) NSString *author; - -@end diff --git a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/WatchCommon.h b/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/WatchCommon.h deleted file mode 100644 index 27b37d2d7b..0000000000 --- a/submodules/WatchCommon/Host/PublicHeaders/WatchCommon/WatchCommon.h +++ /dev/null @@ -1,29 +0,0 @@ -#import - -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeActionMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeActionMediaAttachment.m deleted file mode 100644 index 763cf8a1eb..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeActionMediaAttachment.m +++ /dev/null @@ -1,33 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeAudioMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeAudioMediaAttachment.m deleted file mode 100644 index 3f4096a897..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeAudioMediaAttachment.m +++ /dev/null @@ -1,65 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeBotCommandInfo.m b/submodules/WatchCommon/Host/Sources/TGBridgeBotCommandInfo.m deleted file mode 100644 index 0f1e005861..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeBotCommandInfo.m +++ /dev/null @@ -1,25 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeBotInfo.m b/submodules/WatchCommon/Host/Sources/TGBridgeBotInfo.m deleted file mode 100644 index 996abb3a95..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeBotInfo.m +++ /dev/null @@ -1,25 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeChat.m b/submodules/WatchCommon/Host/Sources/TGBridgeChat.m deleted file mode 100644 index 973522fa3c..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeChat.m +++ /dev/null @@ -1,148 +0,0 @@ -#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 *)involvedUserIds -{ - NSMutableSet *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 *)participantsUserIds -{ - NSMutableSet *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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeChatMessages.m b/submodules/WatchCommon/Host/Sources/TGBridgeChatMessages.m deleted file mode 100644 index c7b64e2c13..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeChatMessages.m +++ /dev/null @@ -1,27 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeCommon.m b/submodules/WatchCommon/Host/Sources/TGBridgeCommon.m deleted file mode 100644 index ae0cf5300b..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeCommon.m +++ /dev/null @@ -1,295 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeContactMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeContactMediaAttachment.m deleted file mode 100644 index 4b2f482eaa..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeContactMediaAttachment.m +++ /dev/null @@ -1,60 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeContext.m b/submodules/WatchCommon/Host/Sources/TGBridgeContext.m deleted file mode 100644 index 4b0600e2fc..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeContext.m +++ /dev/null @@ -1,101 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeDocumentMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeDocumentMediaAttachment.m deleted file mode 100644 index 8d492ae704..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeDocumentMediaAttachment.m +++ /dev/null @@ -1,84 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeForwardedMessageMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeForwardedMessageMediaAttachment.m deleted file mode 100644 index 169e261cff..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeForwardedMessageMediaAttachment.m +++ /dev/null @@ -1,35 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeImageMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeImageMediaAttachment.m deleted file mode 100644 index 8ab5ec7044..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeImageMediaAttachment.m +++ /dev/null @@ -1,33 +0,0 @@ -#import "TGBridgeImageMediaAttachment.h" -#import - -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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeLocationMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeLocationMediaAttachment.m deleted file mode 100644 index f6762eb549..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeLocationMediaAttachment.m +++ /dev/null @@ -1,95 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeLocationVenue.m b/submodules/WatchCommon/Host/Sources/TGBridgeLocationVenue.m deleted file mode 100644 index 01c8fc8c1a..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeLocationVenue.m +++ /dev/null @@ -1,66 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeMediaAttachment.m deleted file mode 100644 index 971a23b64d..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeMediaAttachment.m +++ /dev/null @@ -1,32 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeMessage.m b/submodules/WatchCommon/Host/Sources/TGBridgeMessage.m deleted file mode 100644 index e66e3313b3..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeMessage.m +++ /dev/null @@ -1,242 +0,0 @@ -#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 *)involvedUserIds -{ - NSMutableSet *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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeMessageEntities.m b/submodules/WatchCommon/Host/Sources/TGBridgeMessageEntities.m deleted file mode 100644 index 8d639a9468..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeMessageEntities.m +++ /dev/null @@ -1,83 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeMessageEntitiesAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeMessageEntitiesAttachment.m deleted file mode 100644 index fb5cb3b7d7..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeMessageEntitiesAttachment.m +++ /dev/null @@ -1,30 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgePeerNotificationSettings.m b/submodules/WatchCommon/Host/Sources/TGBridgePeerNotificationSettings.m deleted file mode 100644 index 662c2f4ca4..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgePeerNotificationSettings.m +++ /dev/null @@ -1,22 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeReplyMarkupMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeReplyMarkupMediaAttachment.m deleted file mode 100644 index 1299c900cd..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeReplyMarkupMediaAttachment.m +++ /dev/null @@ -1,29 +0,0 @@ -#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 \ No newline at end of file diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeReplyMessageMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeReplyMessageMediaAttachment.m deleted file mode 100644 index fbc2456919..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeReplyMessageMediaAttachment.m +++ /dev/null @@ -1,33 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeSubscriptions.m b/submodules/WatchCommon/Host/Sources/TGBridgeSubscriptions.m deleted file mode 100644 index 8c4b50d224..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeSubscriptions.m +++ /dev/null @@ -1,1048 +0,0 @@ -#import "TGBridgeSubscriptions.h" - -#import - -#import "TGBridgeImageMediaAttachment.h" -#import "TGBridgeVideoMediaAttachment.h" -#import "TGBridgeDocumentMediaAttachment.h" -#import "TGBridgeLocationMediaAttachment.h" -#import "TGBridgePeerNotificationSettings.h" - -NSString *const TGBridgeAudioSubscriptionName = @"media.audio"; -NSString *const TGBridgeAudioSubscriptionAttachmentKey = @"attachment"; -NSString *const TGBridgeAudioSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeAudioSubscriptionMessageIdKey = @"messageId"; - -@implementation TGBridgeAudioSubscription - -- (instancetype)initWithAttachment:(TGBridgeMediaAttachment *)attachment peerId:(int64_t)peerId messageId:(int32_t)messageId -{ - self = [super init]; - if (self != nil) - { - _attachment = attachment; - _peerId = peerId; - _messageId = messageId; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeObject:self.attachment forKey:TGBridgeAudioSubscriptionAttachmentKey]; - [aCoder encodeInt64:self.peerId forKey:TGBridgeAudioSubscriptionPeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeAudioSubscriptionMessageIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _attachment = [aDecoder decodeObjectForKey:TGBridgeAudioSubscriptionAttachmentKey]; - _peerId = [aDecoder decodeInt64ForKey:TGBridgeAudioSubscriptionPeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeAudioSubscriptionMessageIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeAudioSubscriptionName; -} - -@end - - -NSString *const TGBridgeAudioSentSubscriptionName = @"media.audioSent"; -NSString *const TGBridgeAudioSentSubscriptionConversationIdKey = @"conversationId"; - -@implementation TGBridgeAudioSentSubscription - -- (instancetype)initWithConversationId:(int64_t)conversationId -{ - self = [super init]; - if (self != nil) - { - _conversationId = conversationId; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.conversationId forKey:TGBridgeAudioSentSubscriptionConversationIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _conversationId = [aDecoder decodeInt64ForKey:TGBridgeAudioSentSubscriptionConversationIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeAudioSentSubscriptionName; -} - -@end - - -NSString *const TGBridgeChatListSubscriptionName = @"chats.chatList"; -NSString *const TGBridgeChatListSubscriptionLimitKey = @"limit"; - -@implementation TGBridgeChatListSubscription - -- (instancetype)initWithLimit:(int32_t)limit -{ - self = [super init]; - if (self != nil) - { - _limit = limit; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt32:self.limit forKey:TGBridgeChatListSubscriptionLimitKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _limit = [aDecoder decodeInt32ForKey:TGBridgeChatListSubscriptionLimitKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeChatListSubscriptionName; -} - -@end - - -NSString *const TGBridgeChatMessageListSubscriptionName = @"chats.chatMessageList"; -NSString *const TGBridgeChatMessageListSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeChatMessageListSubscriptionAtMessageIdKey = @"atMessageId"; -NSString *const TGBridgeChatMessageListSubscriptionRangeMessageCountKey = @"rangeMessageCount"; - -@implementation TGBridgeChatMessageListSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId atMessageId:(int32_t)messageId rangeMessageCount:(NSUInteger)rangeMessageCount -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _atMessageId = messageId; - _rangeMessageCount = rangeMessageCount; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeChatMessageListSubscriptionPeerIdKey]; - [aCoder encodeInt32:self.atMessageId forKey:TGBridgeChatMessageListSubscriptionAtMessageIdKey]; - [aCoder encodeInt32:(int32_t)self.rangeMessageCount forKey:TGBridgeChatMessageListSubscriptionRangeMessageCountKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeChatMessageListSubscriptionPeerIdKey]; - _atMessageId = [aDecoder decodeInt32ForKey:TGBridgeChatMessageListSubscriptionAtMessageIdKey]; - _rangeMessageCount = [aDecoder decodeInt32ForKey:TGBridgeChatMessageListSubscriptionRangeMessageCountKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeChatMessageListSubscriptionName; -} - -@end - - -NSString *const TGBridgeChatMessageSubscriptionName = @"chats.message"; -NSString *const TGBridgeChatMessageSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeChatMessageSubscriptionMessageIdKey = @"mid"; - -@implementation TGBridgeChatMessageSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _messageId = messageId; - } - return self; -} - -- (bool)synchronous -{ - return true; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeChatMessageSubscriptionPeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeChatMessageSubscriptionMessageIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeChatMessageSubscriptionPeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeChatMessageSubscriptionMessageIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeChatMessageSubscriptionName; -} - -@end - - -NSString *const TGBridgeReadChatMessageListSubscriptionName = @"chats.readChatMessageList"; -NSString *const TGBridgeReadChatMessageListSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeReadChatMessageListSubscriptionMessageIdKey = @"mid"; - -@implementation TGBridgeReadChatMessageListSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _messageId = messageId; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeReadChatMessageListSubscriptionPeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeReadChatMessageListSubscriptionMessageIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeReadChatMessageListSubscriptionPeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeReadChatMessageListSubscriptionMessageIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeReadChatMessageListSubscriptionName; -} - -@end - - -NSString *const TGBridgeContactsSubscriptionName = @"contacts.search"; -NSString *const TGBridgeContactsSubscriptionQueryKey = @"query"; - -@implementation TGBridgeContactsSubscription - -- (instancetype)initWithQuery:(NSString *)query -{ - self = [super init]; - if (self != nil) - { - _query = query; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeObject:self.query forKey:TGBridgeContactsSubscriptionQueryKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _query = [aDecoder decodeObjectForKey:TGBridgeContactsSubscriptionQueryKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeContactsSubscriptionName; -} - -@end - - -NSString *const TGBridgeConversationSubscriptionName = @"chats.conversation"; -NSString *const TGBridgeConversationSubscriptionPeerIdKey = @"peerId"; - -@implementation TGBridgeConversationSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeConversationSubscriptionPeerIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeConversationSubscriptionPeerIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeConversationSubscriptionName; -} - -@end - - -NSString *const TGBridgeNearbyVenuesSubscriptionName = @"location.nearbyVenues"; -NSString *const TGBridgeNearbyVenuesSubscriptionLatitudeKey = @"lat"; -NSString *const TGBridgeNearbyVenuesSubscriptionLongitudeKey = @"lon"; -NSString *const TGBridgeNearbyVenuesSubscriptionLimitKey = @"limit"; - -@implementation TGBridgeNearbyVenuesSubscription - -- (instancetype)initWithCoordinate:(CLLocationCoordinate2D)coordinate limit:(int32_t)limit -{ - self = [super init]; - if (self != nil) - { - _coordinate = coordinate; - _limit = limit; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeDouble:self.coordinate.latitude forKey:TGBridgeNearbyVenuesSubscriptionLatitudeKey]; - [aCoder encodeDouble:self.coordinate.longitude forKey:TGBridgeNearbyVenuesSubscriptionLongitudeKey]; - [aCoder encodeInt32:self.limit forKey:TGBridgeNearbyVenuesSubscriptionLimitKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _coordinate = CLLocationCoordinate2DMake([aDecoder decodeDoubleForKey:TGBridgeNearbyVenuesSubscriptionLatitudeKey], - [aDecoder decodeDoubleForKey:TGBridgeNearbyVenuesSubscriptionLongitudeKey]); - _limit = [aDecoder decodeInt32ForKey:TGBridgeNearbyVenuesSubscriptionLimitKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeNearbyVenuesSubscriptionName; -} - -@end - - -NSString *const TGBridgeMediaThumbnailSubscriptionName = @"media.thumbnail"; -NSString *const TGBridgeMediaThumbnailPeerIdKey = @"peerId"; -NSString *const TGBridgeMediaThumbnailMessageIdKey = @"mid"; -NSString *const TGBridgeMediaThumbnailSizeKey = @"size"; -NSString *const TGBridgeMediaThumbnailNotificationKey = @"notification"; - -@implementation TGBridgeMediaThumbnailSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId size:(CGSize)size notification:(bool)notification -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _messageId = messageId; - _size = size; - _notification = notification; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeMediaThumbnailPeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeMediaThumbnailMessageIdKey]; - [aCoder encodeCGSize:self.size forKey:TGBridgeMediaThumbnailSizeKey]; - [aCoder encodeBool:self.notification forKey:TGBridgeMediaThumbnailNotificationKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeMediaThumbnailPeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeMediaThumbnailMessageIdKey]; - _size = [aDecoder decodeCGSizeForKey:TGBridgeMediaThumbnailSizeKey]; - _notification = [aDecoder decodeBoolForKey:TGBridgeMediaThumbnailNotificationKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeMediaThumbnailSubscriptionName; -} - -@end - - -NSString *const TGBridgeMediaAvatarSubscriptionName = @"media.avatar"; -NSString *const TGBridgeMediaAvatarPeerIdKey = @"peerId"; -NSString *const TGBridgeMediaAvatarUrlKey = @"url"; -NSString *const TGBridgeMediaAvatarTypeKey = @"type"; - -@implementation TGBridgeMediaAvatarSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId url:(NSString *)url type:(TGBridgeMediaAvatarType)type -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _url = url; - _type = type; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeMediaAvatarPeerIdKey]; - [aCoder encodeObject:self.url forKey:TGBridgeMediaAvatarUrlKey]; - [aCoder encodeInt32:self.type forKey:TGBridgeMediaAvatarTypeKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeMediaAvatarPeerIdKey]; - _url = [aDecoder decodeObjectForKey:TGBridgeMediaAvatarUrlKey]; - _type = [aDecoder decodeInt32ForKey:TGBridgeMediaAvatarTypeKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeMediaAvatarSubscriptionName; -} - -@end - - -NSString *const TGBridgeMediaStickerSubscriptionName = @"media.sticker"; -NSString *const TGBridgeMediaStickerDocumentIdKey = @"documentId"; -NSString *const TGBridgeMediaStickerPackIdKey = @"packId"; -NSString *const TGBridgeMediaStickerPackAccessHashKey = @"accessHash"; -NSString *const TGBridgeMediaStickerPeerIdKey = @"peerId"; -NSString *const TGBridgeMediaStickerMessageIdKey = @"mid"; -NSString *const TGBridgeMediaStickerNotificationKey = @"notification"; -NSString *const TGBridgeMediaStickerSizeKey = @"size"; - -@implementation TGBridgeMediaStickerSubscription - -- (instancetype)initWithDocumentId:(int64_t)documentId stickerPackId:(int64_t)stickerPackId stickerPackAccessHash:(int64_t)stickerPackAccessHash stickerPeerId:(int64_t)stickerPeerId stickerMessageId:(int32_t)stickerMessageId notification:(bool)notification size:(CGSize)size -{ - self = [super init]; - if (self != nil) - { - _documentId = documentId; - _stickerPackId = stickerPackId; - _stickerPackAccessHash = stickerPackAccessHash; - _stickerPeerId = stickerPeerId; - _stickerMessageId = stickerMessageId; - _notification = notification; - _size = size; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.documentId forKey:TGBridgeMediaStickerDocumentIdKey]; - [aCoder encodeInt64:self.stickerPackId forKey:TGBridgeMediaStickerPackIdKey]; - [aCoder encodeInt64:self.stickerPackAccessHash forKey:TGBridgeMediaStickerPackAccessHashKey]; - [aCoder encodeInt64:self.stickerPeerId forKey:TGBridgeMediaStickerPeerIdKey]; - [aCoder encodeInt32:self.stickerMessageId forKey:TGBridgeMediaStickerMessageIdKey]; - [aCoder encodeBool:self.notification forKey:TGBridgeMediaStickerNotificationKey]; - [aCoder encodeCGSize:self.size forKey:TGBridgeMediaStickerSizeKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _documentId = [aDecoder decodeInt64ForKey:TGBridgeMediaStickerDocumentIdKey]; - _stickerPackId = [aDecoder decodeInt64ForKey:TGBridgeMediaStickerPackIdKey]; - _stickerPackAccessHash = [aDecoder decodeInt64ForKey:TGBridgeMediaStickerPackAccessHashKey]; - _stickerPeerId = [aDecoder decodeInt64ForKey:TGBridgeMediaStickerPeerIdKey]; - _stickerMessageId = [aDecoder decodeInt32ForKey:TGBridgeMediaStickerMessageIdKey]; - _notification = [aDecoder decodeBoolForKey:TGBridgeMediaStickerNotificationKey]; - _size = [aDecoder decodeCGSizeForKey:TGBridgeMediaStickerSizeKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeMediaStickerSubscriptionName; -} - -@end - - -NSString *const TGBridgePeerSettingsSubscriptionName = @"peer.settings"; -NSString *const TGBridgePeerSettingsSubscriptionPeerIdKey = @"peerId"; - -@implementation TGBridgePeerSettingsSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgePeerSettingsSubscriptionPeerIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgePeerSettingsSubscriptionPeerIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgePeerSettingsSubscriptionName; -} - -@end - - -NSString *const TGBridgePeerUpdateNotificationSettingsSubscriptionName = @"peer.notificationSettings"; -NSString *const TGBridgePeerUpdateNotificationSettingsSubscriptionPeerIdKey = @"peerId"; - -@implementation TGBridgePeerUpdateNotificationSettingsSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgePeerUpdateNotificationSettingsSubscriptionPeerIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgePeerUpdateNotificationSettingsSubscriptionPeerIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgePeerUpdateNotificationSettingsSubscriptionName; -} - -@end - - -NSString *const TGBridgePeerUpdateBlockStatusSubscriptionName = @"peer.updateBlocked"; -NSString *const TGBridgePeerUpdateBlockStatusSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgePeerUpdateBlockStatusSubscriptionBlockedKey = @"blocked"; - -@implementation TGBridgePeerUpdateBlockStatusSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId blocked:(bool)blocked -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _blocked = blocked; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgePeerUpdateBlockStatusSubscriptionPeerIdKey]; - [aCoder encodeBool:self.blocked forKey:TGBridgePeerUpdateBlockStatusSubscriptionBlockedKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgePeerUpdateBlockStatusSubscriptionPeerIdKey]; - _blocked = [aDecoder decodeBoolForKey:TGBridgePeerUpdateBlockStatusSubscriptionBlockedKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgePeerUpdateBlockStatusSubscriptionName; -} - -@end - - -NSString *const TGBridgeRemoteSubscriptionName = @"remote.request"; -NSString *const TGBridgeRemotePeerIdKey = @"peerId"; -NSString *const TGBridgeRemoteMessageIdKey = @"mid"; -NSString *const TGBridgeRemoteTypeKey = @"mediaType"; -NSString *const TGBridgeRemoteAutoPlayKey = @"autoPlay"; - -@implementation TGBridgeRemoteSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId type:(int32_t)type autoPlay:(bool)autoPlay -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _messageId = messageId; - _type = type; - _autoPlay = autoPlay; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeRemotePeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeRemoteMessageIdKey]; - [aCoder encodeInt32:self.type forKey:TGBridgeRemoteTypeKey]; - [aCoder encodeBool:self.autoPlay forKey:TGBridgeRemoteAutoPlayKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeRemotePeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeRemoteMessageIdKey]; - _type = [aDecoder decodeInt32ForKey:TGBridgeRemoteTypeKey]; - _autoPlay = [aDecoder decodeBoolForKey:TGBridgeRemoteAutoPlayKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeRemoteSubscriptionName; -} - -@end - - -NSString *const TGBridgeSendTextMessageSubscriptionName = @"sendMessage.text"; -NSString *const TGBridgeSendTextMessageSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeSendTextMessageSubscriptionTextKey = @"text"; -NSString *const TGBridgeSendTextMessageSubscriptionReplyToMidKey = @"replyToMid"; - -@implementation TGBridgeSendTextMessageSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId text:(NSString *)text replyToMid:(int32_t)replyToMid -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _text = text; - _replyToMid = replyToMid; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeSendTextMessageSubscriptionPeerIdKey]; - [aCoder encodeObject:self.text forKey:TGBridgeSendTextMessageSubscriptionTextKey]; - [aCoder encodeInt32:self.replyToMid forKey:TGBridgeSendTextMessageSubscriptionReplyToMidKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeSendTextMessageSubscriptionPeerIdKey]; - _text = [aDecoder decodeObjectForKey:TGBridgeSendTextMessageSubscriptionTextKey]; - _replyToMid = [aDecoder decodeInt32ForKey:TGBridgeSendTextMessageSubscriptionReplyToMidKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeSendTextMessageSubscriptionName; -} - -@end - - -NSString *const TGBridgeSendStickerMessageSubscriptionName = @"sendMessage.sticker"; -NSString *const TGBridgeSendStickerMessageSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeSendStickerMessageSubscriptionDocumentKey = @"document"; -NSString *const TGBridgeSendStickerMessageSubscriptionReplyToMidKey = @"replyToMid"; - -@implementation TGBridgeSendStickerMessageSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId document:(TGBridgeDocumentMediaAttachment *)document replyToMid:(int32_t)replyToMid -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _document = document; - _replyToMid = replyToMid; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeSendStickerMessageSubscriptionPeerIdKey]; - [aCoder encodeObject:self.document forKey:TGBridgeSendStickerMessageSubscriptionDocumentKey]; - [aCoder encodeInt32:self.replyToMid forKey:TGBridgeSendStickerMessageSubscriptionReplyToMidKey]; -} - - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeSendStickerMessageSubscriptionPeerIdKey]; - _document = [aDecoder decodeObjectForKey:TGBridgeSendStickerMessageSubscriptionDocumentKey]; - _replyToMid = [aDecoder decodeInt32ForKey:TGBridgeSendStickerMessageSubscriptionReplyToMidKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeSendStickerMessageSubscriptionName; -} - -@end - - -NSString *const TGBridgeSendLocationMessageSubscriptionName = @"sendMessage.location"; -NSString *const TGBridgeSendLocationMessageSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeSendLocationMessageSubscriptionLocationKey = @"location"; -NSString *const TGBridgeSendLocationMessageSubscriptionReplyToMidKey = @"replyToMid"; - -@implementation TGBridgeSendLocationMessageSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId location:(TGBridgeLocationMediaAttachment *)location replyToMid:(int32_t)replyToMid -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _location = location; - _replyToMid = replyToMid; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeSendLocationMessageSubscriptionPeerIdKey]; - [aCoder encodeObject:self.location forKey:TGBridgeSendLocationMessageSubscriptionLocationKey]; - [aCoder encodeInt32:self.replyToMid forKey:TGBridgeSendLocationMessageSubscriptionReplyToMidKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeSendLocationMessageSubscriptionPeerIdKey]; - _location = [aDecoder decodeObjectForKey:TGBridgeSendLocationMessageSubscriptionLocationKey]; - _replyToMid = [aDecoder decodeInt32ForKey:TGBridgeSendLocationMessageSubscriptionReplyToMidKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeSendLocationMessageSubscriptionName; -} - -@end - - -NSString *const TGBridgeSendForwardedMessageSubscriptionName = @"sendMessage.forward"; -NSString *const TGBridgeSendForwardedMessageSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeSendForwardedMessageSubscriptionMidKey = @"mid"; -NSString *const TGBridgeSendForwardedMessageSubscriptionTargetPeerIdKey = @"targetPeerId"; - -@implementation TGBridgeSendForwardedMessageSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId targetPeerId:(int64_t)targetPeerId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _messageId = messageId; - _targetPeerId = targetPeerId; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeSendForwardedMessageSubscriptionPeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeSendForwardedMessageSubscriptionMidKey]; - [aCoder encodeInt64:self.targetPeerId forKey:TGBridgeSendForwardedMessageSubscriptionTargetPeerIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeSendForwardedMessageSubscriptionPeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeSendForwardedMessageSubscriptionMidKey]; - _targetPeerId = [aDecoder decodeInt64ForKey:TGBridgeSendForwardedMessageSubscriptionTargetPeerIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeSendForwardedMessageSubscriptionName; -} - -@end - - -NSString *const TGBridgeStateSubscriptionName = @"state.syncState"; - -@implementation TGBridgeStateSubscription - -- (bool)dropPreviouslyQueued -{ - return true; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeStateSubscriptionName; -} - -@end - - -NSString *const TGBridgeStickerPacksSubscriptionName = @"stickers.packs"; - -@implementation TGBridgeStickerPacksSubscription - -+ (NSString *)subscriptionName -{ - return TGBridgeStickerPacksSubscriptionName; -} - -@end - - -NSString *const TGBridgeRecentStickersSubscriptionName = @"stickers.recent"; -NSString *const TGBridgeRecentStickersSubscriptionLimitKey = @"limit"; - -@implementation TGBridgeRecentStickersSubscription - -- (instancetype)initWithLimit:(int32_t)limit -{ - self = [super init]; - if (self != nil) - { - _limit = limit; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt32:self.limit forKey:TGBridgeRecentStickersSubscriptionLimitKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _limit = [aDecoder decodeInt32ForKey:TGBridgeRecentStickersSubscriptionLimitKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeRecentStickersSubscriptionName; -} - -@end - - -NSString *const TGBridgeUserInfoSubscriptionName = @"user.userInfo"; -NSString *const TGBridgeUserInfoSubscriptionUserIdsKey = @"uids"; - -@implementation TGBridgeUserInfoSubscription - -- (instancetype)initWithUserIds:(NSArray *)userIds -{ - self = [super init]; - if (self != nil) - { - _userIds = userIds; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeObject:self.userIds forKey:TGBridgeUserInfoSubscriptionUserIdsKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _userIds = [aDecoder decodeObjectForKey:TGBridgeUserInfoSubscriptionUserIdsKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeUserInfoSubscriptionName; -} - -@end - - -NSString *const TGBridgeUserBotInfoSubscriptionName = @"user.botInfo"; -NSString *const TGBridgeUserBotInfoSubscriptionUserIdsKey = @"uids"; - -@implementation TGBridgeUserBotInfoSubscription - -- (instancetype)initWithUserIds:(NSArray *)userIds -{ - self = [super init]; - if (self != nil) - { - _userIds = userIds; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeObject:self.userIds forKey:TGBridgeUserBotInfoSubscriptionUserIdsKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _userIds = [aDecoder decodeObjectForKey:TGBridgeUserBotInfoSubscriptionUserIdsKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeUserBotInfoSubscriptionName; -} - -@end - - -NSString *const TGBridgeBotReplyMarkupSubscriptionName = @"user.botReplyMarkup"; -NSString *const TGBridgeBotReplyMarkupPeerIdKey = @"peerId"; - -@implementation TGBridgeBotReplyMarkupSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeBotReplyMarkupPeerIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeBotReplyMarkupPeerIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeBotReplyMarkupSubscriptionName; -} - -@end diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeUnsupportedMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeUnsupportedMediaAttachment.m deleted file mode 100644 index b51e422fd1..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeUnsupportedMediaAttachment.m +++ /dev/null @@ -1,35 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeUser.m b/submodules/WatchCommon/Host/Sources/TGBridgeUser.m deleted file mode 100644 index 4c0fed8d97..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeUser.m +++ /dev/null @@ -1,286 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeVideoMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeVideoMediaAttachment.m deleted file mode 100644 index 66fe867996..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeVideoMediaAttachment.m +++ /dev/null @@ -1,39 +0,0 @@ -#import "TGBridgeVideoMediaAttachment.h" -#import - -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 diff --git a/submodules/WatchCommon/Host/Sources/TGBridgeWebPageMediaAttachment.m b/submodules/WatchCommon/Host/Sources/TGBridgeWebPageMediaAttachment.m deleted file mode 100644 index 3983075d69..0000000000 --- a/submodules/WatchCommon/Host/Sources/TGBridgeWebPageMediaAttachment.m +++ /dev/null @@ -1,65 +0,0 @@ -#import "TGBridgeWebPageMediaAttachment.h" -#import "TGBridgeImageMediaAttachment.h" -#import - -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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeActionMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeActionMediaAttachment.h deleted file mode 100644 index 5b2f13e4f4..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeActionMediaAttachment.h +++ /dev/null @@ -1,36 +0,0 @@ -#import - -typedef NS_ENUM(NSUInteger, TGBridgeMessageAction) { - TGBridgeMessageActionNone = 0, - TGBridgeMessageActionChatEditTitle = 1, - TGBridgeMessageActionChatAddMember = 2, - TGBridgeMessageActionChatDeleteMember = 3, - TGBridgeMessageActionCreateChat = 4, - TGBridgeMessageActionChatEditPhoto = 5, - TGBridgeMessageActionContactRequest = 6, - TGBridgeMessageActionAcceptContactRequest = 7, - TGBridgeMessageActionContactRegistered = 8, - TGBridgeMessageActionUserChangedPhoto = 9, - TGBridgeMessageActionEncryptedChatRequest = 10, - TGBridgeMessageActionEncryptedChatAccept = 11, - TGBridgeMessageActionEncryptedChatDecline = 12, - TGBridgeMessageActionEncryptedChatMessageLifetime = 13, - TGBridgeMessageActionEncryptedChatScreenshot = 14, - TGBridgeMessageActionEncryptedChatMessageScreenshot = 15, - TGBridgeMessageActionCreateBroadcastList = 16, - TGBridgeMessageActionJoinedByLink = 17, - TGBridgeMessageActionChannelCreated = 18, - TGBridgeMessageActionChannelCommentsStatusChanged = 19, - TGBridgeMessageActionChannelInviter = 20, - TGBridgeMessageActionGroupMigratedTo = 21, - TGBridgeMessageActionGroupDeactivated = 22, - TGBridgeMessageActionGroupActivated = 23, - TGBridgeMessageActionChannelMigratedFrom = 24 -}; - -@interface TGBridgeActionMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) TGBridgeMessageAction actionType; -@property (nonatomic, strong) NSDictionary *actionData; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeActionMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeActionMediaAttachment.m deleted file mode 100644 index 763cf8a1eb..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeActionMediaAttachment.m +++ /dev/null @@ -1,33 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeAudioMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeAudioMediaAttachment.h deleted file mode 100644 index d6bdcd9716..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeAudioMediaAttachment.h +++ /dev/null @@ -1,16 +0,0 @@ -#import - -@interface TGBridgeAudioMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t audioId; -@property (nonatomic, assign) int64_t accessHash; -@property (nonatomic, assign) int32_t datacenterId; - -@property (nonatomic, assign) int64_t localAudioId; - -@property (nonatomic, assign) int32_t duration; -@property (nonatomic, assign) int32_t fileSize; - -- (int64_t)identifier; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeAudioMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeAudioMediaAttachment.m deleted file mode 100644 index 3f4096a897..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeAudioMediaAttachment.m +++ /dev/null @@ -1,65 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeBotCommandInfo.h b/submodules/WatchCommon/Watch/Sources/TGBridgeBotCommandInfo.h deleted file mode 100644 index fe6f72e1a0..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeBotCommandInfo.h +++ /dev/null @@ -1,12 +0,0 @@ -#import - -@interface TGBridgeBotCommandInfo : NSObject -{ - NSString *_command; - NSString *_commandDescription; -} - -@property (nonatomic, readonly) NSString *command; -@property (nonatomic, readonly) NSString *commandDescription; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeBotCommandInfo.m b/submodules/WatchCommon/Watch/Sources/TGBridgeBotCommandInfo.m deleted file mode 100644 index 0f1e005861..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeBotCommandInfo.m +++ /dev/null @@ -1,25 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeBotInfo.h b/submodules/WatchCommon/Watch/Sources/TGBridgeBotInfo.h deleted file mode 100644 index 0dafae5cef..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeBotInfo.h +++ /dev/null @@ -1,12 +0,0 @@ -#import - -@interface TGBridgeBotInfo : NSObject -{ - NSString *_shortDescription; - NSArray *_commandList; -} - -@property (nonatomic, readonly) NSString *shortDescription; -@property (nonatomic, readonly) NSArray *commandList; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeBotInfo.m b/submodules/WatchCommon/Watch/Sources/TGBridgeBotInfo.m deleted file mode 100644 index 996abb3a95..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeBotInfo.m +++ /dev/null @@ -1,25 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeChat.h b/submodules/WatchCommon/Watch/Sources/TGBridgeChat.h deleted file mode 100644 index d326e18fcf..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeChat.h +++ /dev/null @@ -1,46 +0,0 @@ -#import -#import - -@interface TGBridgeChat : NSObject - -@property (nonatomic) int64_t identifier; -@property (nonatomic) NSTimeInterval date; -@property (nonatomic) int32_t fromUid; -@property (nonatomic, strong) NSString *text; - -@property (nonatomic, strong) NSArray *media; - -@property (nonatomic) bool outgoing; -@property (nonatomic) bool unread; -@property (nonatomic) bool deliveryError; -@property (nonatomic) TGBridgeMessageDeliveryState deliveryState; - -@property (nonatomic) int32_t unreadCount; - -@property (nonatomic) bool isBroadcast; - -@property (nonatomic, strong) NSString *groupTitle; -@property (nonatomic, strong) NSString *groupPhotoSmall; -@property (nonatomic, strong) NSString *groupPhotoBig; - -@property (nonatomic) bool isGroup; -@property (nonatomic) bool hasLeftGroup; -@property (nonatomic) bool isKickedFromGroup; - -@property (nonatomic) bool isChannel; -@property (nonatomic) bool isChannelGroup; - -@property (nonatomic, strong) NSString *userName; -@property (nonatomic, strong) NSString *about; -@property (nonatomic) bool verified; - -@property (nonatomic) int32_t participantsCount; -@property (nonatomic, strong) NSArray *participants; - -- (NSIndexSet *)involvedUserIds; -- (NSIndexSet *)participantsUserIds; - -@end - -extern NSString *const TGBridgeChatKey; -extern NSString *const TGBridgeChatsArrayKey; diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeChat.m b/submodules/WatchCommon/Watch/Sources/TGBridgeChat.m deleted file mode 100644 index 4ea9552f08..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeChat.m +++ /dev/null @@ -1,139 +0,0 @@ -#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]; -} - -- (NSIndexSet *)involvedUserIds -{ - NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; - if (!self.isGroup && !self.isChannel && self.identifier != 0) - [userIds addIndex:(int32_t)self.identifier]; - if ((!self.isChannel || self.isChannelGroup) && self.fromUid != self.identifier && self.fromUid != 0 && !TGPeerIdIsChannel(self.fromUid) && self.fromUid > 0) - [userIds addIndex:(int32_t)self.fromUid]; - - for (TGBridgeMediaAttachment *attachment in self.media) - { - if ([attachment isKindOfClass:[TGBridgeActionMediaAttachment class]]) - { - TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment; - if (actionAttachment.actionData[@"uid"] != nil) - [userIds addIndex:[actionAttachment.actionData[@"uid"] integerValue]]; - } - } - - return userIds; -} - -- (NSIndexSet *)participantsUserIds -{ - NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; - - for (NSNumber *uid in self.participants) - [userIds addIndex:uid.unsignedIntegerValue]; - - return userIds; -} - -- (BOOL)isEqual:(id)object -{ - if (object == self) - return YES; - - if (!object || ![object isKindOfClass:[self class]]) - return NO; - - return self.identifier == ((TGBridgeChat *)object).identifier; -} - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeChatMessages.h b/submodules/WatchCommon/Watch/Sources/TGBridgeChatMessages.h deleted file mode 100644 index b185037e4d..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeChatMessages.h +++ /dev/null @@ -1,14 +0,0 @@ -#import - -@class SSignal; - -@interface TGBridgeChatMessages : NSObject -{ - NSArray *_messages; -} - -@property (nonatomic, readonly) NSArray *messages; - -@end - -extern NSString *const TGBridgeChatMessageListViewKey; diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeChatMessages.m b/submodules/WatchCommon/Watch/Sources/TGBridgeChatMessages.m deleted file mode 100644 index c7b64e2c13..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeChatMessages.m +++ /dev/null @@ -1,27 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeCommon.h b/submodules/WatchCommon/Watch/Sources/TGBridgeCommon.h deleted file mode 100644 index fe0510c041..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeCommon.h +++ /dev/null @@ -1,95 +0,0 @@ -#import - -extern NSString *const TGBridgeIncomingFileTypeKey; -extern NSString *const TGBridgeIncomingFileIdentifierKey; -extern NSString *const TGBridgeIncomingFileRandomIdKey; -extern NSString *const TGBridgeIncomingFilePeerIdKey; -extern NSString *const TGBridgeIncomingFileReplyToMidKey; - -extern NSString *const TGBridgeIncomingFileTypeAudio; -extern NSString *const TGBridgeIncomingFileTypeImage; - -@interface TGBridgeSubscription : NSObject - -@property (nonatomic, readonly) int64_t identifier; -@property (nonatomic, readonly, strong) NSString *name; - -@property (nonatomic, readonly) bool isOneTime; -@property (nonatomic, readonly) bool renewable; -@property (nonatomic, readonly) bool dropPreviouslyQueued; -@property (nonatomic, readonly) bool synchronous; - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder; -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder; - -+ (NSString *)subscriptionName; - -@end - - -@interface TGBridgeDisposal : NSObject - -@property (nonatomic, readonly) int64_t identifier; - -- (instancetype)initWithIdentifier:(int64_t)identifier; - -@end - - -@interface TGBridgeFile : NSObject - -@property (nonatomic, readonly, strong) NSData *data; -@property (nonatomic, readonly, strong) NSDictionary *metadata; - -- (instancetype)initWithData:(NSData *)data metadata:(NSDictionary *)metadata; - -@end - - -@interface TGBridgePing : NSObject - -@property (nonatomic, readonly) int32_t sessionId; - -- (instancetype)initWithSessionId:(int32_t)sessionId; - -@end - - -@interface TGBridgeSubscriptionListRequest : NSObject - -@property (nonatomic, readonly) int32_t sessionId; - -- (instancetype)initWithSessionId:(int32_t)sessionId; - -@end - - -@interface TGBridgeSubscriptionList : NSObject - -@property (nonatomic, readonly, strong) NSArray *subscriptions; - -- (instancetype)initWithArray:(NSArray *)array; - -@end - - -typedef NS_ENUM(int32_t, TGBridgeResponseType) { - TGBridgeResponseTypeUndefined, - TGBridgeResponseTypeNext, - TGBridgeResponseTypeFailed, - TGBridgeResponseTypeCompleted -}; - -@interface TGBridgeResponse : NSObject - -@property (nonatomic, readonly) int64_t subscriptionIdentifier; - -@property (nonatomic, readonly) TGBridgeResponseType type; -@property (nonatomic, readonly, strong) id next; -@property (nonatomic, readonly, strong) NSString *error; - -+ (TGBridgeResponse *)single:(id)next forSubscription:(TGBridgeSubscription *)subscription; -+ (TGBridgeResponse *)fail:(id)error forSubscription:(TGBridgeSubscription *)subscription; -+ (TGBridgeResponse *)completeForSubscription:(TGBridgeSubscription *)subscription; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeCommon.m b/submodules/WatchCommon/Watch/Sources/TGBridgeCommon.m deleted file mode 100644 index ae0cf5300b..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeCommon.m +++ /dev/null @@ -1,295 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeContactMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeContactMediaAttachment.h deleted file mode 100644 index a8531272d8..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeContactMediaAttachment.h +++ /dev/null @@ -1,13 +0,0 @@ -#import - -@interface TGBridgeContactMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int32_t uid; -@property (nonatomic, strong) NSString *firstName; -@property (nonatomic, strong) NSString *lastName; -@property (nonatomic, strong) NSString *phoneNumber; -@property (nonatomic, strong) NSString *prettyPhoneNumber; - -- (NSString *)displayName; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeContactMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeContactMediaAttachment.m deleted file mode 100644 index 4b2f482eaa..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeContactMediaAttachment.m +++ /dev/null @@ -1,60 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeContext.h b/submodules/WatchCommon/Watch/Sources/TGBridgeContext.h deleted file mode 100644 index 45225a04f6..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeContext.h +++ /dev/null @@ -1,18 +0,0 @@ -#import - -@interface TGBridgeContext : NSObject - -@property (nonatomic, readonly) bool authorized; -@property (nonatomic, readonly) int32_t userId; -@property (nonatomic, readonly) bool micAccessAllowed; -@property (nonatomic, readonly) NSDictionary *preheatData; -@property (nonatomic, readonly) NSInteger preheatVersion; - -- (instancetype)initWithDictionary:(NSDictionary *)dictionary; -- (NSDictionary *)dictionary; - -- (TGBridgeContext *)updatedWithAuthorized:(bool)authorized peerId:(int32_t)peerId; -- (TGBridgeContext *)updatedWithPreheatData:(NSDictionary *)data; -- (TGBridgeContext *)updatedWithMicAccessAllowed:(bool)allowed; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeContext.m b/submodules/WatchCommon/Watch/Sources/TGBridgeContext.m deleted file mode 100644 index 4b0600e2fc..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeContext.m +++ /dev/null @@ -1,101 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeDocumentMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeDocumentMediaAttachment.h deleted file mode 100644 index da96a2ba22..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeDocumentMediaAttachment.h +++ /dev/null @@ -1,23 +0,0 @@ -#import - -@interface TGBridgeDocumentMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t documentId; -@property (nonatomic, assign) int64_t localDocumentId; -@property (nonatomic, assign) int32_t fileSize; - -@property (nonatomic, strong) NSString *fileName; -@property (nonatomic, strong) NSValue *imageSize; -@property (nonatomic, assign) bool isAnimated; -@property (nonatomic, assign) bool isSticker; -@property (nonatomic, strong) NSString *stickerAlt; -@property (nonatomic, assign) int64_t stickerPackId; -@property (nonatomic, assign) int64_t stickerPackAccessHash; - -@property (nonatomic, assign) bool isVoice; -@property (nonatomic, assign) bool isAudio; -@property (nonatomic, strong) NSString *title; -@property (nonatomic, strong) NSString *performer; -@property (nonatomic, assign) int32_t duration; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeDocumentMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeDocumentMediaAttachment.m deleted file mode 100644 index 8d492ae704..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeDocumentMediaAttachment.m +++ /dev/null @@ -1,84 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeForwardedMessageMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeForwardedMessageMediaAttachment.h deleted file mode 100644 index 7077334864..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeForwardedMessageMediaAttachment.h +++ /dev/null @@ -1,9 +0,0 @@ -#import - -@interface TGBridgeForwardedMessageMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t peerId; -@property (nonatomic, assign) int32_t mid; -@property (nonatomic, assign) int32_t date; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeForwardedMessageMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeForwardedMessageMediaAttachment.m deleted file mode 100644 index 169e261cff..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeForwardedMessageMediaAttachment.m +++ /dev/null @@ -1,35 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeImageMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeImageMediaAttachment.h deleted file mode 100644 index 2a428dc15a..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeImageMediaAttachment.h +++ /dev/null @@ -1,10 +0,0 @@ -#import - -#import - -@interface TGBridgeImageMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t imageId; -@property (nonatomic, assign) CGSize dimensions; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeImageMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeImageMediaAttachment.m deleted file mode 100644 index 8ab5ec7044..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeImageMediaAttachment.m +++ /dev/null @@ -1,33 +0,0 @@ -#import "TGBridgeImageMediaAttachment.h" -#import - -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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeLocationMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeLocationMediaAttachment.h deleted file mode 100644 index bba943c11c..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeLocationMediaAttachment.h +++ /dev/null @@ -1,19 +0,0 @@ -#import - -@interface TGBridgeVenueAttachment : NSObject - -@property (nonatomic, strong) NSString *title; -@property (nonatomic, strong) NSString *address; -@property (nonatomic, strong) NSString *provider; -@property (nonatomic, strong) NSString *venueId; - -@end - -@interface TGBridgeLocationMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) double latitude; -@property (nonatomic, assign) double longitude; - -@property (nonatomic, strong) TGBridgeVenueAttachment *venue; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeLocationMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeLocationMediaAttachment.m deleted file mode 100644 index f6762eb549..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeLocationMediaAttachment.m +++ /dev/null @@ -1,95 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeLocationVenue.h b/submodules/WatchCommon/Watch/Sources/TGBridgeLocationVenue.h deleted file mode 100644 index c626f76f9c..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeLocationVenue.h +++ /dev/null @@ -1,15 +0,0 @@ -#import - -@class TGBridgeLocationMediaAttachment; - -@interface TGBridgeLocationVenue : NSObject - -@property (nonatomic) CLLocationCoordinate2D coordinate; -@property (nonatomic, strong) NSString *identifier; -@property (nonatomic, strong) NSString *provider; -@property (nonatomic, strong) NSString *name; -@property (nonatomic, strong) NSString *address; - -- (TGBridgeLocationMediaAttachment *)locationAttachment; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeLocationVenue.m b/submodules/WatchCommon/Watch/Sources/TGBridgeLocationVenue.m deleted file mode 100644 index 01c8fc8c1a..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeLocationVenue.m +++ /dev/null @@ -1,66 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeMediaAttachment.h deleted file mode 100644 index 3a564e1575..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeMediaAttachment.h +++ /dev/null @@ -1,11 +0,0 @@ -#import - -@interface TGBridgeMediaAttachment : NSObject - -@property (nonatomic, readonly) NSInteger mediaType; - -+ (NSInteger)mediaType; - -@end - -extern NSString *const TGBridgeMediaAttachmentTypeKey; diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeMediaAttachment.m deleted file mode 100644 index 971a23b64d..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeMediaAttachment.m +++ /dev/null @@ -1,32 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeMessage.h b/submodules/WatchCommon/Watch/Sources/TGBridgeMessage.h deleted file mode 100644 index 59ec1178d2..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeMessage.h +++ /dev/null @@ -1,65 +0,0 @@ -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import - -typedef enum { - TGBridgeTextCheckingResultTypeUndefined, - TGBridgeTextCheckingResultTypeBold, - TGBridgeTextCheckingResultTypeItalic, - TGBridgeTextCheckingResultTypeCode, - TGBridgeTextCheckingResultTypePre -} TGBridgeTextCheckingResultType; - -@interface TGBridgeTextCheckingResult : NSObject - -@property (nonatomic, assign) TGBridgeTextCheckingResultType type; -@property (nonatomic, assign) NSRange range; - -@end - - -typedef NS_ENUM(NSUInteger, TGBridgeMessageDeliveryState) { - TGBridgeMessageDeliveryStateDelivered = 0, - TGBridgeMessageDeliveryStatePending = 1, - TGBridgeMessageDeliveryStateFailed = 2 -}; - -@interface TGBridgeMessage : NSObject - -@property (nonatomic) int32_t identifier; -@property (nonatomic) NSTimeInterval date; -@property (nonatomic) int64_t randomId; -@property (nonatomic) bool unread; -@property (nonatomic) bool deliveryError; -@property (nonatomic) TGBridgeMessageDeliveryState deliveryState; -@property (nonatomic) bool outgoing; -@property (nonatomic) int64_t fromUid; -@property (nonatomic) int64_t toUid; -@property (nonatomic) int64_t cid; -@property (nonatomic, strong) NSString *text; -@property (nonatomic, strong) NSArray *media; -@property (nonatomic) bool forceReply; - -- (NSIndexSet *)involvedUserIds; -- (NSArray *)textCheckingResults; - -+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId; -+ (instancetype)temporaryNewMessageForText:(NSString *)text userId:(int32_t)userId replyToMessage:(TGBridgeMessage *)replyToMessage; -+ (instancetype)temporaryNewMessageForSticker:(TGBridgeDocumentMediaAttachment *)sticker userId:(int32_t)userId; -+ (instancetype)temporaryNewMessageForLocation:(TGBridgeLocationMediaAttachment *)location userId:(int32_t)userId; -+ (instancetype)temporaryNewMessageForAudioWithDuration:(int32_t)duration userId:(int32_t)userId localAudioId:(int64_t)localAudioId; - -@end - -extern NSString *const TGBridgeMessageKey; -extern NSString *const TGBridgeMessagesArrayKey; diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeMessage.m b/submodules/WatchCommon/Watch/Sources/TGBridgeMessage.m deleted file mode 100644 index 4f5e5bb6e7..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeMessage.m +++ /dev/null @@ -1,238 +0,0 @@ -#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]; -} - -- (NSIndexSet *)involvedUserIds -{ - NSMutableIndexSet *userIds = [[NSMutableIndexSet alloc] init]; - if (!TGPeerIdIsChannel(self.fromUid)) - [userIds addIndex:(int32_t)self.fromUid]; - - for (TGBridgeMediaAttachment *attachment in self.media) - { - if ([attachment isKindOfClass:[TGBridgeContactMediaAttachment class]]) - { - TGBridgeContactMediaAttachment *contactAttachment = (TGBridgeContactMediaAttachment *)attachment; - if (contactAttachment.uid != 0) - [userIds addIndex:contactAttachment.uid]; - } - else if ([attachment isKindOfClass:[TGBridgeForwardedMessageMediaAttachment class]]) - { - TGBridgeForwardedMessageMediaAttachment *forwardAttachment = (TGBridgeForwardedMessageMediaAttachment *)attachment; - if (forwardAttachment.peerId != 0 && !TGPeerIdIsChannel(forwardAttachment.peerId)) - [userIds addIndex:(int32_t)forwardAttachment.peerId]; - } - else if ([attachment isKindOfClass:[TGBridgeReplyMessageMediaAttachment class]]) - { - TGBridgeReplyMessageMediaAttachment *replyAttachment = (TGBridgeReplyMessageMediaAttachment *)attachment; - if (replyAttachment.message != nil && !TGPeerIdIsChannel(replyAttachment.message.fromUid)) - [userIds addIndex:(int32_t)replyAttachment.message.fromUid]; - } - else if ([attachment isKindOfClass:[TGBridgeActionMediaAttachment class]]) - { - TGBridgeActionMediaAttachment *actionAttachment = (TGBridgeActionMediaAttachment *)attachment; - if (actionAttachment.actionData[@"uid"] != nil) - [userIds addIndex:(int32_t)[actionAttachment.actionData[@"uid"] intValue]]; - } - } - - return userIds; -} - -- (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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntities.h b/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntities.h deleted file mode 100644 index 669ff3b21d..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntities.h +++ /dev/null @@ -1,59 +0,0 @@ -#import - -@interface TGBridgeMessageEntity : NSObject - -@property (nonatomic, assign) NSRange range; - -+ (instancetype)entitityWithRange:(NSRange)range; - -@end - - -@interface TGBridgeMessageEntityUrl : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityEmail : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityTextUrl : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityMention : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityHashtag : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityBotCommand : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityBold : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityItalic : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityCode : TGBridgeMessageEntity - -@end - - -@interface TGBridgeMessageEntityPre : TGBridgeMessageEntity - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntities.m b/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntities.m deleted file mode 100644 index 8d639a9468..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntities.m +++ /dev/null @@ -1,83 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntitiesAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntitiesAttachment.h deleted file mode 100644 index 9aaec90b25..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntitiesAttachment.h +++ /dev/null @@ -1,8 +0,0 @@ -#import -#import - -@interface TGBridgeMessageEntitiesAttachment : TGBridgeMediaAttachment - -@property (nonatomic, strong) NSArray *entities; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntitiesAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntitiesAttachment.m deleted file mode 100644 index fb5cb3b7d7..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeMessageEntitiesAttachment.m +++ /dev/null @@ -1,30 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgePeerIdAdapter.h b/submodules/WatchCommon/Watch/Sources/TGBridgePeerIdAdapter.h deleted file mode 100644 index c5f0ac92fc..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgePeerIdAdapter.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef Telegraph_TGPeerIdAdapter_h -#define Telegraph_TGPeerIdAdapter_h - -static inline bool TGPeerIdIsGroup(int64_t peerId) { - return peerId < 0 && peerId > INT32_MIN; -} - -static inline bool TGPeerIdIsUser(int64_t peerId) { - return peerId > 0 && peerId < INT32_MAX; -} - -static inline bool TGPeerIdIsChannel(int64_t peerId) { - return peerId <= ((int64_t)INT32_MIN) * 2 && peerId > ((int64_t)INT32_MIN) * 3; -} - -static inline bool TGPeerIdIsAdminLog(int64_t peerId) { - return peerId <= ((int64_t)INT32_MIN) * 3 && peerId > ((int64_t)INT32_MIN) * 4; -} - -static inline int32_t TGChannelIdFromPeerId(int64_t peerId) { - if (TGPeerIdIsChannel(peerId)) { - return (int32_t)(((int64_t)INT32_MIN) * 2 - peerId); - } else { - return 0; - } -} - -static inline int64_t TGPeerIdFromChannelId(int32_t channelId) { - return ((int64_t)INT32_MIN) * 2 - ((int64_t)channelId); -} - -static inline int64_t TGPeerIdFromAdminLogId(int32_t channelId) { - return ((int64_t)INT32_MIN) * 3 - ((int64_t)channelId); -} - -static inline int64_t TGPeerIdFromGroupId(int32_t groupId) { - return -groupId; -} - -static inline int32_t TGGroupIdFromPeerId(int64_t peerId) { - if (TGPeerIdIsGroup(peerId)) { - return (int32_t)-peerId; - } else { - return 0; - } -} - -static inline bool TGPeerIdIsSecretChat(int64_t peerId) { - return peerId <= ((int64_t)INT32_MIN) && peerId > ((int64_t)INT32_MIN) * 2; -} - -#endif diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgePeerNotificationSettings.h b/submodules/WatchCommon/Watch/Sources/TGBridgePeerNotificationSettings.h deleted file mode 100644 index fce723cecb..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgePeerNotificationSettings.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface TGBridgePeerNotificationSettings : NSObject - -@property (nonatomic, assign) int32_t muteFor; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgePeerNotificationSettings.m b/submodules/WatchCommon/Watch/Sources/TGBridgePeerNotificationSettings.m deleted file mode 100644 index 662c2f4ca4..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgePeerNotificationSettings.m +++ /dev/null @@ -1,22 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMarkupMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMarkupMediaAttachment.h deleted file mode 100644 index 430398271a..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMarkupMediaAttachment.h +++ /dev/null @@ -1,9 +0,0 @@ -#import - -@class TGBridgeBotReplyMarkup; - -@interface TGBridgeReplyMarkupMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, strong) TGBridgeBotReplyMarkup *replyMarkup; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMarkupMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMarkupMediaAttachment.m deleted file mode 100644 index 1299c900cd..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMarkupMediaAttachment.m +++ /dev/null @@ -1,29 +0,0 @@ -#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 \ No newline at end of file diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMessageMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMessageMediaAttachment.h deleted file mode 100644 index a5dbeae13c..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMessageMediaAttachment.h +++ /dev/null @@ -1,10 +0,0 @@ -#import - -@class TGBridgeMessage; - -@interface TGBridgeReplyMessageMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int32_t mid; -@property (nonatomic, strong) TGBridgeMessage *message; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMessageMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMessageMediaAttachment.m deleted file mode 100644 index fbc2456919..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeReplyMessageMediaAttachment.m +++ /dev/null @@ -1,33 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeSubscriptions.h b/submodules/WatchCommon/Watch/Sources/TGBridgeSubscriptions.h deleted file mode 100644 index f2f7ec7ac5..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeSubscriptions.h +++ /dev/null @@ -1,268 +0,0 @@ -#import - -#import -#import - -@class TGBridgeMediaAttachment; -@class TGBridgeImageMediaAttachment; -@class TGBridgeVideoMediaAttachment; -@class TGBridgeDocumentMediaAttachment; -@class TGBridgeLocationMediaAttachment; -@class TGBridgePeerNotificationSettings; - -@interface TGBridgeAudioSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) TGBridgeMediaAttachment *attachment; -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; - -- (instancetype)initWithAttachment:(TGBridgeMediaAttachment *)attachment peerId:(int64_t)peerId messageId:(int32_t)messageId; - -@end - - -@interface TGBridgeAudioSentSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t conversationId; - -- (instancetype)initWithConversationId:(int64_t)conversationId; - -@end - - -@interface TGBridgeChatListSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int32_t limit; - -- (instancetype)initWithLimit:(int32_t)limit; - -@end - - -@interface TGBridgeChatMessageListSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t atMessageId; -@property (nonatomic, readonly) NSUInteger rangeMessageCount; - -- (instancetype)initWithPeerId:(int64_t)peerId atMessageId:(int32_t)messageId rangeMessageCount:(NSUInteger)rangeMessageCount; - -@end - - -@interface TGBridgeChatMessageSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId; - -@end - - -@interface TGBridgeReadChatMessageListSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId; - -@end - - -@interface TGBridgeContactsSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) NSString *query; - -- (instancetype)initWithQuery:(NSString *)query; - -@end - - -@interface TGBridgeConversationSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; - -- (instancetype)initWithPeerId:(int64_t)peerId; - -@end - - -@interface TGBridgeNearbyVenuesSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; -@property (nonatomic, readonly) int32_t limit; - -- (instancetype)initWithCoordinate:(CLLocationCoordinate2D)coordinate limit:(int32_t)limit; - -@end - - -@interface TGBridgeMediaThumbnailSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; -@property (nonatomic, readonly) CGSize size; -@property (nonatomic, readonly) bool notification; - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId size:(CGSize)size notification:(bool)notification; - -@end - - -typedef NS_ENUM(NSUInteger, TGBridgeMediaAvatarType) { - TGBridgeMediaAvatarTypeSmall, - TGBridgeMediaAvatarTypeProfile, - TGBridgeMediaAvatarTypeLarge -}; - -@interface TGBridgeMediaAvatarSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) NSString *url; -@property (nonatomic, readonly) TGBridgeMediaAvatarType type; - -- (instancetype)initWithPeerId:(int64_t)peerId url:(NSString *)url type:(TGBridgeMediaAvatarType)type; - -@end - -@interface TGBridgeMediaStickerSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t documentId; -@property (nonatomic, readonly) int64_t stickerPackId; -@property (nonatomic, readonly) int64_t stickerPackAccessHash; -@property (nonatomic, readonly) int64_t stickerPeerId; -@property (nonatomic, readonly) int32_t stickerMessageId; -@property (nonatomic, readonly) bool notification; -@property (nonatomic, readonly) CGSize size; - -- (instancetype)initWithDocumentId:(int64_t)documentId stickerPackId:(int64_t)stickerPackId stickerPackAccessHash:(int64_t)stickerPackAccessHash stickerPeerId:(int64_t)stickerPeerId stickerMessageId:(int32_t)stickerMessageId notification:(bool)notification size:(CGSize)size; - -@end - - -@interface TGBridgePeerSettingsSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; - -- (instancetype)initWithPeerId:(int64_t)peerId; - -@end - -@interface TGBridgePeerUpdateNotificationSettingsSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; - -- (instancetype)initWithPeerId:(int64_t)peerId; - -@end - -@interface TGBridgePeerUpdateBlockStatusSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) bool blocked; - -- (instancetype)initWithPeerId:(int64_t)peerId blocked:(bool)blocked; - -@end - - -@interface TGBridgeRemoteSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; -@property (nonatomic, readonly) int32_t type; -@property (nonatomic, readonly) bool autoPlay; - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId type:(int32_t)type autoPlay:(bool)autoPlay; - -@end - - -@interface TGBridgeSendTextMessageSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) NSString *text; -@property (nonatomic, readonly) int32_t replyToMid; - -- (instancetype)initWithPeerId:(int64_t)peerId text:(NSString *)text replyToMid:(int32_t)replyToMid; - -@end - - -@interface TGBridgeSendStickerMessageSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) TGBridgeDocumentMediaAttachment *document; -@property (nonatomic, readonly) int32_t replyToMid; - -- (instancetype)initWithPeerId:(int64_t)peerId document:(TGBridgeDocumentMediaAttachment *)document replyToMid:(int32_t)replyToMid; - -@end - - -@interface TGBridgeSendLocationMessageSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) TGBridgeLocationMediaAttachment *location; -@property (nonatomic, readonly) int32_t replyToMid; - -- (instancetype)initWithPeerId:(int64_t)peerId location:(TGBridgeLocationMediaAttachment *)location replyToMid:(int32_t)replyToMid; - -@end - - -@interface TGBridgeSendForwardedMessageSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; -@property (nonatomic, readonly) int32_t messageId; -@property (nonatomic, readonly) int64_t targetPeerId; - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId targetPeerId:(int64_t)targetPeerId; - -@end - - -@interface TGBridgeStateSubscription : TGBridgeSubscription - -@end - - -@interface TGBridgeStickerPacksSubscription : TGBridgeSubscription - -@end - - -@interface TGBridgeRecentStickersSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int32_t limit; - -- (instancetype)initWithLimit:(int32_t)limit; - -@end - - -@interface TGBridgeUserInfoSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) NSArray *userIds; - -- (instancetype)initWithUserIds:(NSArray *)userIds; - -@end - - -@interface TGBridgeUserBotInfoSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) NSArray *userIds; - -- (instancetype)initWithUserIds:(NSArray *)userIds; - -@end - -@interface TGBridgeBotReplyMarkupSubscription : TGBridgeSubscription - -@property (nonatomic, readonly) int64_t peerId; - -- (instancetype)initWithPeerId:(int64_t)peerId; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeSubscriptions.m b/submodules/WatchCommon/Watch/Sources/TGBridgeSubscriptions.m deleted file mode 100644 index 8c4b50d224..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeSubscriptions.m +++ /dev/null @@ -1,1048 +0,0 @@ -#import "TGBridgeSubscriptions.h" - -#import - -#import "TGBridgeImageMediaAttachment.h" -#import "TGBridgeVideoMediaAttachment.h" -#import "TGBridgeDocumentMediaAttachment.h" -#import "TGBridgeLocationMediaAttachment.h" -#import "TGBridgePeerNotificationSettings.h" - -NSString *const TGBridgeAudioSubscriptionName = @"media.audio"; -NSString *const TGBridgeAudioSubscriptionAttachmentKey = @"attachment"; -NSString *const TGBridgeAudioSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeAudioSubscriptionMessageIdKey = @"messageId"; - -@implementation TGBridgeAudioSubscription - -- (instancetype)initWithAttachment:(TGBridgeMediaAttachment *)attachment peerId:(int64_t)peerId messageId:(int32_t)messageId -{ - self = [super init]; - if (self != nil) - { - _attachment = attachment; - _peerId = peerId; - _messageId = messageId; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeObject:self.attachment forKey:TGBridgeAudioSubscriptionAttachmentKey]; - [aCoder encodeInt64:self.peerId forKey:TGBridgeAudioSubscriptionPeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeAudioSubscriptionMessageIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _attachment = [aDecoder decodeObjectForKey:TGBridgeAudioSubscriptionAttachmentKey]; - _peerId = [aDecoder decodeInt64ForKey:TGBridgeAudioSubscriptionPeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeAudioSubscriptionMessageIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeAudioSubscriptionName; -} - -@end - - -NSString *const TGBridgeAudioSentSubscriptionName = @"media.audioSent"; -NSString *const TGBridgeAudioSentSubscriptionConversationIdKey = @"conversationId"; - -@implementation TGBridgeAudioSentSubscription - -- (instancetype)initWithConversationId:(int64_t)conversationId -{ - self = [super init]; - if (self != nil) - { - _conversationId = conversationId; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.conversationId forKey:TGBridgeAudioSentSubscriptionConversationIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _conversationId = [aDecoder decodeInt64ForKey:TGBridgeAudioSentSubscriptionConversationIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeAudioSentSubscriptionName; -} - -@end - - -NSString *const TGBridgeChatListSubscriptionName = @"chats.chatList"; -NSString *const TGBridgeChatListSubscriptionLimitKey = @"limit"; - -@implementation TGBridgeChatListSubscription - -- (instancetype)initWithLimit:(int32_t)limit -{ - self = [super init]; - if (self != nil) - { - _limit = limit; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt32:self.limit forKey:TGBridgeChatListSubscriptionLimitKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _limit = [aDecoder decodeInt32ForKey:TGBridgeChatListSubscriptionLimitKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeChatListSubscriptionName; -} - -@end - - -NSString *const TGBridgeChatMessageListSubscriptionName = @"chats.chatMessageList"; -NSString *const TGBridgeChatMessageListSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeChatMessageListSubscriptionAtMessageIdKey = @"atMessageId"; -NSString *const TGBridgeChatMessageListSubscriptionRangeMessageCountKey = @"rangeMessageCount"; - -@implementation TGBridgeChatMessageListSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId atMessageId:(int32_t)messageId rangeMessageCount:(NSUInteger)rangeMessageCount -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _atMessageId = messageId; - _rangeMessageCount = rangeMessageCount; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeChatMessageListSubscriptionPeerIdKey]; - [aCoder encodeInt32:self.atMessageId forKey:TGBridgeChatMessageListSubscriptionAtMessageIdKey]; - [aCoder encodeInt32:(int32_t)self.rangeMessageCount forKey:TGBridgeChatMessageListSubscriptionRangeMessageCountKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeChatMessageListSubscriptionPeerIdKey]; - _atMessageId = [aDecoder decodeInt32ForKey:TGBridgeChatMessageListSubscriptionAtMessageIdKey]; - _rangeMessageCount = [aDecoder decodeInt32ForKey:TGBridgeChatMessageListSubscriptionRangeMessageCountKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeChatMessageListSubscriptionName; -} - -@end - - -NSString *const TGBridgeChatMessageSubscriptionName = @"chats.message"; -NSString *const TGBridgeChatMessageSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeChatMessageSubscriptionMessageIdKey = @"mid"; - -@implementation TGBridgeChatMessageSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _messageId = messageId; - } - return self; -} - -- (bool)synchronous -{ - return true; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeChatMessageSubscriptionPeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeChatMessageSubscriptionMessageIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeChatMessageSubscriptionPeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeChatMessageSubscriptionMessageIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeChatMessageSubscriptionName; -} - -@end - - -NSString *const TGBridgeReadChatMessageListSubscriptionName = @"chats.readChatMessageList"; -NSString *const TGBridgeReadChatMessageListSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeReadChatMessageListSubscriptionMessageIdKey = @"mid"; - -@implementation TGBridgeReadChatMessageListSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _messageId = messageId; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeReadChatMessageListSubscriptionPeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeReadChatMessageListSubscriptionMessageIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeReadChatMessageListSubscriptionPeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeReadChatMessageListSubscriptionMessageIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeReadChatMessageListSubscriptionName; -} - -@end - - -NSString *const TGBridgeContactsSubscriptionName = @"contacts.search"; -NSString *const TGBridgeContactsSubscriptionQueryKey = @"query"; - -@implementation TGBridgeContactsSubscription - -- (instancetype)initWithQuery:(NSString *)query -{ - self = [super init]; - if (self != nil) - { - _query = query; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeObject:self.query forKey:TGBridgeContactsSubscriptionQueryKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _query = [aDecoder decodeObjectForKey:TGBridgeContactsSubscriptionQueryKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeContactsSubscriptionName; -} - -@end - - -NSString *const TGBridgeConversationSubscriptionName = @"chats.conversation"; -NSString *const TGBridgeConversationSubscriptionPeerIdKey = @"peerId"; - -@implementation TGBridgeConversationSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeConversationSubscriptionPeerIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeConversationSubscriptionPeerIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeConversationSubscriptionName; -} - -@end - - -NSString *const TGBridgeNearbyVenuesSubscriptionName = @"location.nearbyVenues"; -NSString *const TGBridgeNearbyVenuesSubscriptionLatitudeKey = @"lat"; -NSString *const TGBridgeNearbyVenuesSubscriptionLongitudeKey = @"lon"; -NSString *const TGBridgeNearbyVenuesSubscriptionLimitKey = @"limit"; - -@implementation TGBridgeNearbyVenuesSubscription - -- (instancetype)initWithCoordinate:(CLLocationCoordinate2D)coordinate limit:(int32_t)limit -{ - self = [super init]; - if (self != nil) - { - _coordinate = coordinate; - _limit = limit; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeDouble:self.coordinate.latitude forKey:TGBridgeNearbyVenuesSubscriptionLatitudeKey]; - [aCoder encodeDouble:self.coordinate.longitude forKey:TGBridgeNearbyVenuesSubscriptionLongitudeKey]; - [aCoder encodeInt32:self.limit forKey:TGBridgeNearbyVenuesSubscriptionLimitKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _coordinate = CLLocationCoordinate2DMake([aDecoder decodeDoubleForKey:TGBridgeNearbyVenuesSubscriptionLatitudeKey], - [aDecoder decodeDoubleForKey:TGBridgeNearbyVenuesSubscriptionLongitudeKey]); - _limit = [aDecoder decodeInt32ForKey:TGBridgeNearbyVenuesSubscriptionLimitKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeNearbyVenuesSubscriptionName; -} - -@end - - -NSString *const TGBridgeMediaThumbnailSubscriptionName = @"media.thumbnail"; -NSString *const TGBridgeMediaThumbnailPeerIdKey = @"peerId"; -NSString *const TGBridgeMediaThumbnailMessageIdKey = @"mid"; -NSString *const TGBridgeMediaThumbnailSizeKey = @"size"; -NSString *const TGBridgeMediaThumbnailNotificationKey = @"notification"; - -@implementation TGBridgeMediaThumbnailSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId size:(CGSize)size notification:(bool)notification -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _messageId = messageId; - _size = size; - _notification = notification; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeMediaThumbnailPeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeMediaThumbnailMessageIdKey]; - [aCoder encodeCGSize:self.size forKey:TGBridgeMediaThumbnailSizeKey]; - [aCoder encodeBool:self.notification forKey:TGBridgeMediaThumbnailNotificationKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeMediaThumbnailPeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeMediaThumbnailMessageIdKey]; - _size = [aDecoder decodeCGSizeForKey:TGBridgeMediaThumbnailSizeKey]; - _notification = [aDecoder decodeBoolForKey:TGBridgeMediaThumbnailNotificationKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeMediaThumbnailSubscriptionName; -} - -@end - - -NSString *const TGBridgeMediaAvatarSubscriptionName = @"media.avatar"; -NSString *const TGBridgeMediaAvatarPeerIdKey = @"peerId"; -NSString *const TGBridgeMediaAvatarUrlKey = @"url"; -NSString *const TGBridgeMediaAvatarTypeKey = @"type"; - -@implementation TGBridgeMediaAvatarSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId url:(NSString *)url type:(TGBridgeMediaAvatarType)type -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _url = url; - _type = type; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeMediaAvatarPeerIdKey]; - [aCoder encodeObject:self.url forKey:TGBridgeMediaAvatarUrlKey]; - [aCoder encodeInt32:self.type forKey:TGBridgeMediaAvatarTypeKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeMediaAvatarPeerIdKey]; - _url = [aDecoder decodeObjectForKey:TGBridgeMediaAvatarUrlKey]; - _type = [aDecoder decodeInt32ForKey:TGBridgeMediaAvatarTypeKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeMediaAvatarSubscriptionName; -} - -@end - - -NSString *const TGBridgeMediaStickerSubscriptionName = @"media.sticker"; -NSString *const TGBridgeMediaStickerDocumentIdKey = @"documentId"; -NSString *const TGBridgeMediaStickerPackIdKey = @"packId"; -NSString *const TGBridgeMediaStickerPackAccessHashKey = @"accessHash"; -NSString *const TGBridgeMediaStickerPeerIdKey = @"peerId"; -NSString *const TGBridgeMediaStickerMessageIdKey = @"mid"; -NSString *const TGBridgeMediaStickerNotificationKey = @"notification"; -NSString *const TGBridgeMediaStickerSizeKey = @"size"; - -@implementation TGBridgeMediaStickerSubscription - -- (instancetype)initWithDocumentId:(int64_t)documentId stickerPackId:(int64_t)stickerPackId stickerPackAccessHash:(int64_t)stickerPackAccessHash stickerPeerId:(int64_t)stickerPeerId stickerMessageId:(int32_t)stickerMessageId notification:(bool)notification size:(CGSize)size -{ - self = [super init]; - if (self != nil) - { - _documentId = documentId; - _stickerPackId = stickerPackId; - _stickerPackAccessHash = stickerPackAccessHash; - _stickerPeerId = stickerPeerId; - _stickerMessageId = stickerMessageId; - _notification = notification; - _size = size; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.documentId forKey:TGBridgeMediaStickerDocumentIdKey]; - [aCoder encodeInt64:self.stickerPackId forKey:TGBridgeMediaStickerPackIdKey]; - [aCoder encodeInt64:self.stickerPackAccessHash forKey:TGBridgeMediaStickerPackAccessHashKey]; - [aCoder encodeInt64:self.stickerPeerId forKey:TGBridgeMediaStickerPeerIdKey]; - [aCoder encodeInt32:self.stickerMessageId forKey:TGBridgeMediaStickerMessageIdKey]; - [aCoder encodeBool:self.notification forKey:TGBridgeMediaStickerNotificationKey]; - [aCoder encodeCGSize:self.size forKey:TGBridgeMediaStickerSizeKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _documentId = [aDecoder decodeInt64ForKey:TGBridgeMediaStickerDocumentIdKey]; - _stickerPackId = [aDecoder decodeInt64ForKey:TGBridgeMediaStickerPackIdKey]; - _stickerPackAccessHash = [aDecoder decodeInt64ForKey:TGBridgeMediaStickerPackAccessHashKey]; - _stickerPeerId = [aDecoder decodeInt64ForKey:TGBridgeMediaStickerPeerIdKey]; - _stickerMessageId = [aDecoder decodeInt32ForKey:TGBridgeMediaStickerMessageIdKey]; - _notification = [aDecoder decodeBoolForKey:TGBridgeMediaStickerNotificationKey]; - _size = [aDecoder decodeCGSizeForKey:TGBridgeMediaStickerSizeKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeMediaStickerSubscriptionName; -} - -@end - - -NSString *const TGBridgePeerSettingsSubscriptionName = @"peer.settings"; -NSString *const TGBridgePeerSettingsSubscriptionPeerIdKey = @"peerId"; - -@implementation TGBridgePeerSettingsSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgePeerSettingsSubscriptionPeerIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgePeerSettingsSubscriptionPeerIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgePeerSettingsSubscriptionName; -} - -@end - - -NSString *const TGBridgePeerUpdateNotificationSettingsSubscriptionName = @"peer.notificationSettings"; -NSString *const TGBridgePeerUpdateNotificationSettingsSubscriptionPeerIdKey = @"peerId"; - -@implementation TGBridgePeerUpdateNotificationSettingsSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgePeerUpdateNotificationSettingsSubscriptionPeerIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgePeerUpdateNotificationSettingsSubscriptionPeerIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgePeerUpdateNotificationSettingsSubscriptionName; -} - -@end - - -NSString *const TGBridgePeerUpdateBlockStatusSubscriptionName = @"peer.updateBlocked"; -NSString *const TGBridgePeerUpdateBlockStatusSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgePeerUpdateBlockStatusSubscriptionBlockedKey = @"blocked"; - -@implementation TGBridgePeerUpdateBlockStatusSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId blocked:(bool)blocked -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _blocked = blocked; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgePeerUpdateBlockStatusSubscriptionPeerIdKey]; - [aCoder encodeBool:self.blocked forKey:TGBridgePeerUpdateBlockStatusSubscriptionBlockedKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgePeerUpdateBlockStatusSubscriptionPeerIdKey]; - _blocked = [aDecoder decodeBoolForKey:TGBridgePeerUpdateBlockStatusSubscriptionBlockedKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgePeerUpdateBlockStatusSubscriptionName; -} - -@end - - -NSString *const TGBridgeRemoteSubscriptionName = @"remote.request"; -NSString *const TGBridgeRemotePeerIdKey = @"peerId"; -NSString *const TGBridgeRemoteMessageIdKey = @"mid"; -NSString *const TGBridgeRemoteTypeKey = @"mediaType"; -NSString *const TGBridgeRemoteAutoPlayKey = @"autoPlay"; - -@implementation TGBridgeRemoteSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId type:(int32_t)type autoPlay:(bool)autoPlay -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _messageId = messageId; - _type = type; - _autoPlay = autoPlay; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeRemotePeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeRemoteMessageIdKey]; - [aCoder encodeInt32:self.type forKey:TGBridgeRemoteTypeKey]; - [aCoder encodeBool:self.autoPlay forKey:TGBridgeRemoteAutoPlayKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeRemotePeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeRemoteMessageIdKey]; - _type = [aDecoder decodeInt32ForKey:TGBridgeRemoteTypeKey]; - _autoPlay = [aDecoder decodeBoolForKey:TGBridgeRemoteAutoPlayKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeRemoteSubscriptionName; -} - -@end - - -NSString *const TGBridgeSendTextMessageSubscriptionName = @"sendMessage.text"; -NSString *const TGBridgeSendTextMessageSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeSendTextMessageSubscriptionTextKey = @"text"; -NSString *const TGBridgeSendTextMessageSubscriptionReplyToMidKey = @"replyToMid"; - -@implementation TGBridgeSendTextMessageSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId text:(NSString *)text replyToMid:(int32_t)replyToMid -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _text = text; - _replyToMid = replyToMid; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeSendTextMessageSubscriptionPeerIdKey]; - [aCoder encodeObject:self.text forKey:TGBridgeSendTextMessageSubscriptionTextKey]; - [aCoder encodeInt32:self.replyToMid forKey:TGBridgeSendTextMessageSubscriptionReplyToMidKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeSendTextMessageSubscriptionPeerIdKey]; - _text = [aDecoder decodeObjectForKey:TGBridgeSendTextMessageSubscriptionTextKey]; - _replyToMid = [aDecoder decodeInt32ForKey:TGBridgeSendTextMessageSubscriptionReplyToMidKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeSendTextMessageSubscriptionName; -} - -@end - - -NSString *const TGBridgeSendStickerMessageSubscriptionName = @"sendMessage.sticker"; -NSString *const TGBridgeSendStickerMessageSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeSendStickerMessageSubscriptionDocumentKey = @"document"; -NSString *const TGBridgeSendStickerMessageSubscriptionReplyToMidKey = @"replyToMid"; - -@implementation TGBridgeSendStickerMessageSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId document:(TGBridgeDocumentMediaAttachment *)document replyToMid:(int32_t)replyToMid -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _document = document; - _replyToMid = replyToMid; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeSendStickerMessageSubscriptionPeerIdKey]; - [aCoder encodeObject:self.document forKey:TGBridgeSendStickerMessageSubscriptionDocumentKey]; - [aCoder encodeInt32:self.replyToMid forKey:TGBridgeSendStickerMessageSubscriptionReplyToMidKey]; -} - - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeSendStickerMessageSubscriptionPeerIdKey]; - _document = [aDecoder decodeObjectForKey:TGBridgeSendStickerMessageSubscriptionDocumentKey]; - _replyToMid = [aDecoder decodeInt32ForKey:TGBridgeSendStickerMessageSubscriptionReplyToMidKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeSendStickerMessageSubscriptionName; -} - -@end - - -NSString *const TGBridgeSendLocationMessageSubscriptionName = @"sendMessage.location"; -NSString *const TGBridgeSendLocationMessageSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeSendLocationMessageSubscriptionLocationKey = @"location"; -NSString *const TGBridgeSendLocationMessageSubscriptionReplyToMidKey = @"replyToMid"; - -@implementation TGBridgeSendLocationMessageSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId location:(TGBridgeLocationMediaAttachment *)location replyToMid:(int32_t)replyToMid -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _location = location; - _replyToMid = replyToMid; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeSendLocationMessageSubscriptionPeerIdKey]; - [aCoder encodeObject:self.location forKey:TGBridgeSendLocationMessageSubscriptionLocationKey]; - [aCoder encodeInt32:self.replyToMid forKey:TGBridgeSendLocationMessageSubscriptionReplyToMidKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeSendLocationMessageSubscriptionPeerIdKey]; - _location = [aDecoder decodeObjectForKey:TGBridgeSendLocationMessageSubscriptionLocationKey]; - _replyToMid = [aDecoder decodeInt32ForKey:TGBridgeSendLocationMessageSubscriptionReplyToMidKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeSendLocationMessageSubscriptionName; -} - -@end - - -NSString *const TGBridgeSendForwardedMessageSubscriptionName = @"sendMessage.forward"; -NSString *const TGBridgeSendForwardedMessageSubscriptionPeerIdKey = @"peerId"; -NSString *const TGBridgeSendForwardedMessageSubscriptionMidKey = @"mid"; -NSString *const TGBridgeSendForwardedMessageSubscriptionTargetPeerIdKey = @"targetPeerId"; - -@implementation TGBridgeSendForwardedMessageSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId messageId:(int32_t)messageId targetPeerId:(int64_t)targetPeerId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - _messageId = messageId; - _targetPeerId = targetPeerId; - } - return self; -} - -- (bool)renewable -{ - return false; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeSendForwardedMessageSubscriptionPeerIdKey]; - [aCoder encodeInt32:self.messageId forKey:TGBridgeSendForwardedMessageSubscriptionMidKey]; - [aCoder encodeInt64:self.targetPeerId forKey:TGBridgeSendForwardedMessageSubscriptionTargetPeerIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeSendForwardedMessageSubscriptionPeerIdKey]; - _messageId = [aDecoder decodeInt32ForKey:TGBridgeSendForwardedMessageSubscriptionMidKey]; - _targetPeerId = [aDecoder decodeInt64ForKey:TGBridgeSendForwardedMessageSubscriptionTargetPeerIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeSendForwardedMessageSubscriptionName; -} - -@end - - -NSString *const TGBridgeStateSubscriptionName = @"state.syncState"; - -@implementation TGBridgeStateSubscription - -- (bool)dropPreviouslyQueued -{ - return true; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeStateSubscriptionName; -} - -@end - - -NSString *const TGBridgeStickerPacksSubscriptionName = @"stickers.packs"; - -@implementation TGBridgeStickerPacksSubscription - -+ (NSString *)subscriptionName -{ - return TGBridgeStickerPacksSubscriptionName; -} - -@end - - -NSString *const TGBridgeRecentStickersSubscriptionName = @"stickers.recent"; -NSString *const TGBridgeRecentStickersSubscriptionLimitKey = @"limit"; - -@implementation TGBridgeRecentStickersSubscription - -- (instancetype)initWithLimit:(int32_t)limit -{ - self = [super init]; - if (self != nil) - { - _limit = limit; - } - return self; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt32:self.limit forKey:TGBridgeRecentStickersSubscriptionLimitKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _limit = [aDecoder decodeInt32ForKey:TGBridgeRecentStickersSubscriptionLimitKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeRecentStickersSubscriptionName; -} - -@end - - -NSString *const TGBridgeUserInfoSubscriptionName = @"user.userInfo"; -NSString *const TGBridgeUserInfoSubscriptionUserIdsKey = @"uids"; - -@implementation TGBridgeUserInfoSubscription - -- (instancetype)initWithUserIds:(NSArray *)userIds -{ - self = [super init]; - if (self != nil) - { - _userIds = userIds; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeObject:self.userIds forKey:TGBridgeUserInfoSubscriptionUserIdsKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _userIds = [aDecoder decodeObjectForKey:TGBridgeUserInfoSubscriptionUserIdsKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeUserInfoSubscriptionName; -} - -@end - - -NSString *const TGBridgeUserBotInfoSubscriptionName = @"user.botInfo"; -NSString *const TGBridgeUserBotInfoSubscriptionUserIdsKey = @"uids"; - -@implementation TGBridgeUserBotInfoSubscription - -- (instancetype)initWithUserIds:(NSArray *)userIds -{ - self = [super init]; - if (self != nil) - { - _userIds = userIds; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeObject:self.userIds forKey:TGBridgeUserBotInfoSubscriptionUserIdsKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _userIds = [aDecoder decodeObjectForKey:TGBridgeUserBotInfoSubscriptionUserIdsKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeUserBotInfoSubscriptionName; -} - -@end - - -NSString *const TGBridgeBotReplyMarkupSubscriptionName = @"user.botReplyMarkup"; -NSString *const TGBridgeBotReplyMarkupPeerIdKey = @"peerId"; - -@implementation TGBridgeBotReplyMarkupSubscription - -- (instancetype)initWithPeerId:(int64_t)peerId -{ - self = [super init]; - if (self != nil) - { - _peerId = peerId; - } - return self; -} - -- (bool)dropPreviouslyQueued -{ - return true; -} - -- (void)_serializeParametersWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeInt64:self.peerId forKey:TGBridgeBotReplyMarkupPeerIdKey]; -} - -- (void)_unserializeParametersWithCoder:(NSCoder *)aDecoder -{ - _peerId = [aDecoder decodeInt64ForKey:TGBridgeBotReplyMarkupPeerIdKey]; -} - -+ (NSString *)subscriptionName -{ - return TGBridgeBotReplyMarkupSubscriptionName; -} - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeUnsupportedMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeUnsupportedMediaAttachment.h deleted file mode 100644 index a115df56bf..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeUnsupportedMediaAttachment.h +++ /dev/null @@ -1,9 +0,0 @@ -#import - -@interface TGBridgeUnsupportedMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, strong) NSString *compactTitle; -@property (nonatomic, strong) NSString *title; -@property (nonatomic, strong) NSString *subtitle; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeUnsupportedMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeUnsupportedMediaAttachment.m deleted file mode 100644 index b51e422fd1..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeUnsupportedMediaAttachment.m +++ /dev/null @@ -1,35 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeUser.h b/submodules/WatchCommon/Watch/Sources/TGBridgeUser.h deleted file mode 100644 index 9aca3fa520..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeUser.h +++ /dev/null @@ -1,59 +0,0 @@ -#import - -@class TGBridgeBotInfo; -@class TGBridgeUserChange; - -typedef NS_ENUM(NSUInteger, TGBridgeUserKind) { - TGBridgeUserKindGeneric, - TGBridgeUserKindBot, - TGBridgeUserKindSmartBot -}; - -typedef NS_ENUM(NSUInteger, TGBridgeBotKind) { - TGBridgeBotKindGeneric, - TGBridgeBotKindPrivate -}; - -@interface TGBridgeUser : NSObject - -@property (nonatomic) int64_t identifier; -@property (nonatomic, strong) NSString *firstName; -@property (nonatomic, strong) NSString *lastName; -@property (nonatomic, strong) NSString *userName; -@property (nonatomic, strong) NSString *phoneNumber; -@property (nonatomic, strong) NSString *prettyPhoneNumber; -@property (nonatomic, strong) NSString *about; - -@property (nonatomic) bool online; -@property (nonatomic) NSTimeInterval lastSeen; - -@property (nonatomic, strong) NSString *photoSmall; -@property (nonatomic, strong) NSString *photoBig; - -@property (nonatomic) TGBridgeUserKind kind; -@property (nonatomic) TGBridgeBotKind botKind; -@property (nonatomic) int32_t botVersion; - -@property (nonatomic) bool verified; - -@property (nonatomic) int32_t userVersion; - -- (NSString *)displayName; -- (TGBridgeUserChange *)changeFromUser:(TGBridgeUser *)user; -- (TGBridgeUser *)userByApplyingChange:(TGBridgeUserChange *)change; - -- (bool)isBot; - -@end - - -@interface TGBridgeUserChange : NSObject - -@property (nonatomic, readonly) int32_t userIdentifier; -@property (nonatomic, readonly) NSDictionary *fields; - -- (instancetype)initWithUserIdentifier:(int32_t)userIdentifier fields:(NSDictionary *)fields; - -@end - -extern NSString *const TGBridgeUsersDictionaryKey; diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeUser.m b/submodules/WatchCommon/Watch/Sources/TGBridgeUser.m deleted file mode 100644 index 4c0fed8d97..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeUser.m +++ /dev/null @@ -1,286 +0,0 @@ -#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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeVideoMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeVideoMediaAttachment.h deleted file mode 100644 index 12eb34bd23..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeVideoMediaAttachment.h +++ /dev/null @@ -1,12 +0,0 @@ -#import - -#import - -@interface TGBridgeVideoMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t videoId; -@property (nonatomic, assign) int32_t duration; -@property (nonatomic, assign) CGSize dimensions; -@property (nonatomic, assign) bool round; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeVideoMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeVideoMediaAttachment.m deleted file mode 100644 index 66fe867996..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeVideoMediaAttachment.m +++ /dev/null @@ -1,39 +0,0 @@ -#import "TGBridgeVideoMediaAttachment.h" -#import - -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 diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeWebPageMediaAttachment.h b/submodules/WatchCommon/Watch/Sources/TGBridgeWebPageMediaAttachment.h deleted file mode 100644 index dda2a83e4a..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeWebPageMediaAttachment.h +++ /dev/null @@ -1,23 +0,0 @@ -#import - -#import - -@class TGBridgeImageMediaAttachment; - -@interface TGBridgeWebPageMediaAttachment : TGBridgeMediaAttachment - -@property (nonatomic, assign) int64_t webPageId; -@property (nonatomic, strong) NSString *url; -@property (nonatomic, strong) NSString *displayUrl; -@property (nonatomic, strong) NSString *pageType; -@property (nonatomic, strong) NSString *siteName; -@property (nonatomic, strong) NSString *title; -@property (nonatomic, strong) NSString *pageDescription; -@property (nonatomic, strong) TGBridgeImageMediaAttachment *photo; -@property (nonatomic, strong) NSString *embedUrl; -@property (nonatomic, strong) NSString *embedType; -@property (nonatomic, assign) CGSize embedSize; -@property (nonatomic, strong) NSNumber *duration; -@property (nonatomic, strong) NSString *author; - -@end diff --git a/submodules/WatchCommon/Watch/Sources/TGBridgeWebPageMediaAttachment.m b/submodules/WatchCommon/Watch/Sources/TGBridgeWebPageMediaAttachment.m deleted file mode 100644 index 3983075d69..0000000000 --- a/submodules/WatchCommon/Watch/Sources/TGBridgeWebPageMediaAttachment.m +++ /dev/null @@ -1,65 +0,0 @@ -#import "TGBridgeWebPageMediaAttachment.h" -#import "TGBridgeImageMediaAttachment.h" -#import - -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 diff --git a/submodules/WatchCommon/Watch/Sources/WatchCommonWatch.h b/submodules/WatchCommon/Watch/Sources/WatchCommonWatch.h deleted file mode 100644 index 38e8745e0f..0000000000 --- a/submodules/WatchCommon/Watch/Sources/WatchCommonWatch.h +++ /dev/null @@ -1,36 +0,0 @@ -#import - -//! Project version number for WatchCommon. -FOUNDATION_EXPORT double WatchCommonVersionNumber; - -//! Project version string for WatchCommon. -FOUNDATION_EXPORT const unsigned char WatchCommonVersionString[]; - -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import - diff --git a/third-party/libx264/BUILD b/third-party/libx264/BUILD deleted file mode 100644 index ca94eee818..0000000000 --- a/third-party/libx264/BUILD +++ /dev/null @@ -1,211 +0,0 @@ - -headers = [ - "x264.h", - "x264_config.h", -] - -libs = [ - "x264", -] - -filegroup( - name = "libx264_sources", - srcs = glob([ - "x264/**/*" - ], exclude = [ - "x264/.git/**/*" - ]), -) - - -genrule( - name = "lib264_build", - srcs = [ - "build-libx264-bazel.sh", - ":libx264_sources", - ], - cmd_bash = - """ - set -ex - - if [ "$(TARGET_CPU)" == "ios_armv7" ]; then - BUILD_ARCH="armv7" - PLATFORM_HEADER_DIR="armv7-darwin-gcc" - elif [ "$(TARGET_CPU)" == "ios_arm64" ]; then - BUILD_ARCH="arm64" - PLATFORM_HEADER_DIR="arm64-darwin-gcc" - elif [ "$(TARGET_CPU)" == "ios_sim_arm64" ]; then - BUILD_ARCH="sim_arm64" - PLATFORM_HEADER_DIR="arm64-iphonesimulator-gcc" - elif [ "$(TARGET_CPU)" == "ios_x86_64" ]; then - BUILD_ARCH="x86_64" - PLATFORM_HEADER_DIR="x86_64-iphonesimulator-gcc" - else - echo "Unsupported architecture $(TARGET_CPU)" - fi - - BUILD_DIR="$(RULEDIR)/build_$${BUILD_ARCH}" - rm -rf "$$BUILD_DIR" - mkdir -p "$$BUILD_DIR" - - YASM_DIR="$$BUILD_DIR/yasm" - rm -rf "$$YASM_DIR" - mkdir -p "$$YASM_DIR" - tar -xf "$(location //third-party/yasm:yasm.tar)" -C "$$YASM_DIR" - ABS_YASM_DIR="$$(pwd)/$$(dirname $$YASM_DIR)/$$(basename $$YASM_DIR)" - - cp $(location :build-libx264-bazel.sh) "$$BUILD_DIR/" - - SOURCE_PATH="third-party/libx264/x264" - - cp -R "$$SOURCE_PATH" "$$BUILD_DIR/" - - mkdir -p "$$BUILD_DIR/Public/libx264" - - PATH="$$PATH:$$ABS_YASM_DIR" sh $$BUILD_DIR/build-libx264-bazel.sh $$BUILD_ARCH "$$BUILD_DIR/x264" "$$BUILD_DIR" - """ + - "\n".join([ - "cp -f \"$$BUILD_DIR/scratch/thin/include/{}\" \"$(location Public/libx264/{})\"".format(header, header) for header in headers - ]) + - "\n" + - "\n".join([ - "cp -f \"$$BUILD_DIR/scratch/thin/lib/lib{}.a\" \"$(location Public/libx264/lib{}.a)\"".format(lib, lib) for lib in libs - ]) + - "\n", - outs = ["Public/libx264/" + x for x in headers] + - ["Public/libx264/lib{}.a".format(x) for x in libs], - tools = [ - "//third-party/yasm:yasm.tar", - ], - visibility = [ - "//visibility:public", - ] -) - -cc_library( - name = "libx264_lib", - srcs = [":Public/libx264/lib" + x + ".a" for x in libs], -) - -cc_library( - name = "libx264", - srcs = [ -"x264/common/osdep.c", -"x264/common/base.c", -"x264/common/cpu.c", -"x264/common/tables.c", -"x264/encoder/api.c", -"x264/common/mc.c", -"x264/common/predict.c", -"x264/common/pixel.c", -"x264/common/macroblock.c", -"x264/common/frame.c", -"x264/common/dct.c", -"x264/common/cabac.c", -"x264/common/common.c", -"x264/common/rectangle.c", -"x264/common/set.c", -"x264/common/quant.c", -"x264/common/deblock.c", -"x264/common/vlc.c", -"x264/common/mvpred.c", -"x264/common/bitstream.c", -"x264/encoder/analyse.c", -"x264/encoder/me.c", -"x264/encoder/ratecontrol.c", -"x264/encoder/set.c", -"x264/encoder/macroblock.c", -"x264/encoder/cabac.c", -"x264/encoder/cavlc.c", -"x264/encoder/encoder.c", -"x264/encoder/lookahead.c", -"x264/common/threadpool.c", - -"x264/encoder/analyse.h", -"x264/encoder/macroblock.h", -"x264/encoder/me.h", -"x264/encoder/ratecontrol.h", -"x264/encoder/set.h", -"x264/common/base.h", -"x264/common/osdep.h", -"x264/common/cpu.h", -"x264/common/tables.h", -"x264/common/common.h", -"x264/common/cabac.h", -"x264/common/bitstream.h", -"x264/common/set.h", -"x264/common/predict.h", -"x264/common/pixel.h", -"x264/common/mc.h", -"x264/common/frame.h", -"x264/common/dct.h", -"x264/common/quant.h", -"x264/common/threadpool.h", -"x264/common/macroblock.h", -"x264/common/rectangle.h", -"Public/libx264/x264_config.h", -"config/config.h", -"x264/x264.h", - -"x264/common/aarch64/asm-offsets.h", -"x264/common/aarch64/bitstream.h", -"x264/common/aarch64/deblock.h", -"x264/common/aarch64/dct.h", -"x264/common/aarch64/mc.h", -"x264/common/aarch64/predict.h", -"x264/common/aarch64/quant.h", -"x264/common/aarch64/pixel.h", - -"x264/common/aarch64/cabac-a.S", -"x264/common/aarch64/dct-a.S", -"x264/common/aarch64/deblock-a.S", -"x264/common/aarch64/mc-a.S", -"x264/common/aarch64/pixel-a.S", -"x264/common/aarch64/predict-a.S", -"x264/common/aarch64/quant-a.S", -"x264/common/aarch64/bitstream-a.S", - -"x264/common/aarch64/asm-offsets.c", -"x264/common/aarch64/mc-c.c", -"x264/common/aarch64/predict-c.c", - ], - hdrs = [ -"x264/encoder/rdo.c", -"x264/encoder/cavlc.c", -"x264/encoder/cabac.c", -"x264/encoder/slicetype.c", -"x264/common/aarch64/asm.S", - ], - includes = [ - "Public", - ], - copts = [ - "-Ithird-party/libx264/x264", - "-Ithird-party/libx264/config", - "-Ithird-party/libx264/Public/libx264", - "-DBIT_DEPTH=8", - "-DHIGH_BIT_DEPTH=0", - "-DPREFIX", - "-Dprivate_prefix=x264_8", - ], - visibility = [ - "//visibility:public", - ], -) - -objc_library( - name = "libx264_old", - module_name = "libx264_old", - enable_modules = True, - hdrs = [":Public/libx264/" + x for x in headers], - includes = [ - "Public", - ], - deps = [ - ":libx264_lib", - ":libx264_from_source", - ], - visibility = [ - "//visibility:public", - ], -) diff --git a/third-party/libx264/Public/libx264/x264.h b/third-party/libx264/Public/libx264/x264.h deleted file mode 100644 index 5aa2a8d70b..0000000000 --- a/third-party/libx264/Public/libx264/x264.h +++ /dev/null @@ -1,1019 +0,0 @@ -/***************************************************************************** - * x264.h: x264 public header - ***************************************************************************** - * Copyright (C) 2003-2022 x264 project - * - * Authors: Laurent Aimar - * Loren Merritt - * Fiona Glaser - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. - * - * This program is also available under a commercial proprietary license. - * For more information, contact us at licensing@x264.com. - *****************************************************************************/ - -#ifndef X264_X264_H -#define X264_X264_H - -#ifdef __cplusplus -extern "C" { -#endif - -#if !defined(_STDINT_H) && !defined(_STDINT_H_) && !defined(_STDINT_H_INCLUDED) && !defined(_STDINT) &&\ - !defined(_SYS_STDINT_H_) && !defined(_INTTYPES_H) && !defined(_INTTYPES_H_) && !defined(_INTTYPES) -# ifdef _MSC_VER -# pragma message("You must include stdint.h or inttypes.h before x264.h") -# else -# warning You must include stdint.h or inttypes.h before x264.h -# endif -#endif - -#include - -#include "x264_config.h" - -#define X264_BUILD 164 - -#ifdef _WIN32 -# define X264_DLL_IMPORT __declspec(dllimport) -# define X264_DLL_EXPORT __declspec(dllexport) -#else -# if defined(__GNUC__) && (__GNUC__ >= 4) -# define X264_DLL_IMPORT -# define X264_DLL_EXPORT __attribute__((visibility("default"))) -# else -# define X264_DLL_IMPORT -# define X264_DLL_EXPORT -# endif -#endif - -/* Application developers planning to link against a shared library version of - * libx264 from a Microsoft Visual Studio or similar development environment - * will need to define X264_API_IMPORTS before including this header. - * This clause does not apply to MinGW, similar development environments, or non - * Windows platforms. */ -#ifdef X264_API_IMPORTS -# define X264_API X264_DLL_IMPORT -#else -# ifdef X264_API_EXPORTS -# define X264_API X264_DLL_EXPORT -# else -# define X264_API -# endif -#endif - -/* x264_t: - * opaque handler for encoder */ -typedef struct x264_t x264_t; - -/**************************************************************************** - * NAL structure and functions - ****************************************************************************/ - -enum nal_unit_type_e -{ - NAL_UNKNOWN = 0, - NAL_SLICE = 1, - NAL_SLICE_DPA = 2, - NAL_SLICE_DPB = 3, - NAL_SLICE_DPC = 4, - NAL_SLICE_IDR = 5, /* ref_idc != 0 */ - NAL_SEI = 6, /* ref_idc == 0 */ - NAL_SPS = 7, - NAL_PPS = 8, - NAL_AUD = 9, - NAL_FILLER = 12, - /* ref_idc == 0 for 6,9,10,11,12 */ -}; -enum nal_priority_e -{ - NAL_PRIORITY_DISPOSABLE = 0, - NAL_PRIORITY_LOW = 1, - NAL_PRIORITY_HIGH = 2, - NAL_PRIORITY_HIGHEST = 3, -}; - -/* The data within the payload is already NAL-encapsulated; the ref_idc and type - * are merely in the struct for easy access by the calling application. - * All data returned in an x264_nal_t, including the data in p_payload, is no longer - * valid after the next call to x264_encoder_encode. Thus it must be used or copied - * before calling x264_encoder_encode or x264_encoder_headers again. */ -typedef struct x264_nal_t -{ - int i_ref_idc; /* nal_priority_e */ - int i_type; /* nal_unit_type_e */ - int b_long_startcode; - int i_first_mb; /* If this NAL is a slice, the index of the first MB in the slice. */ - int i_last_mb; /* If this NAL is a slice, the index of the last MB in the slice. */ - - /* Size of payload (including any padding) in bytes. */ - int i_payload; - /* If param->b_annexb is set, Annex-B bytestream with startcode. - * Otherwise, startcode is replaced with a 4-byte size. - * This size is the size used in mp4/similar muxing; it is equal to i_payload-4 */ - uint8_t *p_payload; - - /* Size of padding in bytes. */ - int i_padding; -} x264_nal_t; - -/**************************************************************************** - * Encoder parameters - ****************************************************************************/ -/* CPU flags */ - -/* x86 */ -#define X264_CPU_MMX (1U<<0) -#define X264_CPU_MMX2 (1U<<1) /* MMX2 aka MMXEXT aka ISSE */ -#define X264_CPU_MMXEXT X264_CPU_MMX2 -#define X264_CPU_SSE (1U<<2) -#define X264_CPU_SSE2 (1U<<3) -#define X264_CPU_LZCNT (1U<<4) -#define X264_CPU_SSE3 (1U<<5) -#define X264_CPU_SSSE3 (1U<<6) -#define X264_CPU_SSE4 (1U<<7) /* SSE4.1 */ -#define X264_CPU_SSE42 (1U<<8) /* SSE4.2 */ -#define X264_CPU_AVX (1U<<9) /* Requires OS support even if YMM registers aren't used */ -#define X264_CPU_XOP (1U<<10) /* AMD XOP */ -#define X264_CPU_FMA4 (1U<<11) /* AMD FMA4 */ -#define X264_CPU_FMA3 (1U<<12) -#define X264_CPU_BMI1 (1U<<13) -#define X264_CPU_BMI2 (1U<<14) -#define X264_CPU_AVX2 (1U<<15) -#define X264_CPU_AVX512 (1U<<16) /* AVX-512 {F, CD, BW, DQ, VL}, requires OS support */ -/* x86 modifiers */ -#define X264_CPU_CACHELINE_32 (1U<<17) /* avoid memory loads that span the border between two cachelines */ -#define X264_CPU_CACHELINE_64 (1U<<18) /* 32/64 is the size of a cacheline in bytes */ -#define X264_CPU_SSE2_IS_SLOW (1U<<19) /* avoid most SSE2 functions on Athlon64 */ -#define X264_CPU_SSE2_IS_FAST (1U<<20) /* a few functions are only faster on Core2 and Phenom */ -#define X264_CPU_SLOW_SHUFFLE (1U<<21) /* The Conroe has a slow shuffle unit (relative to overall SSE performance) */ -#define X264_CPU_STACK_MOD4 (1U<<22) /* if stack is only mod4 and not mod16 */ -#define X264_CPU_SLOW_ATOM (1U<<23) /* The Atom is terrible: slow SSE unaligned loads, slow - * SIMD multiplies, slow SIMD variable shifts, slow pshufb, - * cacheline split penalties -- gather everything here that - * isn't shared by other CPUs to avoid making half a dozen - * new SLOW flags. */ -#define X264_CPU_SLOW_PSHUFB (1U<<24) /* such as on the Intel Atom */ -#define X264_CPU_SLOW_PALIGNR (1U<<25) /* such as on the AMD Bobcat */ - -/* PowerPC */ -#define X264_CPU_ALTIVEC 0x0000001U - -/* ARM and AArch64 */ -#define X264_CPU_ARMV6 0x0000001U -#define X264_CPU_NEON 0x0000002U /* ARM NEON */ -#define X264_CPU_FAST_NEON_MRC 0x0000004U /* Transfer from NEON to ARM register is fast (Cortex-A9) */ -#define X264_CPU_ARMV8 0x0000008U - -/* MIPS */ -#define X264_CPU_MSA 0x0000001U /* MIPS MSA */ - -/* Analyse flags */ -#define X264_ANALYSE_I4x4 0x0001U /* Analyse i4x4 */ -#define X264_ANALYSE_I8x8 0x0002U /* Analyse i8x8 (requires 8x8 transform) */ -#define X264_ANALYSE_PSUB16x16 0x0010U /* Analyse p16x8, p8x16 and p8x8 */ -#define X264_ANALYSE_PSUB8x8 0x0020U /* Analyse p8x4, p4x8, p4x4 */ -#define X264_ANALYSE_BSUB16x16 0x0100U /* Analyse b16x8, b8x16 and b8x8 */ - -#define X264_DIRECT_PRED_NONE 0 -#define X264_DIRECT_PRED_SPATIAL 1 -#define X264_DIRECT_PRED_TEMPORAL 2 -#define X264_DIRECT_PRED_AUTO 3 -#define X264_ME_DIA 0 -#define X264_ME_HEX 1 -#define X264_ME_UMH 2 -#define X264_ME_ESA 3 -#define X264_ME_TESA 4 -#define X264_CQM_FLAT 0 -#define X264_CQM_JVT 1 -#define X264_CQM_CUSTOM 2 -#define X264_RC_CQP 0 -#define X264_RC_CRF 1 -#define X264_RC_ABR 2 -#define X264_QP_AUTO 0 -#define X264_AQ_NONE 0 -#define X264_AQ_VARIANCE 1 -#define X264_AQ_AUTOVARIANCE 2 -#define X264_AQ_AUTOVARIANCE_BIASED 3 -#define X264_B_ADAPT_NONE 0 -#define X264_B_ADAPT_FAST 1 -#define X264_B_ADAPT_TRELLIS 2 -#define X264_WEIGHTP_NONE 0 -#define X264_WEIGHTP_SIMPLE 1 -#define X264_WEIGHTP_SMART 2 -#define X264_B_PYRAMID_NONE 0 -#define X264_B_PYRAMID_STRICT 1 -#define X264_B_PYRAMID_NORMAL 2 -#define X264_KEYINT_MIN_AUTO 0 -#define X264_KEYINT_MAX_INFINITE (1<<30) - -/* AVC-Intra flavors */ -#define X264_AVCINTRA_FLAVOR_PANASONIC 0 -#define X264_AVCINTRA_FLAVOR_SONY 1 - -static const char * const x264_direct_pred_names[] = { "none", "spatial", "temporal", "auto", 0 }; -static const char * const x264_motion_est_names[] = { "dia", "hex", "umh", "esa", "tesa", 0 }; -static const char * const x264_b_pyramid_names[] = { "none", "strict", "normal", 0 }; -static const char * const x264_overscan_names[] = { "undef", "show", "crop", 0 }; -static const char * const x264_vidformat_names[] = { "component", "pal", "ntsc", "secam", "mac", "undef", 0 }; -static const char * const x264_fullrange_names[] = { "off", "on", 0 }; -static const char * const x264_colorprim_names[] = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "film", "bt2020", "smpte428", - "smpte431", "smpte432", 0 }; -static const char * const x264_transfer_names[] = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "linear", "log100", "log316", - "iec61966-2-4", "bt1361e", "iec61966-2-1", "bt2020-10", "bt2020-12", "smpte2084", "smpte428", "arib-std-b67", 0 }; -static const char * const x264_colmatrix_names[] = { "GBR", "bt709", "undef", "", "fcc", "bt470bg", "smpte170m", "smpte240m", "YCgCo", "bt2020nc", "bt2020c", - "smpte2085", "chroma-derived-nc", "chroma-derived-c", "ICtCp", 0 }; -static const char * const x264_nal_hrd_names[] = { "none", "vbr", "cbr", 0 }; -static const char * const x264_avcintra_flavor_names[] = { "panasonic", "sony", 0 }; - -/* Colorspace type */ -#define X264_CSP_MASK 0x00ff /* */ -#define X264_CSP_NONE 0x0000 /* Invalid mode */ -#define X264_CSP_I400 0x0001 /* monochrome 4:0:0 */ -#define X264_CSP_I420 0x0002 /* yuv 4:2:0 planar */ -#define X264_CSP_YV12 0x0003 /* yvu 4:2:0 planar */ -#define X264_CSP_NV12 0x0004 /* yuv 4:2:0, with one y plane and one packed u+v */ -#define X264_CSP_NV21 0x0005 /* yuv 4:2:0, with one y plane and one packed v+u */ -#define X264_CSP_I422 0x0006 /* yuv 4:2:2 planar */ -#define X264_CSP_YV16 0x0007 /* yvu 4:2:2 planar */ -#define X264_CSP_NV16 0x0008 /* yuv 4:2:2, with one y plane and one packed u+v */ -#define X264_CSP_YUYV 0x0009 /* yuyv 4:2:2 packed */ -#define X264_CSP_UYVY 0x000a /* uyvy 4:2:2 packed */ -#define X264_CSP_V210 0x000b /* 10-bit yuv 4:2:2 packed in 32 */ -#define X264_CSP_I444 0x000c /* yuv 4:4:4 planar */ -#define X264_CSP_YV24 0x000d /* yvu 4:4:4 planar */ -#define X264_CSP_BGR 0x000e /* packed bgr 24bits */ -#define X264_CSP_BGRA 0x000f /* packed bgr 32bits */ -#define X264_CSP_RGB 0x0010 /* packed rgb 24bits */ -#define X264_CSP_MAX 0x0011 /* end of list */ -#define X264_CSP_VFLIP 0x1000 /* the csp is vertically flipped */ -#define X264_CSP_HIGH_DEPTH 0x2000 /* the csp has a depth of 16 bits per pixel component */ - -/* Slice type */ -#define X264_TYPE_AUTO 0x0000 /* Let x264 choose the right type */ -#define X264_TYPE_IDR 0x0001 -#define X264_TYPE_I 0x0002 -#define X264_TYPE_P 0x0003 -#define X264_TYPE_BREF 0x0004 /* Non-disposable B-frame */ -#define X264_TYPE_B 0x0005 -#define X264_TYPE_KEYFRAME 0x0006 /* IDR or I depending on b_open_gop option */ -#define IS_X264_TYPE_I(x) ((x)==X264_TYPE_I || (x)==X264_TYPE_IDR || (x)==X264_TYPE_KEYFRAME) -#define IS_X264_TYPE_B(x) ((x)==X264_TYPE_B || (x)==X264_TYPE_BREF) - -/* Log level */ -#define X264_LOG_NONE (-1) -#define X264_LOG_ERROR 0 -#define X264_LOG_WARNING 1 -#define X264_LOG_INFO 2 -#define X264_LOG_DEBUG 3 - -/* Threading */ -#define X264_THREADS_AUTO 0 /* Automatically select optimal number of threads */ -#define X264_SYNC_LOOKAHEAD_AUTO (-1) /* Automatically select optimal lookahead thread buffer size */ - -/* HRD */ -#define X264_NAL_HRD_NONE 0 -#define X264_NAL_HRD_VBR 1 -#define X264_NAL_HRD_CBR 2 - -/* Zones: override ratecontrol or other options for specific sections of the video. - * See x264_encoder_reconfig() for which options can be changed. - * If zones overlap, whichever comes later in the list takes precedence. */ -typedef struct x264_zone_t -{ - int i_start, i_end; /* range of frame numbers */ - int b_force_qp; /* whether to use qp vs bitrate factor */ - int i_qp; - float f_bitrate_factor; - struct x264_param_t *param; -} x264_zone_t; - -typedef struct x264_param_t -{ - /* CPU flags */ - uint32_t cpu; - int i_threads; /* encode multiple frames in parallel */ - int i_lookahead_threads; /* multiple threads for lookahead analysis */ - int b_sliced_threads; /* Whether to use slice-based threading. */ - int b_deterministic; /* whether to allow non-deterministic optimizations when threaded */ - int b_cpu_independent; /* force canonical behavior rather than cpu-dependent optimal algorithms */ - int i_sync_lookahead; /* threaded lookahead buffer */ - - /* Video Properties */ - int i_width; - int i_height; - int i_csp; /* CSP of encoded bitstream */ - int i_bitdepth; - int i_level_idc; - int i_frame_total; /* number of frames to encode if known, else 0 */ - - /* NAL HRD - * Uses Buffering and Picture Timing SEIs to signal HRD - * The HRD in H.264 was not designed with VFR in mind. - * It is therefore not recommendeded to use NAL HRD with VFR. - * Furthermore, reconfiguring the VBV (via x264_encoder_reconfig) - * will currently generate invalid HRD. */ - int i_nal_hrd; - - struct - { - /* they will be reduced to be 0 < x <= 65535 and prime */ - int i_sar_height; - int i_sar_width; - - int i_overscan; /* 0=undef, 1=no overscan, 2=overscan */ - - /* see h264 annex E for the values of the following */ - int i_vidformat; - int b_fullrange; - int i_colorprim; - int i_transfer; - int i_colmatrix; - int i_chroma_loc; /* both top & bottom */ - } vui; - - /* Bitstream parameters */ - int i_frame_reference; /* Maximum number of reference frames */ - int i_dpb_size; /* Force a DPB size larger than that implied by B-frames and reference frames. - * Useful in combination with interactive error resilience. */ - int i_keyint_max; /* Force an IDR keyframe at this interval */ - int i_keyint_min; /* Scenecuts closer together than this are coded as I, not IDR. */ - int i_scenecut_threshold; /* how aggressively to insert extra I frames */ - int b_intra_refresh; /* Whether or not to use periodic intra refresh instead of IDR frames. */ - - int i_bframe; /* how many b-frame between 2 references pictures */ - int i_bframe_adaptive; - int i_bframe_bias; - int i_bframe_pyramid; /* Keep some B-frames as references: 0=off, 1=strict hierarchical, 2=normal */ - int b_open_gop; - int b_bluray_compat; - int i_avcintra_class; - int i_avcintra_flavor; - - int b_deblocking_filter; - int i_deblocking_filter_alphac0; /* [-6, 6] -6 light filter, 6 strong */ - int i_deblocking_filter_beta; /* [-6, 6] idem */ - - int b_cabac; - int i_cabac_init_idc; - - int b_interlaced; - int b_constrained_intra; - - int i_cqm_preset; - char *psz_cqm_file; /* filename (in UTF-8) of CQM file, JM format */ - uint8_t cqm_4iy[16]; /* used only if i_cqm_preset == X264_CQM_CUSTOM */ - uint8_t cqm_4py[16]; - uint8_t cqm_4ic[16]; - uint8_t cqm_4pc[16]; - uint8_t cqm_8iy[64]; - uint8_t cqm_8py[64]; - uint8_t cqm_8ic[64]; - uint8_t cqm_8pc[64]; - - /* Log */ - void (*pf_log)( void *, int i_level, const char *psz, va_list ); - void *p_log_private; - int i_log_level; - int b_full_recon; /* fully reconstruct frames, even when not necessary for encoding. Implied by psz_dump_yuv */ - char *psz_dump_yuv; /* filename (in UTF-8) for reconstructed frames */ - - /* Encoder analyser parameters */ - struct - { - unsigned int intra; /* intra partitions */ - unsigned int inter; /* inter partitions */ - - int b_transform_8x8; - int i_weighted_pred; /* weighting for P-frames */ - int b_weighted_bipred; /* implicit weighting for B-frames */ - int i_direct_mv_pred; /* spatial vs temporal mv prediction */ - int i_chroma_qp_offset; - - int i_me_method; /* motion estimation algorithm to use (X264_ME_*) */ - int i_me_range; /* integer pixel motion estimation search range (from predicted mv) */ - int i_mv_range; /* maximum length of a mv (in pixels). -1 = auto, based on level */ - int i_mv_range_thread; /* minimum space between threads. -1 = auto, based on number of threads. */ - int i_subpel_refine; /* subpixel motion estimation quality */ - int b_chroma_me; /* chroma ME for subpel and mode decision in P-frames */ - int b_mixed_references; /* allow each mb partition to have its own reference number */ - int i_trellis; /* trellis RD quantization */ - int b_fast_pskip; /* early SKIP detection on P-frames */ - int b_dct_decimate; /* transform coefficient thresholding on P-frames */ - int i_noise_reduction; /* adaptive pseudo-deadzone */ - float f_psy_rd; /* Psy RD strength */ - float f_psy_trellis; /* Psy trellis strength */ - int b_psy; /* Toggle all psy optimizations */ - - int b_mb_info; /* Use input mb_info data in x264_picture_t */ - int b_mb_info_update; /* Update the values in mb_info according to the results of encoding. */ - - /* the deadzone size that will be used in luma quantization */ - int i_luma_deadzone[2]; /* {inter, intra} */ - - int b_psnr; /* compute and print PSNR stats */ - int b_ssim; /* compute and print SSIM stats */ - } analyse; - - /* Rate control parameters */ - struct - { - int i_rc_method; /* X264_RC_* */ - - int i_qp_constant; /* 0=lossless */ - int i_qp_min; /* min allowed QP value */ - int i_qp_max; /* max allowed QP value */ - int i_qp_step; /* max QP step between frames */ - - int i_bitrate; - float f_rf_constant; /* 1pass VBR, nominal QP */ - float f_rf_constant_max; /* In CRF mode, maximum CRF as caused by VBV */ - float f_rate_tolerance; - int i_vbv_max_bitrate; - int i_vbv_buffer_size; - float f_vbv_buffer_init; /* <=1: fraction of buffer_size. >1: kbit */ - float f_ip_factor; - float f_pb_factor; - - /* VBV filler: force CBR VBV and use filler bytes to ensure hard-CBR. - * Implied by NAL-HRD CBR. */ - int b_filler; - - int i_aq_mode; /* psy adaptive QP. (X264_AQ_*) */ - float f_aq_strength; - int b_mb_tree; /* Macroblock-tree ratecontrol. */ - int i_lookahead; - - /* 2pass */ - int b_stat_write; /* Enable stat writing in psz_stat_out */ - char *psz_stat_out; /* output filename (in UTF-8) of the 2pass stats file */ - int b_stat_read; /* Read stat from psz_stat_in and use it */ - char *psz_stat_in; /* input filename (in UTF-8) of the 2pass stats file */ - - /* 2pass params (same as ffmpeg ones) */ - float f_qcompress; /* 0.0 => cbr, 1.0 => constant qp */ - float f_qblur; /* temporally blur quants */ - float f_complexity_blur; /* temporally blur complexity */ - x264_zone_t *zones; /* ratecontrol overrides */ - int i_zones; /* number of zone_t's */ - char *psz_zones; /* alternate method of specifying zones */ - } rc; - - /* Cropping Rectangle parameters: added to those implicitly defined by - non-mod16 video resolutions. */ - struct - { - int i_left; - int i_top; - int i_right; - int i_bottom; - } crop_rect; - - /* frame packing arrangement flag */ - int i_frame_packing; - - /* mastering display SEI: Primary and white point chromaticity coordinates - in 0.00002 increments. Brightness units are 0.0001 cd/m^2. */ - struct - { - int b_mastering_display; /* enable writing this SEI */ - int i_green_x; - int i_green_y; - int i_blue_x; - int i_blue_y; - int i_red_x; - int i_red_y; - int i_white_x; - int i_white_y; - int64_t i_display_max; - int64_t i_display_min; - } mastering_display; - - /* content light level SEI */ - struct - { - int b_cll; /* enable writing this SEI */ - int i_max_cll; - int i_max_fall; - } content_light_level; - - /* alternative transfer SEI */ - int i_alternative_transfer; - - /* Muxing parameters */ - int b_aud; /* generate access unit delimiters */ - int b_repeat_headers; /* put SPS/PPS before each keyframe */ - int b_annexb; /* if set, place start codes (4 bytes) before NAL units, - * otherwise place size (4 bytes) before NAL units. */ - int i_sps_id; /* SPS and PPS id number */ - int b_vfr_input; /* VFR input. If 1, use timebase and timestamps for ratecontrol purposes. - * If 0, use fps only. */ - int b_pulldown; /* use explicitly set timebase for CFR */ - uint32_t i_fps_num; - uint32_t i_fps_den; - uint32_t i_timebase_num; /* Timebase numerator */ - uint32_t i_timebase_den; /* Timebase denominator */ - - int b_tff; - - /* Pulldown: - * The correct pic_struct must be passed with each input frame. - * The input timebase should be the timebase corresponding to the output framerate. This should be constant. - * e.g. for 3:2 pulldown timebase should be 1001/30000 - * The PTS passed with each frame must be the PTS of the frame after pulldown is applied. - * Frame doubling and tripling require b_vfr_input set to zero (see H.264 Table D-1) - * - * Pulldown changes are not clearly defined in H.264. Therefore, it is the calling app's responsibility to manage this. - */ - - int b_pic_struct; - - /* Fake Interlaced. - * - * Used only when b_interlaced=0. Setting this flag makes it possible to flag the stream as PAFF interlaced yet - * encode all frames progessively. It is useful for encoding 25p and 30p Blu-Ray streams. - */ - - int b_fake_interlaced; - - /* Don't optimize header parameters based on video content, e.g. ensure that splitting an input video, compressing - * each part, and stitching them back together will result in identical SPS/PPS. This is necessary for stitching - * with container formats that don't allow multiple SPS/PPS. */ - int b_stitchable; - - int b_opencl; /* use OpenCL when available */ - int i_opencl_device; /* specify count of GPU devices to skip, for CLI users */ - void *opencl_device_id; /* pass explicit cl_device_id as void*, for API users */ - char *psz_clbin_file; /* filename (in UTF-8) of the compiled OpenCL kernel cache file */ - - /* Slicing parameters */ - int i_slice_max_size; /* Max size per slice in bytes; includes estimated NAL overhead. */ - int i_slice_max_mbs; /* Max number of MBs per slice; overrides i_slice_count. */ - int i_slice_min_mbs; /* Min number of MBs per slice */ - int i_slice_count; /* Number of slices per frame: forces rectangular slices. */ - int i_slice_count_max; /* Absolute cap on slices per frame; stops applying slice-max-size - * and slice-max-mbs if this is reached. */ - - /* Optional callback for freeing this x264_param_t when it is done being used. - * Only used when the x264_param_t sits in memory for an indefinite period of time, - * i.e. when an x264_param_t is passed to x264_t in an x264_picture_t or in zones. - * Not used when x264_encoder_reconfig is called directly. */ - void (*param_free)( void* ); - - /* Optional low-level callback for low-latency encoding. Called for each output NAL unit - * immediately after the NAL unit is finished encoding. This allows the calling application - * to begin processing video data (e.g. by sending packets over a network) before the frame - * is done encoding. - * - * This callback MUST do the following in order to work correctly: - * 1) Have available an output buffer of at least size nal->i_payload*3/2 + 5 + 64. - * 2) Call x264_nal_encode( h, dst, nal ), where dst is the output buffer. - * After these steps, the content of nal is valid and can be used in the same way as if - * the NAL unit were output by x264_encoder_encode. - * - * This does not need to be synchronous with the encoding process: the data pointed to - * by nal (both before and after x264_nal_encode) will remain valid until the next - * x264_encoder_encode call. The callback must be re-entrant. - * - * This callback does not work with frame-based threads; threads must be disabled - * or sliced-threads enabled. This callback also does not work as one would expect - * with HRD -- since the buffering period SEI cannot be calculated until the frame - * is finished encoding, it will not be sent via this callback. - * - * Note also that the NALs are not necessarily returned in order when sliced threads is - * enabled. Accordingly, the variable i_first_mb and i_last_mb are available in - * x264_nal_t to help the calling application reorder the slices if necessary. - * - * When this callback is enabled, x264_encoder_encode does not return valid NALs; - * the calling application is expected to acquire all output NALs through the callback. - * - * It is generally sensible to combine this callback with a use of slice-max-mbs or - * slice-max-size. - * - * The opaque pointer is the opaque pointer from the input frame associated with this - * NAL unit. This helps distinguish between nalu_process calls from different sources, - * e.g. if doing multiple encodes in one process. - */ - void (*nalu_process)( x264_t *h, x264_nal_t *nal, void *opaque ); - - /* For internal use only */ - void *opaque; -} x264_param_t; - -X264_API void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal ); - -/**************************************************************************** - * H.264 level restriction information - ****************************************************************************/ - -typedef struct x264_level_t -{ - uint8_t level_idc; - int32_t mbps; /* max macroblock processing rate (macroblocks/sec) */ - int32_t frame_size; /* max frame size (macroblocks) */ - int32_t dpb; /* max decoded picture buffer (mbs) */ - int32_t bitrate; /* max bitrate (kbit/sec) */ - int32_t cpb; /* max vbv buffer (kbit) */ - uint16_t mv_range; /* max vertical mv component range (pixels) */ - uint8_t mvs_per_2mb; /* max mvs per 2 consecutive mbs. */ - uint8_t slice_rate; /* ?? */ - uint8_t mincr; /* min compression ratio */ - uint8_t bipred8x8; /* limit bipred to >=8x8 */ - uint8_t direct8x8; /* limit b_direct to >=8x8 */ - uint8_t frame_only; /* forbid interlacing */ -} x264_level_t; - -/* all of the levels defined in the standard, terminated by .level_idc=0 */ -X264_API extern const x264_level_t x264_levels[]; - -/**************************************************************************** - * Basic parameter handling functions - ****************************************************************************/ - -/* x264_param_default: - * fill x264_param_t with default values and do CPU detection */ -X264_API void x264_param_default( x264_param_t * ); - -/* x264_param_parse: - * set one parameter by name. - * returns 0 on success, or returns one of the following errors. - * note: BAD_VALUE occurs only if it can't even parse the value, - * numerical range is not checked until x264_encoder_open() or - * x264_encoder_reconfig(). - * value=NULL means "true" for boolean options, but is a BAD_VALUE for non-booleans. - * can allocate memory which should be freed by call of x264_param_cleanup. */ -#define X264_PARAM_BAD_NAME (-1) -#define X264_PARAM_BAD_VALUE (-2) -#define X264_PARAM_ALLOC_FAILED (-3) -X264_API int x264_param_parse( x264_param_t *, const char *name, const char *value ); - -/* x264_param_cleanup: - * Cleans up and frees allocated members of x264_param_t. - * This *does not* free the x264_param_t itself, as it may exist on the - * stack. It only frees any members of the struct that were allocated by - * x264 itself, in e.g. x264_param_parse(). */ -X264_API void x264_param_cleanup( x264_param_t *param ); - -/**************************************************************************** - * Advanced parameter handling functions - ****************************************************************************/ - -/* These functions expose the full power of x264's preset-tune-profile system for - * easy adjustment of large numbers of internal parameters. - * - * In order to replicate x264CLI's option handling, these functions MUST be called - * in the following order: - * 1) x264_param_default_preset - * 2) Custom user options (via param_parse or directly assigned variables) - * 3) x264_param_apply_fastfirstpass - * 4) x264_param_apply_profile - * - * Additionally, x264CLI does not apply step 3 if the preset chosen is "placebo" - * or --slow-firstpass is set. */ - -/* x264_param_default_preset: - * The same as x264_param_default, but also use the passed preset and tune - * to modify the default settings. - * (either can be NULL, which implies no preset or no tune, respectively) - * - * Currently available presets are, ordered from fastest to slowest: */ -static const char * const x264_preset_names[] = { "ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo", 0 }; - -/* The presets can also be indexed numerically, as in: - * x264_param_default_preset( ¶m, "3", ... ) - * with ultrafast mapping to "0" and placebo mapping to "9". This mapping may - * of course change if new presets are added in between, but will always be - * ordered from fastest to slowest. - * - * Warning: the speed of these presets scales dramatically. Ultrafast is a full - * 100 times faster than placebo! - * - * Currently available tunings are: */ -static const char * const x264_tune_names[] = { "film", "animation", "grain", "stillimage", "psnr", "ssim", "fastdecode", "zerolatency", 0 }; - -/* Multiple tunings can be used if separated by a delimiter in ",./-+", - * however multiple psy tunings cannot be used. - * film, animation, grain, stillimage, psnr, and ssim are psy tunings. - * - * returns 0 on success, negative on failure (e.g. invalid preset/tune name). */ -X264_API int x264_param_default_preset( x264_param_t *, const char *preset, const char *tune ); - -/* x264_param_apply_fastfirstpass: - * If first-pass mode is set (rc.b_stat_read == 0, rc.b_stat_write == 1), - * modify the encoder settings to disable options generally not useful on - * the first pass. */ -X264_API void x264_param_apply_fastfirstpass( x264_param_t * ); - -/* x264_param_apply_profile: - * Applies the restrictions of the given profile. - * Currently available profiles are, from most to least restrictive: */ -static const char * const x264_profile_names[] = { "baseline", "main", "high", "high10", "high422", "high444", 0 }; - -/* (can be NULL, in which case the function will do nothing) - * - * Does NOT guarantee that the given profile will be used: if the restrictions - * of "High" are applied to settings that are already Baseline-compatible, the - * stream will remain baseline. In short, it does not increase settings, only - * decrease them. - * - * returns 0 on success, negative on failure (e.g. invalid profile name). */ -X264_API int x264_param_apply_profile( x264_param_t *, const char *profile ); - -/**************************************************************************** - * Picture structures and functions - ****************************************************************************/ - -/* x264_chroma_format: - * Specifies the chroma formats that x264 supports encoding. When this - * value is non-zero, then it represents a X264_CSP_* that is the only - * chroma format that x264 supports encoding. If the value is 0 then - * there are no restrictions. */ -X264_API extern const int x264_chroma_format; - -enum pic_struct_e -{ - PIC_STRUCT_AUTO = 0, // automatically decide (default) - PIC_STRUCT_PROGRESSIVE = 1, // progressive frame - // "TOP" and "BOTTOM" are not supported in x264 (PAFF only) - PIC_STRUCT_TOP_BOTTOM = 4, // top field followed by bottom - PIC_STRUCT_BOTTOM_TOP = 5, // bottom field followed by top - PIC_STRUCT_TOP_BOTTOM_TOP = 6, // top field, bottom field, top field repeated - PIC_STRUCT_BOTTOM_TOP_BOTTOM = 7, // bottom field, top field, bottom field repeated - PIC_STRUCT_DOUBLE = 8, // double frame - PIC_STRUCT_TRIPLE = 9, // triple frame -}; - -typedef struct x264_hrd_t -{ - double cpb_initial_arrival_time; - double cpb_final_arrival_time; - double cpb_removal_time; - - double dpb_output_time; -} x264_hrd_t; - -/* Arbitrary user SEI: - * Payload size is in bytes and the payload pointer must be valid. - * Payload types and syntax can be found in Annex D of the H.264 Specification. - * SEI payload alignment bits as described in Annex D must be included at the - * end of the payload if needed. - * The payload should not be NAL-encapsulated. - * Payloads are written first in order of input, apart from in the case when HRD - * is enabled where payloads are written after the Buffering Period SEI. */ - -typedef struct x264_sei_payload_t -{ - int payload_size; - int payload_type; - uint8_t *payload; -} x264_sei_payload_t; - -typedef struct x264_sei_t -{ - int num_payloads; - x264_sei_payload_t *payloads; - /* In: optional callback to free each payload AND x264_sei_payload_t when used. */ - void (*sei_free)( void* ); -} x264_sei_t; - -typedef struct x264_image_t -{ - int i_csp; /* Colorspace */ - int i_plane; /* Number of image planes */ - int i_stride[4]; /* Strides for each plane */ - uint8_t *plane[4]; /* Pointers to each plane */ -} x264_image_t; - -typedef struct x264_image_properties_t -{ - /* All arrays of data here are ordered as follows: - * each array contains one offset per macroblock, in raster scan order. In interlaced - * mode, top-field MBs and bottom-field MBs are interleaved at the row level. - * Macroblocks are 16x16 blocks of pixels (with respect to the luma plane). For the - * purposes of calculating the number of macroblocks, width and height are rounded up to - * the nearest 16. If in interlaced mode, height is rounded up to the nearest 32 instead. */ - - /* In: an array of quantizer offsets to be applied to this image during encoding. - * These are added on top of the decisions made by x264. - * Offsets can be fractional; they are added before QPs are rounded to integer. - * Adaptive quantization must be enabled to use this feature. Behavior if quant - * offsets differ between encoding passes is undefined. */ - float *quant_offsets; - /* In: optional callback to free quant_offsets when used. - * Useful if one wants to use a different quant_offset array for each frame. */ - void (*quant_offsets_free)( void* ); - - /* In: optional array of flags for each macroblock. - * Allows specifying additional information for the encoder such as which macroblocks - * remain unchanged. Usable flags are listed below. - * x264_param_t.analyse.b_mb_info must be set to use this, since x264 needs to track - * extra data internally to make full use of this information. - * - * Out: if b_mb_info_update is set, x264 will update this array as a result of encoding. - * - * For "MBINFO_CONSTANT", it will remove this flag on any macroblock whose decoded - * pixels have changed. This can be useful for e.g. noting which areas of the - * frame need to actually be blitted. Note: this intentionally ignores the effects - * of deblocking for the current frame, which should be fine unless one needs exact - * pixel-perfect accuracy. - * - * Results for MBINFO_CONSTANT are currently only set for P-frames, and are not - * guaranteed to enumerate all blocks which haven't changed. (There may be false - * negatives, but no false positives.) - */ - uint8_t *mb_info; - /* In: optional callback to free mb_info when used. */ - void (*mb_info_free)( void* ); - - /* The macroblock is constant and remains unchanged from the previous frame. */ - #define X264_MBINFO_CONSTANT (1U<<0) - /* More flags may be added in the future. */ - - /* Out: SSIM of the the frame luma (if x264_param_t.b_ssim is set) */ - double f_ssim; - /* Out: Average PSNR of the frame (if x264_param_t.b_psnr is set) */ - double f_psnr_avg; - /* Out: PSNR of Y, U, and V (if x264_param_t.b_psnr is set) */ - double f_psnr[3]; - - /* Out: Average effective CRF of the encoded frame */ - double f_crf_avg; -} x264_image_properties_t; - -typedef struct x264_picture_t -{ - /* In: force picture type (if not auto) - * If x264 encoding parameters are violated in the forcing of picture types, - * x264 will correct the input picture type and log a warning. - * Out: type of the picture encoded */ - int i_type; - /* In: force quantizer for != X264_QP_AUTO */ - int i_qpplus1; - /* In: pic_struct, for pulldown/doubling/etc...used only if b_pic_struct=1. - * use pic_struct_e for pic_struct inputs - * Out: pic_struct element associated with frame */ - int i_pic_struct; - /* Out: whether this frame is a keyframe. Important when using modes that result in - * SEI recovery points being used instead of IDR frames. */ - int b_keyframe; - /* In: user pts, Out: pts of encoded picture (user)*/ - int64_t i_pts; - /* Out: frame dts. When the pts of the first frame is close to zero, - * initial frames may have a negative dts which must be dealt with by any muxer */ - int64_t i_dts; - /* In: custom encoding parameters to be set from this frame forwards - (in coded order, not display order). If NULL, continue using - parameters from the previous frame. Some parameters, such as - aspect ratio, can only be changed per-GOP due to the limitations - of H.264 itself; in this case, the caller must force an IDR frame - if it needs the changed parameter to apply immediately. */ - x264_param_t *param; - /* In: raw image data */ - /* Out: reconstructed image data. x264 may skip part of the reconstruction process, - e.g. deblocking, in frames where it isn't necessary. To force complete - reconstruction, at a small speed cost, set b_full_recon. */ - x264_image_t img; - /* In: optional information to modify encoder decisions for this frame - * Out: information about the encoded frame */ - x264_image_properties_t prop; - /* Out: HRD timing information. Output only when i_nal_hrd is set. */ - x264_hrd_t hrd_timing; - /* In: arbitrary user SEI (e.g subtitles, AFDs) */ - x264_sei_t extra_sei; - /* private user data. copied from input to output frames. */ - void *opaque; -} x264_picture_t; - -/* x264_picture_init: - * initialize an x264_picture_t. Needs to be done if the calling application - * allocates its own x264_picture_t as opposed to using x264_picture_alloc. */ -X264_API void x264_picture_init( x264_picture_t *pic ); - -/* x264_picture_alloc: - * alloc data for a picture. You must call x264_picture_clean on it. - * returns 0 on success, or -1 on malloc failure or invalid colorspace. */ -X264_API int x264_picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_height ); - -/* x264_picture_clean: - * free associated resource for a x264_picture_t allocated with - * x264_picture_alloc ONLY */ -X264_API void x264_picture_clean( x264_picture_t *pic ); - -/**************************************************************************** - * Encoder functions - ****************************************************************************/ - -/* Force a link error in the case of linking against an incompatible API version. - * Glue #defines exist to force correct macro expansion; the final output of the macro - * is x264_encoder_open_##X264_BUILD (for purposes of dlopen). */ -#define x264_encoder_glue1(x,y) x##y -#define x264_encoder_glue2(x,y) x264_encoder_glue1(x,y) -#define x264_encoder_open x264_encoder_glue2(x264_encoder_open_,X264_BUILD) - -/* x264_encoder_open: - * create a new encoder handler, all parameters from x264_param_t are copied */ -X264_API x264_t *x264_encoder_open( x264_param_t * ); - -/* x264_encoder_reconfig: - * various parameters from x264_param_t are copied. - * this takes effect immediately, on whichever frame is encoded next; - * due to delay, this may not be the next frame passed to encoder_encode. - * if the change should apply to some particular frame, use x264_picture_t->param instead. - * returns 0 on success, negative on parameter validation error. - * not all parameters can be changed; see the actual function for a detailed breakdown. - * - * since not all parameters can be changed, moving from preset to preset may not always - * fully copy all relevant parameters, but should still work usably in practice. however, - * more so than for other presets, many of the speed shortcuts used in ultrafast cannot be - * switched out of; using reconfig to switch between ultrafast and other presets is not - * recommended without a more fine-grained breakdown of parameters to take this into account. */ -X264_API int x264_encoder_reconfig( x264_t *, x264_param_t * ); -/* x264_encoder_parameters: - * copies the current internal set of parameters to the pointer provided - * by the caller. useful when the calling application needs to know - * how x264_encoder_open has changed the parameters, or the current state - * of the encoder after multiple x264_encoder_reconfig calls. - * note that the data accessible through pointers in the returned param struct - * (e.g. filenames) should not be modified by the calling application. */ -X264_API void x264_encoder_parameters( x264_t *, x264_param_t * ); -/* x264_encoder_headers: - * return the SPS and PPS that will be used for the whole stream. - * *pi_nal is the number of NAL units outputted in pp_nal. - * returns the number of bytes in the returned NALs. - * returns negative on error. - * the payloads of all output NALs are guaranteed to be sequential in memory. */ -X264_API int x264_encoder_headers( x264_t *, x264_nal_t **pp_nal, int *pi_nal ); -/* x264_encoder_encode: - * encode one picture. - * *pi_nal is the number of NAL units outputted in pp_nal. - * returns the number of bytes in the returned NALs. - * returns negative on error and zero if no NAL units returned. - * the payloads of all output NALs are guaranteed to be sequential in memory. */ -X264_API int x264_encoder_encode( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out ); -/* x264_encoder_close: - * close an encoder handler */ -X264_API void x264_encoder_close( x264_t * ); -/* x264_encoder_delayed_frames: - * return the number of currently delayed (buffered) frames - * this should be used at the end of the stream, to know when you have all the encoded frames. */ -X264_API int x264_encoder_delayed_frames( x264_t * ); -/* x264_encoder_maximum_delayed_frames( x264_t * ): - * return the maximum number of delayed (buffered) frames that can occur with the current - * parameters. */ -X264_API int x264_encoder_maximum_delayed_frames( x264_t * ); -/* x264_encoder_intra_refresh: - * If an intra refresh is not in progress, begin one with the next P-frame. - * If an intra refresh is in progress, begin one as soon as the current one finishes. - * Requires that b_intra_refresh be set. - * - * Useful for interactive streaming where the client can tell the server that packet loss has - * occurred. In this case, keyint can be set to an extremely high value so that intra refreshes - * only occur when calling x264_encoder_intra_refresh. - * - * In multi-pass encoding, if x264_encoder_intra_refresh is called differently in each pass, - * behavior is undefined. - * - * Should not be called during an x264_encoder_encode. */ -X264_API void x264_encoder_intra_refresh( x264_t * ); -/* x264_encoder_invalidate_reference: - * An interactive error resilience tool, designed for use in a low-latency one-encoder-few-clients - * system. When the client has packet loss or otherwise incorrectly decodes a frame, the encoder - * can be told with this command to "forget" the frame and all frames that depend on it, referencing - * only frames that occurred before the loss. This will force a keyframe if no frames are left to - * reference after the aforementioned "forgetting". - * - * It is strongly recommended to use a large i_dpb_size in this case, which allows the encoder to - * keep around extra, older frames to fall back on in case more recent frames are all invalidated. - * Unlike increasing i_frame_reference, this does not increase the number of frames used for motion - * estimation and thus has no speed impact. It is also recommended to set a very large keyframe - * interval, so that keyframes are not used except as necessary for error recovery. - * - * x264_encoder_invalidate_reference is not currently compatible with the use of B-frames or intra - * refresh. - * - * In multi-pass encoding, if x264_encoder_invalidate_reference is called differently in each pass, - * behavior is undefined. - * - * Should not be called during an x264_encoder_encode, but multiple calls can be made simultaneously. - * - * Returns 0 on success, negative on failure. */ -X264_API int x264_encoder_invalidate_reference( x264_t *, int64_t pts ); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/third-party/libx264/Public/libx264/x264_config.h b/third-party/libx264/Public/libx264/x264_config.h deleted file mode 100644 index 66f26c8cf1..0000000000 --- a/third-party/libx264/Public/libx264/x264_config.h +++ /dev/null @@ -1,6 +0,0 @@ -#define X264_GPL 1 -#define X264_INTERLACED 1 -#define X264_BIT_DEPTH 8 -#define X264_CHROMA_FORMAT 0 -#define X264_VERSION "" -#define X264_POINTVER "0.164.x" diff --git a/third-party/libx264/build-libx264-bazel.sh b/third-party/libx264/build-libx264-bazel.sh deleted file mode 100755 index 1bd34b04c5..0000000000 --- a/third-party/libx264/build-libx264-bazel.sh +++ /dev/null @@ -1,89 +0,0 @@ -#! /bin/sh - -set -e -set -x - -RAW_ARCH="$1" - -SOURCE_DIR=$(echo "$(cd "$(dirname "$2")"; pwd -P)/$(basename "$2")") -BUILD_DIR=$(echo "$(cd "$(dirname "$3")"; pwd -P)/$(basename "$3")") - -SCRATCH="$BUILD_DIR/scratch" - -#set -e -#devnull='> /dev/null 2>&1' - -DEPLOYMENT_TARGET="13.0" -CONFIGURE_FLAGS="--enable-static --enable-pic --disable-cli --bit-depth=8 --disable-opencl" - -echo "building $RAW_ARCH..." -mkdir -p "$SCRATCH/$RAW_ARCH" -cd "$SCRATCH/$RAW_ARCH" -ASFLAGS= - -if [ "$RAW_ARCH" = "i386" -o "$RAW_ARCH" = "x86_64" ] -then - ARCH="$RAW_ARCH" - PLATFORM="iPhoneSimulator" - CPU="" - CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET" - HOST="--host=i386-apple-darwin" -elif [ "$RAW_ARCH" = "sim_arm64" ]; then - ARCH="arm64" - PLATFORM="iPhoneSimulator" - CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET --target=arm64-apple-ios$DEPLOYMENT_TARGET-simulator" - HOST="--host=aarch64-apple-darwin" -else - ARCH="$RAW_ARCH" - PLATFORM="iPhoneOS" - HOST="--host=aarch64-apple-darwin" - XARCH="-arch aarch64" - CFLAGS="$CFLAGS -mios-version-min=$DEPLOYMENT_TARGET" - ASFLAGS="$CFLAGS" - if [ "$RAW_ARCH" = "arm64" ] - then - EXPORT="GASPP_FIX_XCODE5=1" - fi -fi - -CFLAGS="-arch $ARCH" - -#if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" -o "$ARCH" = "" ]; then -# PLATFORM="iPhoneSimulator" -# CPU= -# if [ "$ARCH" = "x86_64" ] -# then -# CFLAGS="$CFLAGS -mios-simulator-version-min=7.0" -# HOST= -# else -# CFLAGS="$CFLAGS -mios-simulator-version-min=5.0" -# HOST="--host=i386-apple-darwin" -# fi -#else -# PLATFORM="iPhoneOS" -# if [ $ARCH = "arm64" ] -# then -# HOST="--host=aarch64-apple-darwin" -# XARCH="-arch aarch64" -# else -# HOST="--host=arm-apple-darwin" -# XARCH="-arch arm" -# fi -# CFLAGS="$CFLAGS -fembed-bitcode -mios-version-min=7.0" -# ASFLAGS="$CFLAGS" -#fi - -XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'` -CC="xcrun -sdk $XCRUN_SDK clang" -if [ $PLATFORM = "iPhoneOS" ] -then - export AS="$SOURCE_DIR/tools/gas-preprocessor.pl $XARCH -- $CC" -else - export -n AS -fi -CXXFLAGS="$CFLAGS" -LDFLAGS="$CFLAGS" - -CC=$CC $SOURCE_DIR/configure $CONFIGURE_FLAGS $HOST --extra-cflags="$CFLAGS" --extra-asflags="$ASFLAGS" --extra-ldflags="$LDFLAGS" --prefix="$SCRATCH/thin" || exit 1 - -make -j3 install || exit 1 diff --git a/third-party/libx264/config/config.h b/third-party/libx264/config/config.h deleted file mode 100644 index dff9e6ae22..0000000000 --- a/third-party/libx264/config/config.h +++ /dev/null @@ -1,42 +0,0 @@ -#define HAVE_AARCH64 1 -#define HAVE_NEON 1 -#define ARCH_AARCH64 1 -#define SYS_MACOSX 1 -#define STACK_ALIGNMENT 16 -#define HAVE_POSIXTHREAD 1 -#define HAVE_THREAD 1 -#define HAVE_LOG2F 1 -#define HAVE_STRTOK_R 1 -#define HAVE_CLOCK_GETTIME 1 -#define HAVE_MMAP 1 -#define HAVE_VECTOREXT 1 -#define fseek fseeko -#define ftell ftello -#define HAVE_BITDEPTH8 1 -#define HAVE_GPL 1 -#define HAVE_INTERLACED 1 -#define HAVE_MALLOC_H 0 -#define HAVE_ALTIVEC 0 -#define HAVE_ALTIVEC_H 0 -#define HAVE_MMX 0 -#define HAVE_ARMV6 0 -#define HAVE_ARMV6T2 0 -#define HAVE_BEOSTHREAD 0 -#define HAVE_WIN32THREAD 0 -#define HAVE_SWSCALE 0 -#define HAVE_LAVF 0 -#define HAVE_FFMS 0 -#define HAVE_GPAC 0 -#define HAVE_AVS 0 -#define HAVE_CPU_COUNT 0 -#define HAVE_OPENCL 0 -#define HAVE_THP 0 -#define HAVE_LSMASH 0 -#define HAVE_X86_INLINE_ASM 0 -#define HAVE_AS_FUNC 0 -#define HAVE_INTEL_DISPATCHER 0 -#define HAVE_MSA 0 -#define HAVE_WINRT 0 -#define HAVE_VSX 0 -#define HAVE_ARM_INLINE_ASM 0 -#define HAVE_BITDEPTH10 0 \ No newline at end of file