diff --git a/Telegram/SiriIntents/IntentHandler.swift b/Telegram/SiriIntents/IntentHandler.swift index c10ee63d47..deeca75664 100644 --- a/Telegram/SiriIntents/IntentHandler.swift +++ b/Telegram/SiriIntents/IntentHandler.swift @@ -619,7 +619,7 @@ class DefaultIntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo } for (_, messageId) in maxMessageIdsToApply { - signals.append(applyMaxReadIndexInteractively(postbox: account.postbox, stateManager: account.stateManager, index: MessageIndex(id: messageId, timestamp: 0)) + signals.append(TelegramEngine(account: account).messages.applyMaxReadIndexInteractively(index: MessageIndex(id: messageId, timestamp: 0)) |> castError(IntentHandlingError.self)) } diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutController.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutController.swift index 93adaa12f1..560dd508be 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutController.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutController.swift @@ -36,13 +36,13 @@ public final class BotCheckoutController: ViewController { "button_text_color": Int32(bitPattern: presentationData.theme.list.itemCheckColors.foregroundColor.argb) ] - return fetchBotPaymentForm(postbox: context.account.postbox, network: context.account.network, messageId: messageId, themeParams: themeParams) + return context.engine.payments.fetchBotPaymentForm(messageId: messageId, themeParams: themeParams) |> mapError { _ -> FetchError in return .generic } |> mapToSignal { paymentForm -> Signal in if let current = paymentForm.savedInfo { - return validateBotPaymentForm(account: context.account, saveInfo: true, messageId: messageId, formInfo: current) + return context.engine.payments.validateBotPaymentForm(saveInfo: true, messageId: messageId, formInfo: current) |> mapError { _ -> FetchError in return .generic } diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift index cf03bb4a04..6a212cecbb 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift @@ -1229,7 +1229,7 @@ final class BotCheckoutControllerNode: ItemListControllerNode, PKPaymentAuthoriz let totalAmount = currentTotalPrice(paymentForm: paymentForm, validatedFormInfo: self.currentValidatedFormInfo, currentShippingOptionId: self.currentShippingOptionId, currentTip: self.currentTipAmount) let currencyValue = formatCurrencyAmount(totalAmount, currency: paymentForm.invoice.currency) - self.payDisposable.set((sendBotPaymentForm(account: self.context.account, messageId: self.messageId, formId: paymentForm.id, validatedInfoId: self.currentValidatedFormInfo?.id, shippingOptionId: self.currentShippingOptionId, tipAmount: tipAmount, credentials: credentials) |> deliverOnMainQueue).start(next: { [weak self] result in + self.payDisposable.set((self.context.engine.payments.sendBotPaymentForm(messageId: self.messageId, formId: paymentForm.id, validatedInfoId: self.currentValidatedFormInfo?.id, shippingOptionId: self.currentShippingOptionId, tipAmount: tipAmount, credentials: credentials) |> deliverOnMainQueue).start(next: { [weak self] result in if let strongSelf = self { strongSelf.inProgressDimNode.isUserInteractionEnabled = false strongSelf.inProgressDimNode.alpha = 0.0 diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutInfoControllerNode.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutInfoControllerNode.swift index 8f91094946..034628432e 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutInfoControllerNode.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutInfoControllerNode.swift @@ -338,7 +338,7 @@ final class BotCheckoutInfoControllerNode: ViewControllerTracingNode, UIScrollVi func verify() { self.isVerifying = true let formInfo = self.collectFormInfo() - self.verifyDisposable.set((validateBotPaymentForm(account: self.context.account, saveInfo: self.saveInfoItem.isOn, messageId: self.messageId, formInfo: formInfo) |> deliverOnMainQueue).start(next: { [weak self] result in + self.verifyDisposable.set((self.context.engine.payments.validateBotPaymentForm(saveInfo: self.saveInfoItem.isOn, messageId: self.messageId, formInfo: formInfo) |> deliverOnMainQueue).start(next: { [weak self] result in if let strongSelf = self { strongSelf.formInfoUpdated(formInfo, result) } diff --git a/submodules/BotPaymentsUI/Sources/BotReceiptControllerNode.swift b/submodules/BotPaymentsUI/Sources/BotReceiptControllerNode.swift index f605cf78dd..522e9f91bf 100644 --- a/submodules/BotPaymentsUI/Sources/BotReceiptControllerNode.swift +++ b/submodules/BotPaymentsUI/Sources/BotReceiptControllerNode.swift @@ -306,7 +306,7 @@ final class BotReceiptControllerNode: ItemListControllerNode { super.init(controller: controller, navigationBar: navigationBar, updateNavigationOffset: updateNavigationOffset, state: signal) - self.dataRequestDisposable = (requestBotPaymentReceipt(account: context.account, messageId: messageId) |> deliverOnMainQueue).start(next: { [weak self] receipt in + self.dataRequestDisposable = (context.engine.payments.requestBotPaymentReceipt(messageId: messageId) |> deliverOnMainQueue).start(next: { [weak self] receipt in if let strongSelf = self { UIView.transition(with: strongSelf.view, duration: 0.25, options: UIView.AnimationOptions.transitionCrossDissolve, animations: { }, completion: nil) diff --git a/submodules/CallListUI/Sources/CallListController.swift b/submodules/CallListUI/Sources/CallListController.swift index 01e5c07ff0..dc53949168 100644 --- a/submodules/CallListUI/Sources/CallListController.swift +++ b/submodules/CallListUI/Sources/CallListController.swift @@ -288,7 +288,7 @@ public final class CallListController: TelegramBaseController { return } - var signal = clearCallHistory(account: strongSelf.context.account, forEveryone: forEveryone) + var signal = strongSelf.context.engine.messages.clearCallHistory(forEveryone: forEveryone) var cancelImpl: (() -> Void)? let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } diff --git a/submodules/CallListUI/Sources/CallListControllerNode.swift b/submodules/CallListUI/Sources/CallListControllerNode.swift index db7cf53b83..52a77c4730 100644 --- a/submodules/CallListUI/Sources/CallListControllerNode.swift +++ b/submodules/CallListUI/Sources/CallListControllerNode.swift @@ -343,7 +343,7 @@ final class CallListControllerNode: ASDisplayNode { guard let strongSelf = self else { return } - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: messageIds, type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: messageIds, type: .forEveryone).start() })) items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.Conversation_DeleteMessagesForMe, color: .destructive, action: { [weak actionSheet] in @@ -353,7 +353,7 @@ final class CallListControllerNode: ASDisplayNode { return } - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: messageIds, type: .forLocalPeer).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: messageIds, type: .forLocalPeer).start() })) actionSheet.setItemGroups([ diff --git a/submodules/ChatImportUI/Sources/ChatImportActivityScreen.swift b/submodules/ChatImportUI/Sources/ChatImportActivityScreen.swift index 29fd0383e0..4c9001312c 100644 --- a/submodules/ChatImportUI/Sources/ChatImportActivityScreen.swift +++ b/submodules/ChatImportUI/Sources/ChatImportActivityScreen.swift @@ -823,7 +823,7 @@ public final class ChatImportActivityScreen: ViewController { let resolvedPeerId: Signal if self.peerId.namespace == Namespaces.Peer.CloudGroup { - resolvedPeerId = convertGroupToSupergroup(account: self.context.account, peerId: self.peerId) + resolvedPeerId = self.context.engine.peers.convertGroupToSupergroup(peerId: self.peerId) |> mapError { _ -> ImportManager.ImportError in return .generic } diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 71a48ce17a..113c170936 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -1180,7 +1180,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController if !self.didSuggestLocalization { self.didSuggestLocalization = true - let network = self.context.account.network + let context = self.context let signal = combineLatest(self.context.sharedContext.accountManager.transaction { transaction -> String in let languageCode: String if let current = transaction.getSharedData(SharedDataKeys.localizationSettings) as? LocalizationSettings { @@ -1206,7 +1206,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController guard let suggestedLocalization = value.1, !suggestedLocalization.isSeen && suggestedLocalization.languageCode != "en" && suggestedLocalization.languageCode != value.0 else { return .single(nil) } - return suggestedLocalizationInfo(network: network, languageCode: suggestedLocalization.languageCode, extractKeys: LanguageSuggestionControllerStrings.keys) + return context.engine.localization.suggestedLocalizationInfo(languageCode: suggestedLocalization.languageCode, extractKeys: LanguageSuggestionControllerStrings.keys) |> map({ suggestedLocalization -> (String, SuggestedLocalizationInfo)? in return (value.0, suggestedLocalization) }) @@ -1223,7 +1223,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController } }) { strongSelf.present(controller, in: .window(.root)) - _ = markSuggestedLocalizationAsSeenInteractively(postbox: strongSelf.context.account.postbox, languageCode: suggestedLocalization.languageCode).start() + _ = strongSelf.context.engine.localization.markSuggestedLocalizationAsSeenInteractively(languageCode: suggestedLocalization.languageCode).start() } })) @@ -2295,7 +2295,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController return false } if value == .commit { - let _ = clearHistoryInteractively(postbox: strongSelf.context.account.postbox, peerId: peerId, type: type).start(completed: { + let _ = strongSelf.context.engine.messages.clearHistoryInteractively(peerId: peerId, type: type).start(completed: { guard let strongSelf = self else { return } diff --git a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift index a2df45c8cd..5da162da88 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift @@ -844,7 +844,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo items.append(ActionSheetButtonItem(title: globalTitle, color: .destructive, action: { [weak actionSheet] in actionSheet?.dismissAnimated() if let strongSelf = self { - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() strongSelf.updateState { state in return state.withUpdatedSelectedMessageIds(nil) @@ -867,7 +867,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo items.append(ActionSheetButtonItem(title: localOptionText, color: .destructive, action: { [weak actionSheet] in actionSheet?.dismissAnimated() if let strongSelf = self { - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forLocalPeer).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forLocalPeer).start() strongSelf.updateState { state in return state.withUpdatedSelectedMessageIds(nil) diff --git a/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift b/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift index 7d2313a5f4..4bb50c8669 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift @@ -920,7 +920,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { addAppLogEvent(postbox: context.account.postbox, type: "search_global_query") } - let searchSignal = searchMessages(account: context.account, location: location, query: finalQuery, state: nil, limit: 50) + let searchSignal = context.engine.messages.searchMessages(location: location, query: finalQuery, state: nil, limit: 50) |> map { result, updatedState -> ChatListSearchMessagesResult in return ChatListSearchMessagesResult(query: finalQuery, messages: result.messages.sorted(by: { $0.index > $1.index }), readStates: result.readStates, hasMore: !result.completed, totalCount: result.totalCount, state: updatedState) } @@ -929,7 +929,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { |> mapToSignal { searchContext -> Signal<(([Message], [PeerId: CombinedPeerReadState], Int32), Bool), NoError> in if let searchContext = searchContext, searchContext.result.hasMore { if let _ = searchContext.loadMoreIndex { - return searchMessages(account: context.account, location: location, query: finalQuery, state: searchContext.result.state, limit: 80) + return context.engine.messages.searchMessages(location: location, query: finalQuery, state: searchContext.result.state, limit: 80) |> map { result, updatedState -> ChatListSearchMessagesResult in return ChatListSearchMessagesResult(query: finalQuery, messages: result.messages.sorted(by: { $0.index > $1.index }), readStates: result.readStates, hasMore: !result.completed, totalCount: result.totalCount, state: updatedState) } @@ -966,7 +966,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode { |> then(context.sharedContext.resolveUrl(context: context, peerId: nil, url: finalQuery, skipUrlAuth: true) |> mapToSignal { resolvedUrl -> Signal in if case let .channelMessage(_, messageId) = resolvedUrl { - return downloadMessage(postbox: context.account.postbox, network: context.account.network, messageId: messageId) + return context.engine.messages.downloadMessage(messageId: messageId) } else { return .single(nil) } diff --git a/submodules/ContactListUI/Sources/ContactContextMenus.swift b/submodules/ContactListUI/Sources/ContactContextMenus.swift index 2a525d8e60..17dbcc8682 100644 --- a/submodules/ContactListUI/Sources/ContactContextMenus.swift +++ b/submodules/ContactListUI/Sources/ContactContextMenus.swift @@ -61,7 +61,7 @@ func contactContextMenuItems(context: AccountContext, peerId: PeerId, contactsCo context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(currentPeerId), peekData: nil)) } } else { - var createSignal = createSecretChat(account: context.account, peerId: peerId) + var createSignal = context.engine.peers.createSecretChat(peerId: peerId) var cancelImpl: (() -> Void)? let progressSignal = Signal { subscriber in let presentationData = context.sharedContext.currentPresentationData.with { $0 } diff --git a/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift b/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift index 46fdf27b98..ad84f2079a 100644 --- a/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift +++ b/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift @@ -998,7 +998,7 @@ final class ChatItemGalleryFooterContentNode: GalleryFooterContentNode, UIScroll items.append(ActionSheetButtonItem(title: globalTitle, color: .destructive, action: { [weak actionSheet] in actionSheet?.dismissAnimated() if let strongSelf = self { - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: messages.map { $0.id }, type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: messages.map { $0.id }, type: .forEveryone).start() strongSelf.controllerInteraction?.dismissController() } })) @@ -1013,13 +1013,13 @@ final class ChatItemGalleryFooterContentNode: GalleryFooterContentNode, UIScroll items.append(ActionSheetButtonItem(title: localOptionText, color: .destructive, action: { [weak actionSheet] in actionSheet?.dismissAnimated() if let strongSelf = self { - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: messages.map { $0.id }, type: .forLocalPeer).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: messages.map { $0.id }, type: .forLocalPeer).start() strongSelf.controllerInteraction?.dismissController() } })) } if !ask && items.count == 1 { - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: messages.map { $0.id }, type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: messages.map { $0.id }, type: .forEveryone).start() strongSelf.controllerInteraction?.dismissController() } else if !items.isEmpty { strongSelf.interacting?(true) diff --git a/submodules/HashtagSearchUI/Sources/HashtagSearchController.swift b/submodules/HashtagSearchUI/Sources/HashtagSearchController.swift index 03b576262f..1bbf864d87 100644 --- a/submodules/HashtagSearchUI/Sources/HashtagSearchController.swift +++ b/submodules/HashtagSearchUI/Sources/HashtagSearchController.swift @@ -43,7 +43,7 @@ public final class HashtagSearchController: TelegramBaseController { let chatListPresentationData = ChatListPresentationData(theme: self.presentationData.theme, fontSize: self.presentationData.listsFontSize, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, nameSortOrder: self.presentationData.nameSortOrder, nameDisplayOrder: self.presentationData.nameDisplayOrder, disableAnimations: self.presentationData.disableAnimations) let location: SearchMessagesLocation = .general(tags: nil, minDate: nil, maxDate: nil) - let search = searchMessages(account: context.account, location: location, query: query, state: nil) + let search = context.engine.messages.searchMessages(location: location, query: query, state: nil) let foundMessages: Signal<[ChatListSearchEntry], NoError> = search |> map { result, _ in return result.messages.map({ .message($0, RenderedPeer(message: $0), result.readStates[$0.id.peerId], chatListPresentationData, result.totalCount, nil, false) }) diff --git a/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewController.swift b/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewController.swift index 82c76ccd0c..fb69b70373 100644 --- a/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewController.swift +++ b/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewController.swift @@ -65,7 +65,7 @@ public final class LanguageLinkPreviewController: ViewController { } self.displayNodeDidLoad() - self.disposable.set((requestLocalizationPreview(network: self.context.account.network, identifier: self.identifier) + self.disposable.set((self.context.engine.localization.requestLocalizationPreview(identifier: self.identifier) |> deliverOnMainQueue).start(next: { [weak self] result in guard let strongSelf = self else { return @@ -115,7 +115,7 @@ public final class LanguageLinkPreviewController: ViewController { return } self.controllerNode.setInProgress(true) - self.disposable.set((downloadAndApplyLocalization(accountManager: self.context.sharedContext.accountManager, postbox: self.context.account.postbox, network: self.context.account.network, languageCode: localizationInfo.languageCode) + self.disposable.set((self.context.engine.localization.downloadAndApplyLocalization(accountManager: self.context.sharedContext.accountManager, languageCode: localizationInfo.languageCode) |> deliverOnMainQueue).start(error: { [weak self] _ in guard let strongSelf = self else { return diff --git a/submodules/LanguageSuggestionUI/Sources/LanguageSuggestionController.swift b/submodules/LanguageSuggestionUI/Sources/LanguageSuggestionController.swift index bdde36d467..0635c5b176 100644 --- a/submodules/LanguageSuggestionUI/Sources/LanguageSuggestionController.swift +++ b/submodules/LanguageSuggestionUI/Sources/LanguageSuggestionController.swift @@ -353,7 +353,7 @@ public func languageSuggestionController(context: AccountContext, suggestedLocal dismissImpl?(true) } else { startActivity() - disposable.set((downloadAndApplyLocalization(accountManager: context.sharedContext.accountManager, postbox: context.account.postbox, network: context.account.network, languageCode: languageCode) + disposable.set((context.engine.localization.downloadAndApplyLocalization(accountManager: context.sharedContext.accountManager, languageCode: languageCode) |> deliverOnMainQueue).start(completed: { dismissImpl?(true) })) diff --git a/submodules/LiveLocationManager/Sources/LiveLocationManager.swift b/submodules/LiveLocationManager/Sources/LiveLocationManager.swift index 0cb7e547ea..d407c26456 100644 --- a/submodules/LiveLocationManager/Sources/LiveLocationManager.swift +++ b/submodules/LiveLocationManager/Sources/LiveLocationManager.swift @@ -10,9 +10,7 @@ import AccountContext public final class LiveLocationManagerImpl: LiveLocationManager { private let queue = Queue.mainQueue() - private let postbox: Postbox - private let network: Network - private let stateManager: AccountStateManager + private let account: Account private let locationManager: DeviceLocationManager private let summaryManagerImpl: LiveLocationSummaryManagerImpl @@ -46,16 +44,14 @@ public final class LiveLocationManagerImpl: LiveLocationManager { private var invalidationTimer: (SwiftSignalKit.Timer, Int32)? - public init(postbox: Postbox, network: Network, accountPeerId: PeerId, viewTracker: AccountViewTracker, stateManager: AccountStateManager, locationManager: DeviceLocationManager, inForeground: Signal) { - self.postbox = postbox - self.network = network - self.stateManager = stateManager + public init(account: Account, locationManager: DeviceLocationManager, inForeground: Signal) { + self.account = account self.locationManager = locationManager - self.summaryManagerImpl = LiveLocationSummaryManagerImpl(queue: self.queue, postbox: postbox, accountPeerId: accountPeerId, viewTracker: viewTracker) + self.summaryManagerImpl = LiveLocationSummaryManagerImpl(queue: self.queue, postbox: account.postbox, accountPeerId: account.peerId, viewTracker: account.viewTracker) let viewKey: PostboxViewKey = .localMessageTag(.OutgoingLiveLocation) - self.messagesDisposable = (postbox.combinedView(keys: [viewKey]) + self.messagesDisposable = (account.postbox.combinedView(keys: [viewKey]) |> deliverOn(self.queue)).start(next: { [weak self] view in if let strongSelf = self { let timestamp = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970) @@ -175,7 +171,7 @@ public final class LiveLocationManagerImpl: LiveLocationManager { let addedStopped = stopMessageIds.subtracting(self.stopMessageIds) self.stopMessageIds = stopMessageIds for id in addedStopped { - self.editMessageDisposables.set((requestEditLiveLocation(postbox: self.postbox, network: self.network, stateManager: self.stateManager, messageId: id, stop: true, coordinate: nil, heading: nil, proximityNotificationRadius: nil) + self.editMessageDisposables.set((TelegramEngine(account: self.account).messages.requestEditLiveLocation(messageId: id, stop: true, coordinate: nil, heading: nil, proximityNotificationRadius: nil) |> deliverOn(self.queue)).start(completed: { [weak self] in if let strongSelf = self { strongSelf.editMessageDisposables.set(nil, forKey: id) @@ -230,7 +226,7 @@ public final class LiveLocationManagerImpl: LiveLocationManager { let ids = self.broadcastToMessageIds let remainingIds = Atomic>(value: Set(ids.keys)) for id in ids.keys { - self.editMessageDisposables.set((requestEditLiveLocation(postbox: self.postbox, network: self.network, stateManager: self.stateManager, messageId: id, stop: false, coordinate: (latitude: coordinate.latitude, longitude: coordinate.longitude, accuracyRadius: Int32(accuracyRadius)), heading: heading.flatMap { Int32($0) }, proximityNotificationRadius: nil) + self.editMessageDisposables.set((TelegramEngine(account: self.account).messages.requestEditLiveLocation(messageId: id, stop: false, coordinate: (latitude: coordinate.latitude, longitude: coordinate.longitude, accuracyRadius: Int32(accuracyRadius)), heading: heading.flatMap { Int32($0) }, proximityNotificationRadius: nil) |> deliverOn(self.queue)).start(completed: { [weak self] in if let strongSelf = self { strongSelf.editMessageDisposables.set(nil, forKey: id) @@ -253,7 +249,7 @@ public final class LiveLocationManagerImpl: LiveLocationManager { let ids = self.broadcastToMessageIds.keys.filter({ $0.peerId == peerId }) if !ids.isEmpty { - let _ = self.postbox.transaction({ transaction -> Void in + let _ = self.account.postbox.transaction({ transaction -> Void in for id in ids { transaction.updateMessage(id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? diff --git a/submodules/LocationUI/Sources/LocationViewController.swift b/submodules/LocationUI/Sources/LocationViewController.swift index 14920a2593..e99daa8f99 100644 --- a/submodules/LocationUI/Sources/LocationViewController.swift +++ b/submodules/LocationUI/Sources/LocationViewController.swift @@ -192,7 +192,7 @@ public final class LocationViewController: ViewController { return state } - let _ = requestEditLiveLocation(postbox: context.account.postbox, network: context.account.network, stateManager: context.account.stateManager, messageId: messageId, stop: false, coordinate: nil, heading: nil, proximityNotificationRadius: 0).start(completed: { [weak self] in + let _ = context.engine.messages.requestEditLiveLocation(messageId: messageId, stop: false, coordinate: nil, heading: nil, proximityNotificationRadius: 0).start(completed: { [weak self] in guard let strongSelf = self else { return } @@ -261,7 +261,7 @@ public final class LocationViewController: ViewController { return state } - let _ = requestEditLiveLocation(postbox: context.account.postbox, network: context.account.network, stateManager: context.account.stateManager, messageId: messageId, stop: false, coordinate: nil, heading: nil, proximityNotificationRadius: distance).start(completed: { [weak self] in + let _ = context.engine.messages.requestEditLiveLocation(messageId: messageId, stop: false, coordinate: nil, heading: nil, proximityNotificationRadius: distance).start(completed: { [weak self] in guard let strongSelf = self else { return } diff --git a/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryController.swift b/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryController.swift index e901ef56c9..4b0324d822 100644 --- a/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryController.swift +++ b/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryController.swift @@ -885,7 +885,7 @@ public class AvatarGalleryController: ViewController, StandalonePresentableContr } } else { if let messageId = messageId { - let _ = deleteMessagesInteractively(account: self.context.account, messageIds: [messageId], type: .forEveryone).start() + let _ = self.context.engine.messages.deleteMessagesInteractively(messageIds: [messageId], type: .forEveryone).start() } if entry == self.entries.first { diff --git a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift index 45416f9842..24cb05f037 100644 --- a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift @@ -1220,7 +1220,7 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi case conversionFailed } - let signal = convertGroupToSupergroup(account: context.account, peerId: peerId) + let signal = context.engine.peers.convertGroupToSupergroup(peerId: peerId) |> map(Optional.init) |> `catch` { error -> Signal in switch error { diff --git a/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift b/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift index 872d4bea6a..6ddf88abf6 100644 --- a/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift @@ -650,7 +650,7 @@ public func channelBannedMemberController(context: AccountContext, peerId: PeerI } if peerId.namespace == Namespaces.Peer.CloudGroup { - let signal = convertGroupToSupergroup(account: context.account, peerId: peerId) + let signal = context.engine.peers.convertGroupToSupergroup(peerId: peerId) |> map(Optional.init) |> `catch` { error -> Signal in switch error { diff --git a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift index 7c16bdf96b..eee1c7a3fa 100644 --- a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift @@ -327,7 +327,7 @@ public func channelDiscussionGroupSetupController(context: AccountContext, peerI var applySignal: Signal var updatedPeerId: PeerId? = nil if let legacyGroup = groupPeer as? TelegramGroup { - applySignal = convertGroupToSupergroup(account: context.account, peerId: legacyGroup.id) + applySignal = context.engine.peers.convertGroupToSupergroup(peerId: legacyGroup.id) |> mapError { error -> ChannelDiscussionGroupError in switch error { case .tooManyChannels: diff --git a/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift b/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift index 2dc4cd0c0f..c25f8f176d 100644 --- a/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift @@ -460,7 +460,7 @@ private func commitChannelOwnershipTransferController(context: AccountContext, p } |> then(.single(nil)) } else if let peer = peer as? TelegramGroup { - signal = convertGroupToSupergroup(account: context.account, peerId: peer.id) + signal = context.engine.peers.convertGroupToSupergroup(peerId: peer.id) |> map(Optional.init) |> mapError { error -> ChannelOwnershipTransferError in switch error { diff --git a/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift b/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift index b416888015..540cce7c68 100644 --- a/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift @@ -797,7 +797,7 @@ public func channelPermissionsController(context: AccountContext, peerId origina let progress = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) presentControllerImpl?(progress, nil) - let signal = convertGroupToSupergroup(account: context.account, peerId: view.peerId) + let signal = context.engine.peers.convertGroupToSupergroup(peerId: view.peerId) |> mapError { error -> UpdateChannelSlowModeError in switch error { case .tooManyChannels: diff --git a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift index bb0fa9d466..9c0cb6985a 100644 --- a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift @@ -1171,7 +1171,7 @@ public func channelVisibilityController(context: AccountContext, peerId: PeerId, } _ = ApplicationSpecificNotice.markAsSeenSetPublicChannelLink(accountManager: context.sharedContext.accountManager).start() - let signal = convertGroupToSupergroup(account: context.account, peerId: peerId) + let signal = context.engine.peers.convertGroupToSupergroup(peerId: peerId) |> mapToSignal { upgradedPeerId -> Signal in return context.engine.peers.updateAddressName(domain: .peer(upgradedPeerId), name: updatedAddressNameValue.isEmpty ? nil : updatedAddressNameValue) |> `catch` { _ -> Signal in diff --git a/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift b/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift index 494e9537c2..b1dbe193b9 100644 --- a/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift +++ b/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift @@ -149,7 +149,7 @@ public func convertToSupergroupController(context: AccountContext, peerId: PeerI } if !alreadyConverting { - convertDisposable.set((convertGroupToSupergroup(account: context.account, peerId: peerId) + convertDisposable.set((context.engine.peers.convertGroupToSupergroup(peerId: peerId) |> deliverOnMainQueue).start(next: { createdPeerId in replaceControllerImpl?(context.sharedContext.makeChatController(context: context, chatLocation: .peer(createdPeerId), subject: nil, botStart: nil, mode: .standard(previewing: false))) })) diff --git a/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift b/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift index f16c20505d..6ef4e75beb 100644 --- a/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift +++ b/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift @@ -161,7 +161,7 @@ public func groupPreHistorySetupController(context: AccountContext, peerId: Peer } if let value = value, value != defaultValue { if peerId.namespace == Namespaces.Peer.CloudGroup { - let signal = convertGroupToSupergroup(account: context.account, peerId: peerId) + let signal = context.engine.peers.convertGroupToSupergroup(peerId: peerId) |> mapToSignal { upgradedPeerId -> Signal in return updateChannelHistoryAvailabilitySettingsInteractively(postbox: context.account.postbox, network: context.account.network, accountStateManager: context.account.stateManager, peerId: upgradedPeerId, historyAvailableForNewMembers: value) |> `catch` { _ -> Signal in diff --git a/submodules/PeerInfoUI/Sources/PeerAutoremoveSetupScreen.swift b/submodules/PeerInfoUI/Sources/PeerAutoremoveSetupScreen.swift index 3840254013..6767eab567 100644 --- a/submodules/PeerInfoUI/Sources/PeerAutoremoveSetupScreen.swift +++ b/submodules/PeerInfoUI/Sources/PeerAutoremoveSetupScreen.swift @@ -212,7 +212,7 @@ public func peerAutoremoveSetupScreen(context: AccountContext, peerId: PeerId, c } if updated { - let signal = setChatMessageAutoremoveTimeoutInteractively(account: context.account, peerId: peerId, timeout: resolvedValue) + let signal = context.engine.peers.setChatMessageAutoremoveTimeoutInteractively(peerId: peerId, timeout: resolvedValue) |> deliverOnMainQueue applyDisposable.set((signal diff --git a/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift b/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift index f7393cf892..9beb049164 100644 --- a/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift +++ b/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift @@ -418,7 +418,7 @@ final class LocalizationListControllerNode: ViewControllerTracingNode { let transition = preparedLanguageListNodeTransition(presentationData: presentationData, from: previousEntriesAndPresentationData?.0 ?? [], to: entries, openSearch: openSearch, selectLocalization: { [weak self] info in self?.selectLocalization(info) }, setItemWithRevealedOptions: setItemWithRevealedOptions, removeItem: removeItem, firstTime: previousEntriesAndPresentationData == nil, isLoading: entries.isEmpty, forceUpdate: previousEntriesAndPresentationData?.1 !== presentationData.theme || previousEntriesAndPresentationData?.2 !== presentationData.strings, animated: (previousEntriesAndPresentationData?.0.count ?? 0) >= entries.count, crossfade: (previousState == nil) != (localizationListState == nil)) strongSelf.enqueueTransition(transition) }) - self.updatedDisposable = synchronizedLocalizationListState(postbox: context.account.postbox, network: context.account.network).start() + self.updatedDisposable = context.engine.localization.synchronizedLocalizationListState().start() } deinit { @@ -501,7 +501,7 @@ final class LocalizationListControllerNode: ViewControllerTracingNode { return } strongSelf.applyingCode.set(.single(info.languageCode)) - strongSelf.applyDisposable.set((downloadAndApplyLocalization(accountManager: strongSelf.context.sharedContext.accountManager, postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, languageCode: info.languageCode) + strongSelf.applyDisposable.set((strongSelf.context.engine.localization.downloadAndApplyLocalization(accountManager: strongSelf.context.sharedContext.accountManager, languageCode: info.languageCode) |> deliverOnMainQueue).start(completed: { self?.applyingCode.set(.single(nil)) })) diff --git a/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift index 3aa25bcff8..04c8921075 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift @@ -360,7 +360,7 @@ public func dataPrivacyController(context: AccountContext) -> ViewController { info.insert(.shippingInfo) } - clearPaymentInfoDisposable.set((clearBotPaymentInfo(network: context.account.network, info: info) + clearPaymentInfoDisposable.set((context.engine.payments.clearBotPaymentInfo(info: info) |> deliverOnMainQueue).start(completed: { updateState { state in var state = state @@ -482,7 +482,7 @@ public func dataPrivacyController(context: AccountContext) -> ViewController { return state } if clear { - clearPaymentInfoDisposable.set((clearCloudDraftsInteractively(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId) + clearPaymentInfoDisposable.set((context.engine.messages.clearCloudDraftsInteractively() |> deliverOnMainQueue).start(completed: { updateState { state in var state = state diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift index 0f79690bd9..a3f57b7fd6 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift @@ -708,7 +708,7 @@ private func languageSearchableItems(context: AccountContext, localizations: [Lo let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) present(.immediate, controller) - let _ = (downloadAndApplyLocalization(accountManager: context.sharedContext.accountManager, postbox: context.account.postbox, network: context.account.network, languageCode: languageCode) + let _ = (context.engine.localization.downloadAndApplyLocalization(accountManager: context.sharedContext.accountManager, languageCode: languageCode) |> deliverOnMainQueue).start(completed: { [weak controller] in controller?.dismiss() present(.dismiss, nil) diff --git a/submodules/ShareController/Sources/ShareController.swift b/submodules/ShareController/Sources/ShareController.swift index 785e24c330..dcf21b5996 100644 --- a/submodules/ShareController/Sources/ShareController.swift +++ b/submodules/ShareController/Sources/ShareController.swift @@ -618,7 +618,7 @@ public final class ShareController: ViewController { if let error = error { Queue.mainQueue().async { let _ = (account.postbox.transaction { transaction -> Peer? in - deleteMessages(transaction: transaction, mediaBox: account.postbox.mediaBox, ids: [id]) + TelegramEngine(account: account).messages.deleteMessages(transaction: transaction, ids: [id]) return transaction.getPeer(id.peerId) } |> deliverOnMainQueue).start(next: { peer in diff --git a/submodules/StatisticsUI/Sources/MessageStatsController.swift b/submodules/StatisticsUI/Sources/MessageStatsController.swift index 72ce6daff7..cd36e64526 100644 --- a/submodules/StatisticsUI/Sources/MessageStatsController.swift +++ b/submodules/StatisticsUI/Sources/MessageStatsController.swift @@ -215,13 +215,13 @@ public func messageStatsController(context: AccountContext, messageId: MessageId let previousData = Atomic(value: nil) - let searchSignal = searchMessages(account: context.account, location: .publicForwards(messageId: messageId, datacenterId: Int(datacenterId)), query: "", state: nil) + let searchSignal = context.engine.messages.searchMessages(location: .publicForwards(messageId: messageId, datacenterId: Int(datacenterId)), query: "", state: nil) |> map(Optional.init) |> afterNext { result in if let result = result { for message in result.0.messages { if let peer = message.peers[message.id.peerId], let peerReference = PeerReference(peer) { - let _ = updatedRemotePeer(postbox: context.account.postbox, network: context.account.network, peer: peerReference).start() + let _ = context.engine.peers.updatedRemotePeer(peer: peerReference).start() } } } diff --git a/submodules/TelegramCore/Sources/CachedChannelParticipants.swift b/submodules/TelegramCore/Sources/ApiUtils/CachedChannelParticipants.swift similarity index 100% rename from submodules/TelegramCore/Sources/CachedChannelParticipants.swift rename to submodules/TelegramCore/Sources/ApiUtils/CachedChannelParticipants.swift diff --git a/submodules/TelegramCore/Sources/CachedGroupParticipants.swift b/submodules/TelegramCore/Sources/ApiUtils/CachedGroupParticipants.swift similarity index 100% rename from submodules/TelegramCore/Sources/CachedGroupParticipants.swift rename to submodules/TelegramCore/Sources/ApiUtils/CachedGroupParticipants.swift diff --git a/submodules/TelegramCore/Sources/CloudFileMediaResource.swift b/submodules/TelegramCore/Sources/ApiUtils/CloudFileMediaResource.swift similarity index 100% rename from submodules/TelegramCore/Sources/CloudFileMediaResource.swift rename to submodules/TelegramCore/Sources/ApiUtils/CloudFileMediaResource.swift diff --git a/submodules/TelegramCore/Sources/CloudMediaResourceParameters.swift b/submodules/TelegramCore/Sources/ApiUtils/CloudMediaResourceParameters.swift similarity index 100% rename from submodules/TelegramCore/Sources/CloudMediaResourceParameters.swift rename to submodules/TelegramCore/Sources/ApiUtils/CloudMediaResourceParameters.swift diff --git a/submodules/TelegramCore/Sources/EncryptedMediaResource.swift b/submodules/TelegramCore/Sources/ApiUtils/EncryptedMediaResource.swift similarity index 100% rename from submodules/TelegramCore/Sources/EncryptedMediaResource.swift rename to submodules/TelegramCore/Sources/ApiUtils/EncryptedMediaResource.swift diff --git a/submodules/TelegramCore/Sources/ImageRepresentationWithReference.swift b/submodules/TelegramCore/Sources/ApiUtils/ImageRepresentationWithReference.swift similarity index 100% rename from submodules/TelegramCore/Sources/ImageRepresentationWithReference.swift rename to submodules/TelegramCore/Sources/ApiUtils/ImageRepresentationWithReference.swift diff --git a/submodules/TelegramCore/Sources/Authorization.swift b/submodules/TelegramCore/Sources/Authorization.swift index a921cdf250..fd9d45105b 100644 --- a/submodules/TelegramCore/Sources/Authorization.swift +++ b/submodules/TelegramCore/Sources/Authorization.swift @@ -31,6 +31,44 @@ func switchToAuthorizedAccount(transaction: AccountManagerModifier, account: Una transaction.removeAuth() } +private struct Regex { + let pattern: String + let options: NSRegularExpression.Options! + + private var matcher: NSRegularExpression { + return try! NSRegularExpression(pattern: self.pattern, options: self.options) + } + + init(_ pattern: String) { + self.pattern = pattern + self.options = [] + } + + func match(_ string: String, options: NSRegularExpression.MatchingOptions = []) -> Bool { + return self.matcher.numberOfMatches(in: string, options: options, range: NSMakeRange(0, string.utf16.count)) != 0 + } +} + +private protocol RegularExpressionMatchable { + func match(_ regex: Regex) -> Bool +} + +private struct MatchString: RegularExpressionMatchable { + private let string: String + + init(_ string: String) { + self.string = string + } + + func match(_ regex: Regex) -> Bool { + return regex.match(self.string) + } +} + +private func ~=(pattern: Regex, matchable: T) -> Bool { + return matchable.match(pattern) +} + public func sendAuthorizationCode(accountManager: AccountManager, account: UnauthorizedAccount, phoneNumber: String, apiId: Int32, apiHash: String, syncContacts: Bool) -> Signal { let sendCode = Api.functions.auth.sendCode(phoneNumber: phoneNumber, apiId: apiId, apiHash: apiHash, settings: .codeSettings(flags: 0)) @@ -39,7 +77,7 @@ public func sendAuthorizationCode(accountManager: AccountManager, account: Unaut return (result, account) } |> `catch` { error -> Signal<(Api.auth.SentCode, UnauthorizedAccount), MTRpcError> in - switch (error.errorDescription ?? "") { + switch MatchString(error.errorDescription ?? "") { case Regex("(PHONE_|USER_|NETWORK_)MIGRATE_(\\d+)"): let range = error.errorDescription.range(of: "MIGRATE_")! let updatedMasterDatacenterId = Int32(error.errorDescription[range.upperBound ..< error.errorDescription.endIndex])! @@ -85,7 +123,6 @@ public func sendAuthorizationCode(accountManager: AccountManager, account: Unaut return account } |> mapError { _ -> AuthorizationCodeRequestError in - return .generic(info: nil) } } } @@ -123,7 +160,7 @@ public func resendAuthorizationCode(account: UnauthorizedAccount) -> Signal mapError { _ -> AuthorizationCodeRequestError in return .generic(info: nil) } + } |> mapError { _ -> AuthorizationCodeRequestError in } } } else { return .fail(.generic(info: nil)) @@ -136,7 +173,6 @@ public func resendAuthorizationCode(account: UnauthorizedAccount) -> Signal mapError { _ -> AuthorizationCodeRequestError in - return .generic(info: nil) } |> switchToLatest } @@ -233,7 +269,6 @@ public func authorizeWithCode(accountManager: AccountManager, account: Unauthori } |> switchToLatest |> mapError { _ -> AuthorizationCodeVerificationError in - return .generic } } default: @@ -244,7 +279,6 @@ public func authorizeWithCode(accountManager: AccountManager, account: Unauthori } } |> mapError { _ -> AuthorizationCodeVerificationError in - return .generic } |> switchToLatest } @@ -294,7 +328,6 @@ public func authorizeWithPassword(accountManager: AccountManager, account: Unaut } |> switchToLatest |> mapError { _ -> AuthorizationPasswordVerificationError in - return .generic } } } @@ -369,7 +402,7 @@ public func performPasswordRecovery(accountManager: AccountManager, account: Una } } |> switchToLatest - |> mapError { _ in return PasswordRecoveryError.expired } + |> mapError { _ -> PasswordRecoveryError in } } } @@ -418,7 +451,7 @@ public func performAccountReset(account: UnauthorizedAccount) -> Signal mapError { _ in return AccountResetError.generic } + |> mapError { _ -> AccountResetError in } } } @@ -497,7 +530,6 @@ public func signUpWithName(accountManager: AccountManager, account: Unauthorized } } |> mapError { _ -> SignUpError in - return .generic } |> switchToLatest } diff --git a/submodules/TelegramCore/Sources/FetchedMediaResource.swift b/submodules/TelegramCore/Sources/FetchedMediaResource.swift index 0adc130a3c..8196b509b6 100644 --- a/submodules/TelegramCore/Sources/FetchedMediaResource.swift +++ b/submodules/TelegramCore/Sources/FetchedMediaResource.swift @@ -369,7 +369,7 @@ final class MediaReferenceRevalidationContext { func peer(postbox: Postbox, network: Network, background: Bool, peer: PeerReference) -> Signal { return self.genericItem(key: .peer(peer: peer), background: background, request: { next, error in - return (updatedRemotePeer(postbox: postbox, network: network, peer: peer) + return (_internal_updatedRemotePeer(postbox: postbox, network: network, peer: peer) |> mapError { _ -> RevalidateMediaReferenceError in return .generic }).start(next: { value in diff --git a/submodules/TelegramCore/Sources/HistoryViewStateValidation.swift b/submodules/TelegramCore/Sources/HistoryViewStateValidation.swift index b5988b23ae..9dfa747529 100644 --- a/submodules/TelegramCore/Sources/HistoryViewStateValidation.swift +++ b/submodules/TelegramCore/Sources/HistoryViewStateValidation.swift @@ -832,7 +832,7 @@ private func validateBatch(postbox: Postbox, network: Network, transaction: Tran return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, threadId: currentMessage.threadId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: updatedTags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media)) }) } else { - deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [id]) + _internal_deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [id]) Logger.shared.log("HistoryValidation", "deleting message \(id) in \(id.peerId)") } } @@ -1011,7 +1011,7 @@ private func validateReplyThreadBatch(postbox: Postbox, network: Network, transa for id in removedMessageIds { if !validMessageIds.contains(id) { - deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [id]) + _internal_deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [id]) Logger.shared.log("HistoryValidation", "deleting thread message \(id) in \(id.peerId)") } } diff --git a/submodules/TelegramCore/Sources/InstallInteractiveReadMessagesAction.swift b/submodules/TelegramCore/Sources/InstallInteractiveReadMessagesAction.swift index ec862edad0..fd5a79dc92 100644 --- a/submodules/TelegramCore/Sources/InstallInteractiveReadMessagesAction.swift +++ b/submodules/TelegramCore/Sources/InstallInteractiveReadMessagesAction.swift @@ -56,7 +56,7 @@ public func installInteractiveReadMessagesAction(postbox: Postbox, stateManager: } for (_, index) in readMessageIndexByNamespace { - applyMaxReadIndexInteractively(transaction: transaction, stateManager: stateManager, index: index) + _internal_applyMaxReadIndexInteractively(transaction: transaction, stateManager: stateManager, index: index) } }) } diff --git a/submodules/TelegramCore/Sources/MacInternalUpdater.swift b/submodules/TelegramCore/Sources/MacOS/MacInternalUpdater.swift similarity index 100% rename from submodules/TelegramCore/Sources/MacInternalUpdater.swift rename to submodules/TelegramCore/Sources/MacOS/MacInternalUpdater.swift diff --git a/submodules/TelegramCore/Sources/ChatUpdatingMessageMedia.swift b/submodules/TelegramCore/Sources/PendingMessages/ChatUpdatingMessageMedia.swift similarity index 100% rename from submodules/TelegramCore/Sources/ChatUpdatingMessageMedia.swift rename to submodules/TelegramCore/Sources/PendingMessages/ChatUpdatingMessageMedia.swift diff --git a/submodules/TelegramCore/Sources/EnqueueMessage.swift b/submodules/TelegramCore/Sources/PendingMessages/EnqueueMessage.swift similarity index 99% rename from submodules/TelegramCore/Sources/EnqueueMessage.swift rename to submodules/TelegramCore/Sources/PendingMessages/EnqueueMessage.swift index 7c66f0c083..3599c947c6 100644 --- a/submodules/TelegramCore/Sources/EnqueueMessage.swift +++ b/submodules/TelegramCore/Sources/PendingMessages/EnqueueMessage.swift @@ -260,7 +260,7 @@ public func resendMessages(account: Account, messageIds: [MessageId]) -> Signal< } let _ = enqueueMessages(transaction: transaction, account: account, peerId: peerId, messages: messages.map { (false, $0) }) } - deleteMessages(transaction: transaction, mediaBox: account.postbox.mediaBox, ids: removeMessageIds, deleteMedia: false) + _internal_deleteMessages(transaction: transaction, mediaBox: account.postbox.mediaBox, ids: removeMessageIds, deleteMedia: false) } } diff --git a/submodules/TelegramCore/Sources/PendingMessageUploadedContent.swift b/submodules/TelegramCore/Sources/PendingMessages/PendingMessageUploadedContent.swift similarity index 100% rename from submodules/TelegramCore/Sources/PendingMessageUploadedContent.swift rename to submodules/TelegramCore/Sources/PendingMessages/PendingMessageUploadedContent.swift diff --git a/submodules/TelegramCore/Sources/PendingUpdateMessageManager.swift b/submodules/TelegramCore/Sources/PendingMessages/PendingUpdateMessageManager.swift similarity index 100% rename from submodules/TelegramCore/Sources/PendingUpdateMessageManager.swift rename to submodules/TelegramCore/Sources/PendingMessages/PendingUpdateMessageManager.swift diff --git a/submodules/TelegramCore/Sources/RequestEditMessage.swift b/submodules/TelegramCore/Sources/PendingMessages/RequestEditMessage.swift similarity index 96% rename from submodules/TelegramCore/Sources/RequestEditMessage.swift rename to submodules/TelegramCore/Sources/PendingMessages/RequestEditMessage.swift index 69ffc23c06..a97ce331bb 100644 --- a/submodules/TelegramCore/Sources/RequestEditMessage.swift +++ b/submodules/TelegramCore/Sources/PendingMessages/RequestEditMessage.swift @@ -28,7 +28,7 @@ public enum RequestEditMessageError { case invalidGrouping } -public func requestEditMessage(account: Account, messageId: MessageId, text: String, media: RequestEditMessageMedia, entities: TextEntitiesMessageAttribute? = nil, disableUrlPreview: Bool = false, scheduleTime: Int32? = nil) -> Signal { +func _internal_requestEditMessage(account: Account, messageId: MessageId, text: String, media: RequestEditMessageMedia, entities: TextEntitiesMessageAttribute? = nil, disableUrlPreview: Bool = false, scheduleTime: Int32? = nil) -> Signal { return requestEditMessage(postbox: account.postbox, network: account.network, stateManager: account.stateManager, transformOutgoingMessageMedia: account.transformOutgoingMessageMedia, messageMediaPreuploadManager: account.messageMediaPreuploadManager, mediaReferenceRevalidationContext: account.mediaReferenceRevalidationContext, messageId: messageId, text: text, media: media, entities: entities, disableUrlPreview: disableUrlPreview, scheduleTime: scheduleTime) } @@ -255,7 +255,7 @@ private func requestEditMessageInternal(postbox: Postbox, network: Network, stat } } -public func requestEditLiveLocation(postbox: Postbox, network: Network, stateManager: AccountStateManager, messageId: MessageId, stop: Bool, coordinate: (latitude: Double, longitude: Double, accuracyRadius: Int32?)?, heading: Int32?, proximityNotificationRadius: Int32?) -> Signal { +func _internal_requestEditLiveLocation(postbox: Postbox, network: Network, stateManager: AccountStateManager, messageId: MessageId, stop: Bool, coordinate: (latitude: Double, longitude: Double, accuracyRadius: Int32?)?, heading: Int32?, proximityNotificationRadius: Int32?) -> Signal { return postbox.transaction { transaction -> (Api.InputPeer, TelegramMediaMap)? in guard let inputPeer = transaction.getPeer(messageId.peerId).flatMap(apiInputPeer) else { return nil diff --git a/submodules/TelegramCore/Sources/StandaloneSendMessage.swift b/submodules/TelegramCore/Sources/PendingMessages/StandaloneSendMessage.swift similarity index 100% rename from submodules/TelegramCore/Sources/StandaloneSendMessage.swift rename to submodules/TelegramCore/Sources/PendingMessages/StandaloneSendMessage.swift diff --git a/submodules/TelegramCore/Sources/StandaloneUploadedMedia.swift b/submodules/TelegramCore/Sources/PendingMessages/StandaloneUploadedMedia.swift similarity index 100% rename from submodules/TelegramCore/Sources/StandaloneUploadedMedia.swift rename to submodules/TelegramCore/Sources/PendingMessages/StandaloneUploadedMedia.swift diff --git a/submodules/TelegramCore/Sources/Regex.swift b/submodules/TelegramCore/Sources/Regex.swift deleted file mode 100644 index 474e383e1f..0000000000 --- a/submodules/TelegramCore/Sources/Regex.swift +++ /dev/null @@ -1,33 +0,0 @@ -import Foundation - -public struct Regex { - let pattern: String - let options: NSRegularExpression.Options! - - private var matcher: NSRegularExpression { - return try! NSRegularExpression(pattern: self.pattern, options: self.options) - } - - public init(_ pattern: String) { - self.pattern = pattern - self.options = [] - } - - public func match(_ string: String, options: NSRegularExpression.MatchingOptions = []) -> Bool { - return self.matcher.numberOfMatches(in: string, options: options, range: NSMakeRange(0, string.utf16.count)) != 0 - } -} - -public protocol RegularExpressionMatchable { - func match(_ regex: Regex) -> Bool -} - -extension String: RegularExpressionMatchable { - public func match(_ regex: Regex) -> Bool { - return regex.match(self) - } -} - -public func ~=(pattern: Regex, matchable: T) -> Bool { - return matchable.match(pattern) -} diff --git a/submodules/TelegramCore/Sources/RemovePeerChat.swift b/submodules/TelegramCore/Sources/RemovePeerChat.swift index 0cae498d09..1b72cd2cdd 100644 --- a/submodules/TelegramCore/Sources/RemovePeerChat.swift +++ b/submodules/TelegramCore/Sources/RemovePeerChat.swift @@ -58,17 +58,17 @@ public func removePeerChat(account: Account, transaction: Transaction, mediaBox: } } } - clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId, namespaces: .all) + _internal_clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId, namespaces: .all) transaction.updatePeerChatListInclusion(peerId, inclusion: .notIncluded) transaction.removeOrderedItemListItem(collectionId: Namespaces.OrderedItemList.RecentlySearchedPeerIds, itemId: RecentPeerItemId(peerId).rawValue) } else { cloudChatAddRemoveChatOperation(transaction: transaction, peerId: peerId, reportChatSpam: reportChatSpam, deleteGloballyIfPossible: deleteGloballyIfPossible) if peerId.namespace == Namespaces.Peer.CloudUser { transaction.updatePeerChatListInclusion(peerId, inclusion: .notIncluded) - clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId, namespaces: .all) + _internal_clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId, namespaces: .all) } else if peerId.namespace == Namespaces.Peer.CloudGroup { transaction.updatePeerChatListInclusion(peerId, inclusion: .notIncluded) - clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId, namespaces: .all) + _internal_clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId, namespaces: .all) } else { transaction.updatePeerChatListInclusion(peerId, inclusion: .notIncluded) } diff --git a/submodules/TelegramCore/Sources/RequestPhoneNumber.swift b/submodules/TelegramCore/Sources/RequestPhoneNumber.swift deleted file mode 100644 index 575f55a634..0000000000 --- a/submodules/TelegramCore/Sources/RequestPhoneNumber.swift +++ /dev/null @@ -1,28 +0,0 @@ -import Foundation -import Postbox -import SwiftSignalKit -import TelegramApi - -public func requestPhoneNumber(account: Account, peerId: PeerId) -> Signal { - return .never() - /*return account.postbox.transaction { transaction -> Api.InputPeer? in - return transaction.getPeer(peerId).flatMap(apiInputPeer) - } - |> mapToSignal { inputPeer -> Signal in - guard let inputPeer = inputPeer else { - return .complete() - } - return account.network.request(Api.functions.messages.sendPhoneNumberRequest(peer: inputPeer, randomId: Int64.random(in: Int64.min ... Int64.max))) - |> map(Optional.init) - |> `catch` { _ -> Signal in - return .single(nil) - } - |> mapToSignal { updates -> Signal in - if let updates = updates { - account.stateManager.addUpdates(updates) - } - return .complete() - } - }*/ -} - diff --git a/submodules/TelegramCore/Sources/SecretChats/UpdateSecretChat.swift b/submodules/TelegramCore/Sources/SecretChats/UpdateSecretChat.swift index 7157b2735a..17a937f8f1 100644 --- a/submodules/TelegramCore/Sources/SecretChats/UpdateSecretChat.swift +++ b/submodules/TelegramCore/Sources/SecretChats/UpdateSecretChat.swift @@ -78,7 +78,7 @@ func updateSecretChat(encryptionProvider: EncryptionProvider, accountPeerId: Pee if isRemoved { let peerId = currentPeer.id - clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId, namespaces: .all) + _internal_clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId, namespaces: .all) transaction.updatePeerChatListInclusion(peerId, inclusion: .notIncluded) transaction.removeOrderedItemListItem(collectionId: Namespaces.OrderedItemList.RecentlySearchedPeerIds, itemId: RecentPeerItemId(peerId).rawValue) } diff --git a/submodules/TelegramCore/Sources/SingleMessageView.swift b/submodules/TelegramCore/Sources/SingleMessageView.swift deleted file mode 100644 index 203daf6bce..0000000000 --- a/submodules/TelegramCore/Sources/SingleMessageView.swift +++ /dev/null @@ -1,105 +0,0 @@ -import Foundation -import Postbox -import SwiftSignalKit -import TelegramApi -import MtProtoKit - -import SyncCore - -public func singleMessageView(account: Account, messageId: MessageId, loadIfNotExists: Bool) -> Signal { - return Signal { subscriber in - let loadedMessage = account.postbox.transaction { transaction -> Signal in - if transaction.getMessage(messageId) == nil, loadIfNotExists { - return fetchMessage(transaction: transaction, account: account, messageId: messageId) - } else { - return .complete() - } - } |> switchToLatest - - let disposable = loadedMessage.start() - let viewDisposable = account.postbox.messageView(messageId).start(next: { view in - subscriber.putNext(view) - }) - - return ActionDisposable { - disposable.dispose() - viewDisposable.dispose() - } - } -} - -private func fetchMessage(transaction: Transaction, account: Account, messageId: MessageId) -> Signal { - if let peer = transaction.getPeer(messageId.peerId) { - var signal: Signal? - if messageId.namespace == Namespaces.Message.ScheduledCloud { - if let inputPeer = apiInputPeer(peer) { - signal = account.network.request(Api.functions.messages.getScheduledMessages(peer: inputPeer, id: [messageId.id])) - } - } else if messageId.peerId.namespace == Namespaces.Peer.CloudUser || messageId.peerId.namespace == Namespaces.Peer.CloudGroup { - signal = account.network.request(Api.functions.messages.getMessages(id: [Api.InputMessage.inputMessageID(id: messageId.id)])) - } else if messageId.peerId.namespace == Namespaces.Peer.CloudChannel { - if let inputChannel = apiInputChannel(peer) { - signal = account.network.request(Api.functions.channels.getMessages(channel: inputChannel, id: [Api.InputMessage.inputMessageID(id: messageId.id)])) - } - } - if let signal = signal { - return signal - |> `catch` { _ -> Signal in - return .single(.messages(messages: [], chats: [], users: [])) - } - |> mapToSignal { result -> Signal in - return account.postbox.transaction { transaction -> Void in - let apiMessages: [Api.Message] - let apiChats: [Api.Chat] - let apiUsers: [Api.User] - switch result { - case let .messages(messages, chats, users): - apiMessages = messages - apiChats = chats - apiUsers = users - case let .messagesSlice(_, _, _, _, messages, chats, users): - apiMessages = messages - apiChats = chats - apiUsers = users - case let .channelMessages(_, _, _, _, messages, chats, users): - apiMessages = messages - apiChats = chats - apiUsers = users - case .messagesNotModified: - apiMessages = [] - apiChats = [] - apiUsers = [] - } - - var peers: [PeerId: Peer] = [:] - - for user in apiUsers { - if let user = TelegramUser.merge(transaction.getPeer(user.peerId) as? TelegramUser, rhs: user) { - peers[user.id] = user - } - } - - for chat in apiChats { - if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) { - peers[groupOrChannel.id] = groupOrChannel - } - } - - updatePeers(transaction: transaction, peers: Array(peers.values), update: { _, updated in - return updated - }) - - for message in apiMessages { - if let message = StoreMessage(apiMessage: message, namespace: messageId.namespace) { - let _ = transaction.addMessages([message], location: .Random) - } - } - } - } - } else { - return .complete() - } - } else { - return .complete() - } -} diff --git a/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift b/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift index 3117d853df..1a5c57a4aa 100644 --- a/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift +++ b/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift @@ -2490,7 +2490,7 @@ func replayFinalState(accountManager: AccountManager, postbox: Postbox, accountP } deletedMessageIds.append(contentsOf: ids.map { .global($0) }) case let .DeleteMessages(ids): - deleteMessages(transaction: transaction, mediaBox: mediaBox, ids: ids, manualAddMessageThreadStatsDifference: { id, add, remove in + _internal_deleteMessages(transaction: transaction, mediaBox: mediaBox, ids: ids, manualAddMessageThreadStatsDifference: { id, add, remove in addMessageThreadStatsDifference(threadMessageId: id, remove: remove, addedMessagePeer: nil, addedMessageId: nil, isOutgoing: false) }) deletedMessageIds.append(contentsOf: ids.map { .messageId($0) }) diff --git a/submodules/TelegramCore/Sources/AccountViewTracker.swift b/submodules/TelegramCore/Sources/State/AccountViewTracker.swift similarity index 100% rename from submodules/TelegramCore/Sources/AccountViewTracker.swift rename to submodules/TelegramCore/Sources/State/AccountViewTracker.swift diff --git a/submodules/TelegramCore/Sources/ApplyUpdateMessage.swift b/submodules/TelegramCore/Sources/State/ApplyUpdateMessage.swift similarity index 100% rename from submodules/TelegramCore/Sources/ApplyUpdateMessage.swift rename to submodules/TelegramCore/Sources/State/ApplyUpdateMessage.swift diff --git a/submodules/TelegramCore/Sources/CachedSentMediaReferences.swift b/submodules/TelegramCore/Sources/State/CachedSentMediaReferences.swift similarity index 100% rename from submodules/TelegramCore/Sources/CachedSentMediaReferences.swift rename to submodules/TelegramCore/Sources/State/CachedSentMediaReferences.swift diff --git a/submodules/TelegramCore/Sources/CallSessionManager.swift b/submodules/TelegramCore/Sources/State/CallSessionManager.swift similarity index 100% rename from submodules/TelegramCore/Sources/CallSessionManager.swift rename to submodules/TelegramCore/Sources/State/CallSessionManager.swift diff --git a/submodules/TelegramCore/Sources/CloudChatRemoveMessagesOperation.swift b/submodules/TelegramCore/Sources/State/CloudChatRemoveMessagesOperation.swift similarity index 100% rename from submodules/TelegramCore/Sources/CloudChatRemoveMessagesOperation.swift rename to submodules/TelegramCore/Sources/State/CloudChatRemoveMessagesOperation.swift diff --git a/submodules/TelegramCore/Sources/ContactSyncManager.swift b/submodules/TelegramCore/Sources/State/ContactSyncManager.swift similarity index 100% rename from submodules/TelegramCore/Sources/ContactSyncManager.swift rename to submodules/TelegramCore/Sources/State/ContactSyncManager.swift diff --git a/submodules/TelegramCore/Sources/Fetch.swift b/submodules/TelegramCore/Sources/State/Fetch.swift similarity index 100% rename from submodules/TelegramCore/Sources/Fetch.swift rename to submodules/TelegramCore/Sources/State/Fetch.swift diff --git a/submodules/TelegramCore/Sources/FetchChatList.swift b/submodules/TelegramCore/Sources/State/FetchChatList.swift similarity index 100% rename from submodules/TelegramCore/Sources/FetchChatList.swift rename to submodules/TelegramCore/Sources/State/FetchChatList.swift diff --git a/submodules/TelegramCore/Sources/FetchSecretFileResource.swift b/submodules/TelegramCore/Sources/State/FetchSecretFileResource.swift similarity index 100% rename from submodules/TelegramCore/Sources/FetchSecretFileResource.swift rename to submodules/TelegramCore/Sources/State/FetchSecretFileResource.swift diff --git a/submodules/TelegramCore/Sources/Holes.swift b/submodules/TelegramCore/Sources/State/Holes.swift similarity index 100% rename from submodules/TelegramCore/Sources/Holes.swift rename to submodules/TelegramCore/Sources/State/Holes.swift diff --git a/submodules/TelegramCore/Sources/InitializeAccountAfterLogin.swift b/submodules/TelegramCore/Sources/State/InitializeAccountAfterLogin.swift similarity index 100% rename from submodules/TelegramCore/Sources/InitializeAccountAfterLogin.swift rename to submodules/TelegramCore/Sources/State/InitializeAccountAfterLogin.swift diff --git a/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift b/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift index a610a0dd9f..6d739dd4a3 100644 --- a/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift +++ b/submodules/TelegramCore/Sources/State/ManagedAutoremoveMessageOperations.swift @@ -83,7 +83,7 @@ func managedAutoremoveMessageOperations(network: Network, postbox: Postbox, isRe if let message = transaction.getMessage(entry.messageId) { if message.id.peerId.namespace == Namespaces.Peer.SecretChat || isRemove { - deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [entry.messageId]) + _internal_deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [entry.messageId]) } else { transaction.updateMessage(message.id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? diff --git a/submodules/TelegramCore/Sources/State/ManagedCloudChatRemoveMessagesOperations.swift b/submodules/TelegramCore/Sources/State/ManagedCloudChatRemoveMessagesOperations.swift index ab4e02c849..eb40e138ec 100644 --- a/submodules/TelegramCore/Sources/State/ManagedCloudChatRemoveMessagesOperations.swift +++ b/submodules/TelegramCore/Sources/State/ManagedCloudChatRemoveMessagesOperations.swift @@ -96,7 +96,7 @@ func managedCloudChatRemoveMessagesOperations(postbox: Postbox, network: Network } } else if let operation = entry.contents as? CloudChatClearHistoryOperation { if let peer = transaction.getPeer(entry.peerId) { - return clearHistory(transaction: transaction, postbox: postbox, network: network, stateManager: stateManager, peer: peer, operation: operation) + return _internal_clearHistory(transaction: transaction, postbox: postbox, network: network, stateManager: stateManager, peer: peer, operation: operation) } else { return .complete() } @@ -311,7 +311,7 @@ private func removeChat(transaction: Transaction, postbox: Postbox, network: Net |> then(deleteUser) |> then(reportSignal) |> then(postbox.transaction { transaction -> Void in - clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peer.id, namespaces: .all) + _internal_clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peer.id, namespaces: .all) }) } else if peer.id.namespace == Namespaces.Peer.CloudUser { if let inputPeer = apiInputPeer(peer) { @@ -330,7 +330,7 @@ private func removeChat(transaction: Transaction, postbox: Postbox, network: Net return requestClearHistory(postbox: postbox, network: network, stateManager: stateManager, inputPeer: inputPeer, maxId: operation.topMessageId?.id ?? Int32.max - 1, justClear: false, type: operation.deleteGloballyIfPossible ? .forEveryone : .forLocalPeer) |> then(reportSignal) |> then(postbox.transaction { transaction -> Void in - clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peer.id, namespaces: .not(Namespaces.Message.allScheduled)) + _internal_clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peer.id, namespaces: .not(Namespaces.Message.allScheduled)) }) } else { return .complete() @@ -376,7 +376,7 @@ private func requestClearHistory(postbox: Postbox, network: Network, stateManage } } -private func clearHistory(transaction: Transaction, postbox: Postbox, network: Network, stateManager: AccountStateManager, peer: Peer, operation: CloudChatClearHistoryOperation) -> Signal { +private func _internal_clearHistory(transaction: Transaction, postbox: Postbox, network: Network, stateManager: AccountStateManager, peer: Peer, operation: CloudChatClearHistoryOperation) -> Signal { if peer.id.namespace == Namespaces.Peer.CloudGroup || peer.id.namespace == Namespaces.Peer.CloudUser { if let inputPeer = apiInputPeer(peer) { return requestClearHistory(postbox: postbox, network: network, stateManager: stateManager, inputPeer: inputPeer, maxId: operation.topMessageId.id, justClear: true, type: operation.type) diff --git a/submodules/TelegramCore/Sources/State/ManagedLocalizationUpdatesOperations.swift b/submodules/TelegramCore/Sources/State/ManagedLocalizationUpdatesOperations.swift index 4a95be5cf0..68157e0cfd 100644 --- a/submodules/TelegramCore/Sources/State/ManagedLocalizationUpdatesOperations.swift +++ b/submodules/TelegramCore/Sources/State/ManagedLocalizationUpdatesOperations.swift @@ -228,7 +228,7 @@ private func synchronizeLocalizationUpdates(accountManager: AccountManager, post case .reset: return accountManager.transaction { transaction -> Signal in let (primary, _) = getLocalization(transaction) - return downloadAndApplyLocalization(accountManager: accountManager, postbox: postbox, network: network, languageCode: primary.code) + return _internal_downloadAndApplyLocalization(accountManager: accountManager, postbox: postbox, network: network, languageCode: primary.code) |> mapError { _ -> Void in return Void() } diff --git a/submodules/TelegramCore/Sources/State/ManagedSecretChatOutgoingOperations.swift b/submodules/TelegramCore/Sources/State/ManagedSecretChatOutgoingOperations.swift index 618a7b35a8..4643230e25 100644 --- a/submodules/TelegramCore/Sources/State/ManagedSecretChatOutgoingOperations.swift +++ b/submodules/TelegramCore/Sources/State/ManagedSecretChatOutgoingOperations.swift @@ -1520,7 +1520,7 @@ private func sendMessage(auxiliaryMethods: AccountAuxiliaryMethods, postbox: Pos } } else { replaceOutgoingOperationWithEmptyMessage(transaction: transaction, peerId: messageId.peerId, tagLocalIndex: tagLocalIndex, globallyUniqueId: Int64.random(in: Int64.min ... Int64.max)) - deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [messageId]) + _internal_deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [messageId]) return .complete() } } else { diff --git a/submodules/TelegramCore/Sources/PendingMessageManager.swift b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift similarity index 100% rename from submodules/TelegramCore/Sources/PendingMessageManager.swift rename to submodules/TelegramCore/Sources/State/PendingMessageManager.swift diff --git a/submodules/TelegramCore/Sources/ProcessSecretChatIncomingDecryptedOperations.swift b/submodules/TelegramCore/Sources/State/ProcessSecretChatIncomingDecryptedOperations.swift similarity index 99% rename from submodules/TelegramCore/Sources/ProcessSecretChatIncomingDecryptedOperations.swift rename to submodules/TelegramCore/Sources/State/ProcessSecretChatIncomingDecryptedOperations.swift index dafc41c794..0a5eb061d6 100644 --- a/submodules/TelegramCore/Sources/ProcessSecretChatIncomingDecryptedOperations.swift +++ b/submodules/TelegramCore/Sources/State/ProcessSecretChatIncomingDecryptedOperations.swift @@ -276,10 +276,10 @@ func processSecretChatIncomingDecryptedOperations(encryptionProvider: Encryption } } } - deleteMessages(transaction: transaction, mediaBox: mediaBox, ids: filteredMessageIds) + _internal_deleteMessages(transaction: transaction, mediaBox: mediaBox, ids: filteredMessageIds) } case .clearHistory: - clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId, namespaces: .all) + _internal_clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId, namespaces: .all) case let .markMessagesContentAsConsumed(globallyUniqueIds): var messageIds: [MessageId] = [] for id in globallyUniqueIds { diff --git a/submodules/TelegramCore/Sources/ProcessSecretChatIncomingEncryptedOperations.swift b/submodules/TelegramCore/Sources/State/ProcessSecretChatIncomingEncryptedOperations.swift similarity index 100% rename from submodules/TelegramCore/Sources/ProcessSecretChatIncomingEncryptedOperations.swift rename to submodules/TelegramCore/Sources/State/ProcessSecretChatIncomingEncryptedOperations.swift diff --git a/submodules/TelegramCore/Sources/Serialization.swift b/submodules/TelegramCore/Sources/State/Serialization.swift similarity index 100% rename from submodules/TelegramCore/Sources/Serialization.swift rename to submodules/TelegramCore/Sources/State/Serialization.swift diff --git a/submodules/TelegramCore/Sources/State/StickerManagement.swift b/submodules/TelegramCore/Sources/State/StickerManagement.swift index ab3da0cac2..4aefb157f1 100644 --- a/submodules/TelegramCore/Sources/State/StickerManagement.swift +++ b/submodules/TelegramCore/Sources/State/StickerManagement.swift @@ -90,7 +90,7 @@ public func preloadedFeaturedStickerSet(network: Network, postbox: Postbox, id: return postbox.transaction { transaction -> Signal in if let pack = transaction.getOrderedItemListItem(collectionId: Namespaces.OrderedItemList.CloudFeaturedStickerPacks, itemId: FeaturedStickerPackItemId(id.id).rawValue)?.contents as? FeaturedStickerPackItem { if pack.topItems.count < 5 && pack.topItems.count < pack.info.count { - return requestStickerSet(postbox: postbox, network: network, reference: .id(id: pack.info.id.id, accessHash: pack.info.accessHash)) + return _internal_requestStickerSet(postbox: postbox, network: network, reference: .id(id: pack.info.id.id, accessHash: pack.info.accessHash)) |> map(Optional.init) |> `catch` { _ -> Signal in return .single(nil) diff --git a/submodules/TelegramCore/Sources/UnauthorizedAccountStateManager.swift b/submodules/TelegramCore/Sources/State/UnauthorizedAccountStateManager.swift similarity index 100% rename from submodules/TelegramCore/Sources/UnauthorizedAccountStateManager.swift rename to submodules/TelegramCore/Sources/State/UnauthorizedAccountStateManager.swift diff --git a/submodules/TelegramCore/Sources/StickerPackCreation.swift b/submodules/TelegramCore/Sources/StickerPackCreation.swift deleted file mode 100644 index fecc4ab449..0000000000 --- a/submodules/TelegramCore/Sources/StickerPackCreation.swift +++ /dev/null @@ -1 +0,0 @@ -import Foundation diff --git a/submodules/TelegramCore/Sources/LocalizationInfo.swift b/submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationInfo.swift similarity index 100% rename from submodules/TelegramCore/Sources/LocalizationInfo.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationInfo.swift diff --git a/submodules/TelegramCore/Sources/LocalizationListState.swift b/submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationListState.swift similarity index 96% rename from submodules/TelegramCore/Sources/LocalizationListState.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationListState.swift index 662173ff39..090e40a0cb 100644 --- a/submodules/TelegramCore/Sources/LocalizationListState.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationListState.swift @@ -51,7 +51,7 @@ func updateLocalizationListStateInteractively(transaction: Transaction, _ f: @es }) } -public func synchronizedLocalizationListState(postbox: Postbox, network: Network) -> Signal { +func _internal_synchronizedLocalizationListState(postbox: Postbox, network: Network) -> Signal { return network.request(Api.functions.langpack.getLanguages(langPack: "")) |> retryRequest |> mapToSignal { languages -> Signal in diff --git a/submodules/TelegramCore/Sources/LocalizationPreview.swift b/submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationPreview.swift similarity index 76% rename from submodules/TelegramCore/Sources/LocalizationPreview.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationPreview.swift index 919c74c013..b6aa82f737 100644 --- a/submodules/TelegramCore/Sources/LocalizationPreview.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationPreview.swift @@ -9,7 +9,7 @@ public enum RequestLocalizationPreviewError { case generic } -public func requestLocalizationPreview(network: Network, identifier: String) -> Signal { +func _internal_requestLocalizationPreview(network: Network, identifier: String) -> Signal { return network.request(Api.functions.langpack.getLanguage(langPack: "", langCode: identifier)) |> mapError { _ -> RequestLocalizationPreviewError in return .generic diff --git a/submodules/TelegramCore/Sources/Localizations.swift b/submodules/TelegramCore/Sources/TelegramEngine/Localization/Localizations.swift similarity index 85% rename from submodules/TelegramCore/Sources/Localizations.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Localization/Localizations.swift index 4f6e4fdef6..fa98c35845 100644 --- a/submodules/TelegramCore/Sources/Localizations.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Localization/Localizations.swift @@ -5,14 +5,14 @@ import SwiftSignalKit import SyncCore -public func currentlySuggestedLocalization(network: Network, extractKeys: [String]) -> Signal { +func _internal_currentlySuggestedLocalization(network: Network, extractKeys: [String]) -> Signal { return network.request(Api.functions.help.getConfig()) |> retryRequest |> mapToSignal { result -> Signal in switch result { case let .config(config): if let suggestedLangCode = config.suggestedLangCode { - return suggestedLocalizationInfo(network: network, languageCode: suggestedLangCode, extractKeys: extractKeys) |> map(Optional.init) + return _internal_suggestedLocalizationInfo(network: network, languageCode: suggestedLangCode, extractKeys: extractKeys) |> map(Optional.init) } else { return .single(nil) } @@ -20,7 +20,7 @@ public func currentlySuggestedLocalization(network: Network, extractKeys: [Strin } } -public func suggestedLocalizationInfo(network: Network, languageCode: String, extractKeys: [String]) -> Signal { +func _internal_suggestedLocalizationInfo(network: Network, languageCode: String, extractKeys: [String]) -> Signal { return combineLatest(network.request(Api.functions.langpack.getLanguages(langPack: "")), network.request(Api.functions.langpack.getStrings(langPack: "", langCode: languageCode, keys: extractKeys))) |> retryRequest |> map { languages, strings -> SuggestedLocalizationInfo in @@ -40,7 +40,7 @@ public func suggestedLocalizationInfo(network: Network, languageCode: String, ex } } -public func availableLocalizations(postbox: Postbox, network: Network, allowCached: Bool) -> Signal<[LocalizationInfo], NoError> { +func _internal_availableLocalizations(postbox: Postbox, network: Network, allowCached: Bool) -> Signal<[LocalizationInfo], NoError> { let cached: Signal<[LocalizationInfo], NoError> if allowCached { cached = postbox.transaction { transaction -> Signal<[LocalizationInfo], NoError> in @@ -69,7 +69,7 @@ public enum DownloadLocalizationError { case generic } -public func downloadLocalization(network: Network, languageCode: String) -> Signal { +func _internal_downloadLocalization(network: Network, languageCode: String) -> Signal { return network.request(Api.functions.langpack.getLangPack(langPack: "", langCode: languageCode)) |> mapError { _ -> DownloadLocalizationError in return .generic @@ -100,16 +100,16 @@ public enum DownloadAndApplyLocalizationError { case generic } -public func downloadAndApplyLocalization(accountManager: AccountManager, postbox: Postbox, network: Network, languageCode: String) -> Signal { - return requestLocalizationPreview(network: network, identifier: languageCode) +func _internal_downloadAndApplyLocalization(accountManager: AccountManager, postbox: Postbox, network: Network, languageCode: String) -> Signal { + return _internal_requestLocalizationPreview(network: network, identifier: languageCode) |> mapError { _ -> DownloadAndApplyLocalizationError in return .generic } |> mapToSignal { preview -> Signal in var primaryAndSecondaryLocalizations: [Signal] = [] - primaryAndSecondaryLocalizations.append(downloadLocalization(network: network, languageCode: preview.languageCode)) + primaryAndSecondaryLocalizations.append(_internal_downloadLocalization(network: network, languageCode: preview.languageCode)) if let secondaryCode = preview.baseLanguageCode { - primaryAndSecondaryLocalizations.append(downloadLocalization(network: network, languageCode: secondaryCode)) + primaryAndSecondaryLocalizations.append(_internal_downloadLocalization(network: network, languageCode: secondaryCode)) } return combineLatest(primaryAndSecondaryLocalizations) |> mapError { _ -> DownloadAndApplyLocalizationError in diff --git a/submodules/TelegramCore/Sources/SuggestedLocalizationEntry.swift b/submodules/TelegramCore/Sources/TelegramEngine/Localization/SuggestedLocalizationEntry.swift similarity index 83% rename from submodules/TelegramCore/Sources/SuggestedLocalizationEntry.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Localization/SuggestedLocalizationEntry.swift index 6ba5d1d739..f5e225ab4c 100644 --- a/submodules/TelegramCore/Sources/SuggestedLocalizationEntry.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Localization/SuggestedLocalizationEntry.swift @@ -4,7 +4,7 @@ import SwiftSignalKit import SyncCore -public func markSuggestedLocalizationAsSeenInteractively(postbox: Postbox, languageCode: String) -> Signal { +func _internal_markSuggestedLocalizationAsSeenInteractively(postbox: Postbox, languageCode: String) -> Signal { return postbox.transaction { transaction -> Void in transaction.updatePreferencesEntry(key: PreferencesKeys.suggestedLocalization, { current in if let current = current as? SuggestedLocalizationEntry { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift b/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift index 3f35e99178..699ffb7b3f 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift @@ -1,5 +1,6 @@ import SwiftSignalKit import Postbox +import SyncCore public extension TelegramEngine { final class Localization { @@ -12,6 +13,26 @@ public extension TelegramEngine { public func getCountriesList(accountManager: AccountManager, langCode: String?, forceUpdate: Bool = false) -> Signal<[Country], NoError> { return _internal_getCountriesList(accountManager: accountManager, network: self.account.network, langCode: langCode, forceUpdate: forceUpdate) } + + public func markSuggestedLocalizationAsSeenInteractively(languageCode: String) -> Signal { + return _internal_markSuggestedLocalizationAsSeenInteractively(postbox: self.account.postbox, languageCode: languageCode) + } + + public func synchronizedLocalizationListState() -> Signal { + return _internal_synchronizedLocalizationListState(postbox: self.account.postbox, network: self.account.network) + } + + public func suggestedLocalizationInfo(languageCode: String, extractKeys: [String]) -> Signal { + return _internal_suggestedLocalizationInfo(network: self.account.network, languageCode: languageCode, extractKeys: extractKeys) + } + + public func requestLocalizationPreview(identifier: String) -> Signal { + return _internal_requestLocalizationPreview(network: self.account.network, identifier: identifier) + } + + public func downloadAndApplyLocalization(accountManager: AccountManager, languageCode: String) -> Signal { + return _internal_downloadAndApplyLocalization(accountManager: accountManager, postbox: self.account.postbox, network: self.account.network, languageCode: languageCode) + } } } @@ -26,5 +47,17 @@ public extension TelegramEngineUnauthorized { public func getCountriesList(accountManager: AccountManager, langCode: String?, forceUpdate: Bool = false) -> Signal<[Country], NoError> { return _internal_getCountriesList(accountManager: accountManager, network: self.account.network, langCode: langCode, forceUpdate: forceUpdate) } + + public func markSuggestedLocalizationAsSeenInteractively(languageCode: String) -> Signal { + return _internal_markSuggestedLocalizationAsSeenInteractively(postbox: self.account.postbox, languageCode: languageCode) + } + + public func currentlySuggestedLocalization(extractKeys: [String]) -> Signal { + return _internal_currentlySuggestedLocalization(network: self.account.network, extractKeys: extractKeys) + } + + public func downloadAndApplyLocalization(accountManager: AccountManager, languageCode: String) -> Signal { + return _internal_downloadAndApplyLocalization(accountManager: accountManager, postbox: self.account.postbox, network: self.account.network, languageCode: languageCode) + } } } diff --git a/submodules/TelegramCore/Sources/ApplyMaxReadIndexInteractively.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ApplyMaxReadIndexInteractively.swift similarity index 96% rename from submodules/TelegramCore/Sources/ApplyMaxReadIndexInteractively.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/ApplyMaxReadIndexInteractively.swift index c00e1ca67f..ea804adba5 100644 --- a/submodules/TelegramCore/Sources/ApplyMaxReadIndexInteractively.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ApplyMaxReadIndexInteractively.swift @@ -5,13 +5,13 @@ import SwiftSignalKit import SyncCore -public func applyMaxReadIndexInteractively(postbox: Postbox, stateManager: AccountStateManager, index: MessageIndex) -> Signal { +func _internal_applyMaxReadIndexInteractively(postbox: Postbox, stateManager: AccountStateManager, index: MessageIndex) -> Signal { return postbox.transaction { transaction -> Void in - applyMaxReadIndexInteractively(transaction: transaction, stateManager: stateManager, index: index) + _internal_applyMaxReadIndexInteractively(transaction: transaction, stateManager: stateManager, index: index) } } -func applyMaxReadIndexInteractively(transaction: Transaction, stateManager: AccountStateManager, index: MessageIndex) { +func _internal_applyMaxReadIndexInteractively(transaction: Transaction, stateManager: AccountStateManager, index: MessageIndex) { let messageIds = transaction.applyInteractiveReadMaxIndex(index) if index.id.peerId.namespace == Namespaces.Peer.SecretChat { let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) diff --git a/submodules/TelegramCore/Sources/ClearCloudDrafts.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ClearCloudDrafts.swift similarity index 96% rename from submodules/TelegramCore/Sources/ClearCloudDrafts.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/ClearCloudDrafts.swift index 7a5038ce2e..4f1942760b 100644 --- a/submodules/TelegramCore/Sources/ClearCloudDrafts.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ClearCloudDrafts.swift @@ -5,7 +5,7 @@ import TelegramApi import SyncCore -public func clearCloudDraftsInteractively(postbox: Postbox, network: Network, accountPeerId: PeerId) -> Signal { +func _internal_clearCloudDraftsInteractively(postbox: Postbox, network: Network, accountPeerId: PeerId) -> Signal { return network.request(Api.functions.messages.getAllDrafts()) |> retryRequest |> mapToSignal { updates -> Signal in diff --git a/submodules/TelegramCore/Sources/DeleteMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/DeleteMessages.swift similarity index 89% rename from submodules/TelegramCore/Sources/DeleteMessages.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/DeleteMessages.swift index 787659c8e4..fc69b68f80 100644 --- a/submodules/TelegramCore/Sources/DeleteMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/DeleteMessages.swift @@ -23,7 +23,7 @@ func addMessageMediaResourceIdsToRemove(message: Message, resourceIds: inout [Wr } } -public func deleteMessages(transaction: Transaction, mediaBox: MediaBox, ids: [MessageId], deleteMedia: Bool = true, manualAddMessageThreadStatsDifference: ((MessageId, Int, Int) -> Void)? = nil) { +func _internal_deleteMessages(transaction: Transaction, mediaBox: MediaBox, ids: [MessageId], deleteMedia: Bool = true, manualAddMessageThreadStatsDifference: ((MessageId, Int, Int) -> Void)? = nil) { var resourceIds: [WrappedMediaResourceId] = [] if deleteMedia { for id in ids { @@ -57,7 +57,7 @@ public func deleteMessages(transaction: Transaction, mediaBox: MediaBox, ids: [M }) } -public func deleteAllMessagesWithAuthor(transaction: Transaction, mediaBox: MediaBox, peerId: PeerId, authorId: PeerId, namespace: MessageId.Namespace) { +func _internal_deleteAllMessagesWithAuthor(transaction: Transaction, mediaBox: MediaBox, peerId: PeerId, authorId: PeerId, namespace: MessageId.Namespace) { var resourceIds: [WrappedMediaResourceId] = [] transaction.removeAllMessagesWithAuthor(peerId, authorId: authorId, namespace: namespace, forEachMedia: { media in addMessageMediaResourceIdsToRemove(media: media, resourceIds: &resourceIds) @@ -67,7 +67,7 @@ public func deleteAllMessagesWithAuthor(transaction: Transaction, mediaBox: Medi } } -public func deleteAllMessagesWithForwardAuthor(transaction: Transaction, mediaBox: MediaBox, peerId: PeerId, forwardAuthorId: PeerId, namespace: MessageId.Namespace) { +func _internal_deleteAllMessagesWithForwardAuthor(transaction: Transaction, mediaBox: MediaBox, peerId: PeerId, forwardAuthorId: PeerId, namespace: MessageId.Namespace) { var resourceIds: [WrappedMediaResourceId] = [] transaction.removeAllMessagesWithForwardAuthor(peerId, forwardAuthorId: forwardAuthorId, namespace: namespace, forEachMedia: { media in addMessageMediaResourceIdsToRemove(media: media, resourceIds: &resourceIds) @@ -77,7 +77,7 @@ public func deleteAllMessagesWithForwardAuthor(transaction: Transaction, mediaBo } } -public func clearHistory(transaction: Transaction, mediaBox: MediaBox, peerId: PeerId, namespaces: MessageIdNamespaces) { +func _internal_clearHistory(transaction: Transaction, mediaBox: MediaBox, peerId: PeerId, namespaces: MessageIdNamespaces) { if peerId.namespace == Namespaces.Peer.SecretChat { var resourceIds: [WrappedMediaResourceId] = [] transaction.withAllMessages(peerId: peerId, { message in @@ -96,7 +96,7 @@ public enum ClearCallHistoryError { case generic } -public func clearCallHistory(account: Account, forEveryone: Bool) -> Signal { +func _internal_clearCallHistory(account: Account, forEveryone: Bool) -> Signal { return account.postbox.transaction { transaction -> Signal in var flags: Int32 = 0 if forEveryone { @@ -146,7 +146,7 @@ public enum SetChatMessageAutoremoveTimeoutError { case generic } -public func setChatMessageAutoremoveTimeoutInteractively(account: Account, peerId: PeerId, timeout: Int32?) -> Signal { +func _internal_setChatMessageAutoremoveTimeoutInteractively(account: Account, peerId: PeerId, timeout: Int32?) -> Signal { return account.postbox.transaction { transaction -> Api.InputPeer? in return transaction.getPeer(peerId).flatMap(apiInputPeer) } diff --git a/submodules/TelegramCore/Sources/DeleteMessagesInteractively.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/DeleteMessagesInteractively.swift similarity index 87% rename from submodules/TelegramCore/Sources/DeleteMessagesInteractively.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/DeleteMessagesInteractively.swift index 64e3051ae1..4dd24abec2 100644 --- a/submodules/TelegramCore/Sources/DeleteMessagesInteractively.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/DeleteMessagesInteractively.swift @@ -6,7 +6,7 @@ import MtProtoKit import SyncCore -public func deleteMessagesInteractively(account: Account, messageIds: [MessageId], type: InteractiveMessagesDeletionType, deleteAllInGroup: Bool = false) -> Signal { +func _internal_deleteMessagesInteractively(account: Account, messageIds: [MessageId], type: InteractiveMessagesDeletionType, deleteAllInGroup: Bool = false) -> Signal { return account.postbox.transaction { transaction -> Void in deleteMessagesInteractively(transaction: transaction, stateManager: account.stateManager, postbox: account.postbox, messageIds: messageIds, type: type, removeIfPossiblyDelivered: true) } @@ -88,7 +88,7 @@ func deleteMessagesInteractively(transaction: Transaction, stateManager: Account } } } - deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: messageIds) + _internal_deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: messageIds) stateManager?.notifyDeletedMessages(messageIds: messageIds) @@ -97,22 +97,22 @@ func deleteMessagesInteractively(transaction: Transaction, stateManager: Account } } -public func clearHistoryInteractively(postbox: Postbox, peerId: PeerId, type: InteractiveHistoryClearingType) -> Signal { +func _internal_clearHistoryInteractively(postbox: Postbox, peerId: PeerId, type: InteractiveHistoryClearingType) -> Signal { return postbox.transaction { transaction -> Void in if peerId.namespace == Namespaces.Peer.CloudUser || peerId.namespace == Namespaces.Peer.CloudGroup || peerId.namespace == Namespaces.Peer.CloudChannel { cloudChatAddClearHistoryOperation(transaction: transaction, peerId: peerId, explicitTopMessageId: nil, type: CloudChatClearHistoryType(type)) if type == .scheduledMessages { - clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId, namespaces: .just(Namespaces.Message.allScheduled)) + _internal_clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId, namespaces: .just(Namespaces.Message.allScheduled)) } else { var topIndex: MessageIndex? if let topMessageId = transaction.getTopPeerMessageId(peerId: peerId, namespace: Namespaces.Message.Cloud), let topMessage = transaction.getMessage(topMessageId) { topIndex = topMessage.index } - clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId, namespaces: .not(Namespaces.Message.allScheduled)) + _internal_clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId, namespaces: .not(Namespaces.Message.allScheduled)) if let cachedData = transaction.getPeerCachedData(peerId: peerId) as? CachedChannelData, let migrationReference = cachedData.migrationReference { cloudChatAddClearHistoryOperation(transaction: transaction, peerId: migrationReference.maxMessageId.peerId, explicitTopMessageId: MessageId(peerId: migrationReference.maxMessageId.peerId, namespace: migrationReference.maxMessageId.namespace, id: migrationReference.maxMessageId.id + 1), type: CloudChatClearHistoryType(type)) - clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: migrationReference.maxMessageId.peerId, namespaces: .all) + _internal_clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: migrationReference.maxMessageId.peerId, namespaces: .all) } if let topIndex = topIndex { if peerId.namespace == Namespaces.Peer.CloudUser { @@ -123,7 +123,7 @@ public func clearHistoryInteractively(postbox: Postbox, peerId: PeerId, type: In } } } else if peerId.namespace == Namespaces.Peer.SecretChat { - clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId, namespaces: .all) + _internal_clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId, namespaces: .all) if let state = transaction.getPeerChatState(peerId) as? SecretChatState { var layer: SecretChatLayer? @@ -147,7 +147,7 @@ public func clearHistoryInteractively(postbox: Postbox, peerId: PeerId, type: In } } -public func clearAuthorHistory(account: Account, peerId: PeerId, memberId: PeerId) -> Signal { +func _internal_clearAuthorHistory(account: Account, peerId: PeerId, memberId: PeerId) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId), let memberPeer = transaction.getPeer(memberId), let inputChannel = apiInputChannel(peer), let inputUser = apiInputUser(memberPeer) { @@ -178,7 +178,7 @@ public func clearAuthorHistory(account: Account, peerId: PeerId, memberId: PeerI |> `catch` { success -> Signal in if success { return account.postbox.transaction { transaction -> Void in - deleteAllMessagesWithAuthor(transaction: transaction, mediaBox: account.postbox.mediaBox, peerId: peerId, authorId: memberId, namespace: Namespaces.Message.Cloud) + _internal_deleteAllMessagesWithAuthor(transaction: transaction, mediaBox: account.postbox.mediaBox, peerId: peerId, authorId: memberId, namespace: Namespaces.Message.Cloud) } } else { return .complete() diff --git a/submodules/TelegramCore/Sources/RequestMessageActionCallback.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestMessageActionCallback.swift similarity index 94% rename from submodules/TelegramCore/Sources/RequestMessageActionCallback.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestMessageActionCallback.swift index edfeaa6777..614c827368 100644 --- a/submodules/TelegramCore/Sources/RequestMessageActionCallback.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestMessageActionCallback.swift @@ -24,7 +24,7 @@ public enum MessageActionCallbackError { case userBlocked } -public func requestMessageActionCallbackPasswordCheck(account: Account, messageId: MessageId, isGame: Bool, data: MemoryBuffer?) -> Signal { +func _internal_requestMessageActionCallbackPasswordCheck(account: Account, messageId: MessageId, isGame: Bool, data: MemoryBuffer?) -> Signal { return account.postbox.loadedPeerWithId(messageId.peerId) |> castError(MessageActionCallbackError.self) |> take(1) @@ -72,7 +72,7 @@ public func requestMessageActionCallbackPasswordCheck(account: Account, messageI } } -public func requestMessageActionCallback(account: Account, messageId: MessageId, isGame :Bool, password: String?, data: MemoryBuffer?) -> Signal { +func _internal_requestMessageActionCallback(account: Account, messageId: MessageId, isGame :Bool, password: String?, data: MemoryBuffer?) -> Signal { return account.postbox.loadedPeerWithId(messageId.peerId) |> castError(MessageActionCallbackError.self) |> take(1) @@ -179,7 +179,7 @@ public enum MessageActionUrlSubject { case url(String) } -public func requestMessageActionUrlAuth(account: Account, subject: MessageActionUrlSubject) -> Signal { +func _internal_requestMessageActionUrlAuth(account: Account, subject: MessageActionUrlSubject) -> Signal { let request: Signal var flags: Int32 = 0 switch subject { @@ -221,7 +221,7 @@ public func requestMessageActionUrlAuth(account: Account, subject: MessageAction } } -public func acceptMessageActionUrlAuth(account: Account, subject: MessageActionUrlSubject, allowWriteAccess: Bool) -> Signal { +func _internal_acceptMessageActionUrlAuth(account: Account, subject: MessageActionUrlSubject, allowWriteAccess: Bool) -> Signal { var flags: Int32 = 0 if allowWriteAccess { flags |= Int32(1 << 0) diff --git a/submodules/TelegramCore/Sources/ScheduledMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ScheduledMessages.swift similarity index 98% rename from submodules/TelegramCore/Sources/ScheduledMessages.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/ScheduledMessages.swift index f8500bb722..65d6906e20 100644 --- a/submodules/TelegramCore/Sources/ScheduledMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ScheduledMessages.swift @@ -5,7 +5,7 @@ import TelegramApi import SyncCore -public func sendScheduledMessageNowInteractively(postbox: Postbox, messageId: MessageId) -> Signal { +func _internal_sendScheduledMessageNowInteractively(postbox: Postbox, messageId: MessageId) -> Signal { return postbox.transaction { transaction -> Void in transaction.setPendingMessageAction(type: .sendScheduledMessageImmediately, id: messageId, action: SendScheduledMessageImmediatelyAction()) } diff --git a/submodules/TelegramCore/Sources/SearchMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/SearchMessages.swift similarity index 98% rename from submodules/TelegramCore/Sources/SearchMessages.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Messages/SearchMessages.swift index 21c73f7386..0d70dc6986 100644 --- a/submodules/TelegramCore/Sources/SearchMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/SearchMessages.swift @@ -184,7 +184,7 @@ private func mergedResult(_ state: SearchMessagesState) -> SearchMessagesResult return SearchMessagesResult(messages: messages, readStates: readStates, totalCount: state.main.totalCount + (state.additional?.totalCount ?? 0), completed: state.main.completed && (state.additional?.completed ?? true)) } -public func searchMessages(account: Account, location: SearchMessagesLocation, query: String, state: SearchMessagesState?, limit: Int32 = 100) -> Signal<(SearchMessagesResult, SearchMessagesState), NoError> { +func _internal_searchMessages(account: Account, location: SearchMessagesLocation, query: String, state: SearchMessagesState?, limit: Int32 = 100) -> Signal<(SearchMessagesResult, SearchMessagesState), NoError> { let remoteSearchResult: Signal<(Api.messages.Messages?, Api.messages.Messages?), NoError> switch location { case let .peer(peerId, fromId, tags, topMsgId, minDate, maxDate): @@ -379,7 +379,7 @@ public func searchMessages(account: Account, location: SearchMessagesLocation, q } } -public func downloadMessage(postbox: Postbox, network: Network, messageId: MessageId) -> Signal { +func _internal_downloadMessage(postbox: Postbox, network: Network, messageId: MessageId) -> Signal { return postbox.transaction { transaction -> Message? in return transaction.getMessage(messageId) } |> mapToSignal { message in @@ -562,7 +562,7 @@ func fetchRemoteMessage(postbox: Postbox, source: FetchMessageHistoryHoleSource, } } -public func searchMessageIdByTimestamp(account: Account, peerId: PeerId, threadId: Int64?, timestamp: Int32) -> Signal { +func _internal_searchMessageIdByTimestamp(account: Account, peerId: PeerId, threadId: Int64?, timestamp: Int32) -> Signal { return account.postbox.transaction { transaction -> Signal in if peerId.namespace == Namespaces.Peer.SecretChat { return .single(transaction.findClosestMessageIdByTimestamp(peerId: peerId, timestamp: timestamp)) @@ -672,7 +672,7 @@ public enum UpdatedRemotePeerError { case generic } -public func updatedRemotePeer(postbox: Postbox, network: Network, peer: PeerReference) -> Signal { +func _internal_updatedRemotePeer(postbox: Postbox, network: Network, peer: PeerReference) -> Signal { if let inputUser = peer.inputUser { return network.request(Api.functions.users.getUsers(id: [inputUser])) |> mapError { _ -> UpdatedRemotePeerError in diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift new file mode 100644 index 0000000000..df12d4c2db --- /dev/null +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -0,0 +1,89 @@ +import SwiftSignalKit +import Postbox +import SyncCore + +public extension TelegramEngine { + final class Messages { + private let account: Account + + init(account: Account) { + self.account = account + } + + public func clearCloudDraftsInteractively() -> Signal { + return _internal_clearCloudDraftsInteractively(postbox: self.account.postbox, network: self.account.network, accountPeerId: self.account.peerId) + } + + public func applyMaxReadIndexInteractively(index: MessageIndex) -> Signal { + return _internal_applyMaxReadIndexInteractively(postbox: self.account.postbox, stateManager: self.account.stateManager, index: index) + } + + public func sendScheduledMessageNowInteractively(messageId: MessageId) -> Signal { + return _internal_sendScheduledMessageNowInteractively(postbox: self.account.postbox, messageId: messageId) + } + + public func requestMessageActionCallbackPasswordCheck(messageId: MessageId, isGame: Bool, data: MemoryBuffer?) -> Signal { + return _internal_requestMessageActionCallbackPasswordCheck(account: self.account, messageId: messageId, isGame: isGame, data: data) + } + + public func requestMessageActionCallback(messageId: MessageId, isGame: Bool, password: String?, data: MemoryBuffer?) -> Signal { + return _internal_requestMessageActionCallback(account: self.account, messageId: messageId, isGame: isGame, password: password, data: data) + } + + public func requestMessageActionUrlAuth(subject: MessageActionUrlSubject) -> Signal { + _internal_requestMessageActionUrlAuth(account: self.account, subject: subject) + } + + public func acceptMessageActionUrlAuth(subject: MessageActionUrlSubject, allowWriteAccess: Bool) -> Signal { + return _internal_acceptMessageActionUrlAuth(account: self.account, subject: subject, allowWriteAccess: allowWriteAccess) + } + + public func searchMessages(location: SearchMessagesLocation, query: String, state: SearchMessagesState?, limit: Int32 = 100) -> Signal<(SearchMessagesResult, SearchMessagesState), NoError> { + return _internal_searchMessages(account: self.account, location: location, query: query, state: state, limit: limit) + } + + public func downloadMessage(messageId: MessageId) -> Signal { + return _internal_downloadMessage(postbox: self.account.postbox, network: self.account.network, messageId: messageId) + } + + public func searchMessageIdByTimestamp(peerId: PeerId, threadId: Int64?, timestamp: Int32) -> Signal { + return _internal_searchMessageIdByTimestamp(account: self.account, peerId: peerId, threadId: threadId, timestamp: timestamp) + } + + public func deleteMessages(transaction: Transaction, ids: [MessageId], deleteMedia: Bool = true, manualAddMessageThreadStatsDifference: ((MessageId, Int, Int) -> Void)? = nil) { + return _internal_deleteMessages(transaction: transaction, mediaBox: self.account.postbox.mediaBox, ids: ids, deleteMedia: deleteMedia, manualAddMessageThreadStatsDifference: manualAddMessageThreadStatsDifference) + } + + public func deleteAllMessagesWithAuthor(transaction: Transaction, peerId: PeerId, authorId: PeerId, namespace: MessageId.Namespace) { + return _internal_deleteAllMessagesWithAuthor(transaction: transaction, mediaBox: self.account.postbox.mediaBox, peerId: peerId, authorId: authorId, namespace: namespace) + } + + public func deleteAllMessagesWithForwardAuthor(transaction: Transaction, peerId: PeerId, forwardAuthorId: PeerId, namespace: MessageId.Namespace) { + return _internal_deleteAllMessagesWithForwardAuthor(transaction: transaction, mediaBox: self.account.postbox.mediaBox, peerId: peerId, forwardAuthorId: forwardAuthorId, namespace: namespace) + } + + public func clearCallHistory(forEveryone: Bool) -> Signal { + return _internal_clearCallHistory(account: self.account, forEveryone: forEveryone) + } + + public func deleteMessagesInteractively(messageIds: [MessageId], type: InteractiveMessagesDeletionType, deleteAllInGroup: Bool = false) -> Signal { + return _internal_deleteMessagesInteractively(account: self.account, messageIds: messageIds, type: type, deleteAllInGroup: deleteAllInGroup) + } + + public func clearHistoryInteractively(peerId: PeerId, type: InteractiveHistoryClearingType) -> Signal { + return _internal_clearHistoryInteractively(postbox: self.account.postbox, peerId: peerId, type: type) + } + + public func clearAuthorHistory(peerId: PeerId, memberId: PeerId) -> Signal { + return _internal_clearAuthorHistory(account: self.account, peerId: peerId, memberId: memberId) + } + + public func requestEditMessage(messageId: MessageId, text: String, media: RequestEditMessageMedia, entities: TextEntitiesMessageAttribute? = nil, disableUrlPreview: Bool = false, scheduleTime: Int32? = nil) -> Signal { + return _internal_requestEditMessage(account: self.account, messageId: messageId, text: text, media: media, entities: entities, disableUrlPreview: disableUrlPreview, scheduleTime: scheduleTime) + } + + public func requestEditLiveLocation(messageId: MessageId, stop: Bool, coordinate: (latitude: Double, longitude: Double, accuracyRadius: Int32?)?, heading: Int32?, proximityNotificationRadius: Int32?) -> Signal { + return _internal_requestEditLiveLocation(postbox: self.account.postbox, network: self.account.network, stateManager: self.account.stateManager, messageId: messageId, stop: stop, coordinate: coordinate, heading: heading, proximityNotificationRadius: proximityNotificationRadius) + } + } +} diff --git a/submodules/TelegramCore/Sources/BotPaymentForm.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift similarity index 96% rename from submodules/TelegramCore/Sources/BotPaymentForm.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift index df130abd8f..b5a7c60e04 100644 --- a/submodules/TelegramCore/Sources/BotPaymentForm.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift @@ -174,7 +174,7 @@ extension BotPaymentRequestedInfo { } } -public func fetchBotPaymentForm(postbox: Postbox, network: Network, messageId: MessageId, themeParams: [String: Any]?) -> Signal { +func _internal_fetchBotPaymentForm(postbox: Postbox, network: Network, messageId: MessageId, themeParams: [String: Any]?) -> Signal { return postbox.transaction { transaction -> Api.InputPeer? in return transaction.getPeer(messageId.peerId).flatMap(apiInputPeer) } @@ -269,7 +269,7 @@ extension BotPaymentShippingOption { } } -public func validateBotPaymentForm(account: Account, saveInfo: Bool, messageId: MessageId, formInfo: BotPaymentRequestedInfo) -> Signal { +func _internal_validateBotPaymentForm(account: Account, saveInfo: Bool, messageId: MessageId, formInfo: BotPaymentRequestedInfo) -> Signal { return account.postbox.transaction { transaction -> Api.InputPeer? in return transaction.getPeer(messageId.peerId).flatMap(apiInputPeer) } @@ -347,7 +347,7 @@ public enum SendBotPaymentResult { case externalVerificationRequired(url: String) } -public func sendBotPaymentForm(account: Account, messageId: MessageId, formId: Int64, validatedInfoId: String?, shippingOptionId: String?, tipAmount: Int64?, credentials: BotPaymentCredentials) -> Signal { +func _internal_sendBotPaymentForm(account: Account, messageId: MessageId, formId: Int64, validatedInfoId: String?, shippingOptionId: String?, tipAmount: Int64?, credentials: BotPaymentCredentials) -> Signal { return account.postbox.transaction { transaction -> Api.InputPeer? in return transaction.getPeer(messageId.peerId).flatMap(apiInputPeer) } @@ -461,7 +461,7 @@ public enum RequestBotPaymentReceiptError { case generic } -public func requestBotPaymentReceipt(account: Account, messageId: MessageId) -> Signal { +func _internal_requestBotPaymentReceipt(account: Account, messageId: MessageId) -> Signal { return account.postbox.transaction { transaction -> Api.InputPeer? in return transaction.getPeer(messageId.peerId).flatMap(apiInputPeer) } @@ -545,7 +545,7 @@ public struct BotPaymentInfo: OptionSet { public static let shippingInfo = BotPaymentInfo(rawValue: 1 << 1) } -public func clearBotPaymentInfo(network: Network, info: BotPaymentInfo) -> Signal { +func _internal_clearBotPaymentInfo(network: Network, info: BotPaymentInfo) -> Signal { var flags: Int32 = 0 if info.contains(.paymentInfo) { flags |= (1 << 0) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift index a64a33be17..7bde71b986 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/TelegramEnginePayments.swift @@ -1,4 +1,5 @@ import SwiftSignalKit +import Postbox public extension TelegramEngine { final class Payments { @@ -11,5 +12,25 @@ public extension TelegramEngine { public func getBankCardInfo(cardNumber: String) -> Signal { return _internal_getBankCardInfo(account: self.account, cardNumber: cardNumber) } + + public func fetchBotPaymentForm(messageId: MessageId, themeParams: [String: Any]?) -> Signal { + return _internal_fetchBotPaymentForm(postbox: self.account.postbox, network: self.account.network, messageId: messageId, themeParams: themeParams) + } + + public func validateBotPaymentForm(saveInfo: Bool, messageId: MessageId, formInfo: BotPaymentRequestedInfo) -> Signal { + return _internal_validateBotPaymentForm(account: self.account, saveInfo: saveInfo, messageId: messageId, formInfo: formInfo) + } + + public func sendBotPaymentForm(messageId: MessageId, formId: Int64, validatedInfoId: String?, shippingOptionId: String?, tipAmount: Int64?, credentials: BotPaymentCredentials) -> Signal { + return _internal_sendBotPaymentForm(account: self.account, messageId: messageId, formId: formId, validatedInfoId: validatedInfoId, shippingOptionId: shippingOptionId, tipAmount: tipAmount, credentials: credentials) + } + + public func requestBotPaymentReceipt(messageId: MessageId) -> Signal { + return _internal_requestBotPaymentReceipt(account: self.account, messageId: messageId) + } + + public func clearBotPaymentInfo(info: BotPaymentInfo) -> Signal { + return _internal_clearBotPaymentInfo(network: self.account.network, info: info) + } } } diff --git a/submodules/TelegramCore/Sources/ChatOnlineMembers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChatOnlineMembers.swift similarity index 86% rename from submodules/TelegramCore/Sources/ChatOnlineMembers.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/ChatOnlineMembers.swift index 6be97c6046..aeb9e8593e 100644 --- a/submodules/TelegramCore/Sources/ChatOnlineMembers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChatOnlineMembers.swift @@ -3,7 +3,7 @@ import SwiftSignalKit import Postbox import TelegramApi -public func chatOnlineMembers(postbox: Postbox, network: Network, peerId: PeerId) -> Signal { +func _internal_chatOnlineMembers(postbox: Postbox, network: Network, peerId: PeerId) -> Signal { return postbox.transaction { transaction -> Api.InputPeer? in return transaction.getPeer(peerId).flatMap(apiInputPeer) } diff --git a/submodules/TelegramCore/Sources/ConvertGroupToSupergroup.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ConvertGroupToSupergroup.swift similarity index 95% rename from submodules/TelegramCore/Sources/ConvertGroupToSupergroup.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/ConvertGroupToSupergroup.swift index cce0ed0147..2edaf4434c 100644 --- a/submodules/TelegramCore/Sources/ConvertGroupToSupergroup.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ConvertGroupToSupergroup.swift @@ -9,7 +9,7 @@ public enum ConvertGroupToSupergroupError { case tooManyChannels } -public func convertGroupToSupergroup(account: Account, peerId: PeerId) -> Signal { +func _internal_convertGroupToSupergroup(account: Account, peerId: PeerId) -> Signal { return account.network.request(Api.functions.messages.migrateChat(chatId: peerId.id._internalGetInt32Value())) |> mapError { error -> ConvertGroupToSupergroupError in if error.errorDescription == "CHANNELS_TOO_MUCH" { diff --git a/submodules/TelegramCore/Sources/CreateGroup.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/CreateGroup.swift similarity index 93% rename from submodules/TelegramCore/Sources/CreateGroup.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/CreateGroup.swift index ec68df3240..4245f6cb52 100644 --- a/submodules/TelegramCore/Sources/CreateGroup.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/CreateGroup.swift @@ -13,7 +13,7 @@ public enum CreateGroupError { case serverProvided(String) } -public func createGroup(account: Account, title: String, peerIds: [PeerId]) -> Signal { +func _internal_createGroup(account: Account, title: String, peerIds: [PeerId]) -> Signal { return account.postbox.transaction { transaction -> Signal in var inputUsers: [Api.InputUser] = [] for peerId in peerIds { diff --git a/submodules/TelegramCore/Sources/CreateSecretChat.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/CreateSecretChat.swift similarity index 96% rename from submodules/TelegramCore/Sources/CreateSecretChat.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Peers/CreateSecretChat.swift index 9ce1c2b48b..7d57209fb7 100644 --- a/submodules/TelegramCore/Sources/CreateSecretChat.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/CreateSecretChat.swift @@ -9,7 +9,7 @@ public enum CreateSecretChatError { case limitExceeded } -public func createSecretChat(account: Account, peerId: PeerId) -> Signal { +func _internal_createSecretChat(account: Account, peerId: PeerId) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId), let inputUser = apiInputUser(peer) { return validatedEncryptionConfig(postbox: account.postbox, network: account.network) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift index 2a65d8f46e..4ce9e85463 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift @@ -1,5 +1,6 @@ import SwiftSignalKit import Postbox +import SyncCore public enum AddressNameValidationStatus: Equatable { case checking @@ -69,5 +70,29 @@ public extension TelegramEngine { public func searchPeers(query: String) -> Signal<([FoundPeer], [FoundPeer]), NoError> { return _internal_searchPeers(account: self.account, query: query) } + + public func updatedRemotePeer(peer: PeerReference) -> Signal { + return _internal_updatedRemotePeer(postbox: self.account.postbox, network: self.account.network, peer: peer) + } + + public func chatOnlineMembers(peerId: PeerId) -> Signal { + return _internal_chatOnlineMembers(postbox: self.account.postbox, network: self.account.network, peerId: peerId) + } + + public func convertGroupToSupergroup(peerId: PeerId) -> Signal { + return _internal_convertGroupToSupergroup(account: self.account, peerId: peerId) + } + + public func createGroup(title: String, peerIds: [PeerId]) -> Signal { + return _internal_createGroup(account: self.account, title: title, peerIds: peerIds) + } + + public func createSecretChat(peerId: PeerId) -> Signal { + return _internal_createSecretChat(account: self.account, peerId: peerId) + } + + public func setChatMessageAutoremoveTimeoutInteractively(peerId: PeerId, timeout: Int32?) -> Signal { + return _internal_setChatMessageAutoremoveTimeoutInteractively(account: self.account, peerId: peerId, timeout: timeout) + } } } diff --git a/submodules/TelegramCore/Sources/StickerSetInstallation.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerSetInstallation.swift similarity index 95% rename from submodules/TelegramCore/Sources/StickerSetInstallation.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerSetInstallation.swift index 0abcf37729..18318676ee 100644 --- a/submodules/TelegramCore/Sources/StickerSetInstallation.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerSetInstallation.swift @@ -24,7 +24,7 @@ public enum RequestStickerSetResult { } } -public func requestStickerSet(postbox: Postbox, network: Network, reference: StickerPackReference) -> Signal { +func _internal_requestStickerSet(postbox: Postbox, network: Network, reference: StickerPackReference) -> Signal { let collectionId: ItemCollectionId? let input: Api.InputStickerSet @@ -133,7 +133,7 @@ public final class CoveredStickerSet : Equatable { } } -public func installStickerSetInteractively(account: Account, info: StickerPackCollectionInfo, items: [ItemCollectionItem]) -> Signal { +func _internal_installStickerSetInteractively(account: Account, info: StickerPackCollectionInfo, items: [ItemCollectionItem]) -> Signal { return account.network.request(Api.functions.messages.installStickerSet(stickerset: .inputStickerSetID(id: info.id.id, accessHash: info.accessHash), archived: .boolFalse)) |> mapError { _ -> InstallStickerSetError in return .generic } |> mapToSignal { result -> Signal in @@ -198,7 +198,7 @@ public func installStickerSetInteractively(account: Account, info: StickerPackCo } -public func uninstallStickerSetInteractively(account: Account, info: StickerPackCollectionInfo) -> Signal { +func _internal_uninstallStickerSetInteractively(account: Account, info: StickerPackCollectionInfo) -> Signal { return account.network.request(Api.functions.messages.uninstallStickerSet(stickerset: .inputStickerSetID(id: info.id.id, accessHash: info.accessHash))) |> `catch` { _ -> Signal in return .single(.boolFalse) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift b/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift index 2389f19737..9fd8d6412e 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift @@ -43,6 +43,10 @@ public final class TelegramEngine { public lazy var localization: Localization = { return Localization(account: self.account) }() + + public lazy var messages: Messages = { + return Messages(account: self.account) + }() } public final class TelegramEngineUnauthorized { diff --git a/submodules/TelegramCore/Sources/UpdateCachedPeerData.swift b/submodules/TelegramCore/Sources/UpdateCachedPeerData.swift index 7e0c426020..56fb081c41 100644 --- a/submodules/TelegramCore/Sources/UpdateCachedPeerData.swift +++ b/submodules/TelegramCore/Sources/UpdateCachedPeerData.swift @@ -133,7 +133,7 @@ public func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId guard let view = views.views[.basicPeer(rawPeerId)] as? BasicPeerView else { return .complete() } - guard let peer = view.peer else { + guard let _ = view.peer else { return .complete() } return .single(true) diff --git a/submodules/TelegramCore/Sources/CanSendMessagesToPeer.swift b/submodules/TelegramCore/Sources/Utils/CanSendMessagesToPeer.swift similarity index 100% rename from submodules/TelegramCore/Sources/CanSendMessagesToPeer.swift rename to submodules/TelegramCore/Sources/Utils/CanSendMessagesToPeer.swift diff --git a/submodules/TelegramCore/Sources/DecryptedResourceData.swift b/submodules/TelegramCore/Sources/Utils/DecryptedResourceData.swift similarity index 100% rename from submodules/TelegramCore/Sources/DecryptedResourceData.swift rename to submodules/TelegramCore/Sources/Utils/DecryptedResourceData.swift diff --git a/submodules/TelegramCore/Sources/ImageRepresentationsUtils.swift b/submodules/TelegramCore/Sources/Utils/ImageRepresentationsUtils.swift similarity index 100% rename from submodules/TelegramCore/Sources/ImageRepresentationsUtils.swift rename to submodules/TelegramCore/Sources/Utils/ImageRepresentationsUtils.swift diff --git a/submodules/TelegramCore/Sources/MD5.swift b/submodules/TelegramCore/Sources/Utils/MD5.swift similarity index 100% rename from submodules/TelegramCore/Sources/MD5.swift rename to submodules/TelegramCore/Sources/Utils/MD5.swift diff --git a/submodules/TelegramCore/Sources/PeerUtils.swift b/submodules/TelegramCore/Sources/Utils/PeerUtils.swift similarity index 100% rename from submodules/TelegramCore/Sources/PeerUtils.swift rename to submodules/TelegramCore/Sources/Utils/PeerUtils.swift diff --git a/submodules/TelegramCore/Sources/StringFormat.swift b/submodules/TelegramCore/Sources/Utils/StringFormat.swift similarity index 100% rename from submodules/TelegramCore/Sources/StringFormat.swift rename to submodules/TelegramCore/Sources/Utils/StringFormat.swift diff --git a/submodules/TelegramUI/Sources/AccountContext.swift b/submodules/TelegramUI/Sources/AccountContext.swift index 95fe8149b6..5e5e1ab5c3 100644 --- a/submodules/TelegramUI/Sources/AccountContext.swift +++ b/submodules/TelegramUI/Sources/AccountContext.swift @@ -166,7 +166,7 @@ public final class AccountContextImpl: AccountContext { self.downloadedMediaStoreManager = DownloadedMediaStoreManagerImpl(postbox: account.postbox, accountManager: sharedContext.accountManager) if let locationManager = self.sharedContextImpl.locationManager { - self.liveLocationManager = LiveLocationManagerImpl(postbox: account.postbox, network: account.network, accountPeerId: account.peerId, viewTracker: account.viewTracker, stateManager: account.stateManager, locationManager: locationManager, inForeground: sharedContext.applicationBindings.applicationInForeground) + self.liveLocationManager = LiveLocationManagerImpl(account: account, locationManager: locationManager, inForeground: sharedContext.applicationBindings.applicationInForeground) } else { self.liveLocationManager = nil } @@ -295,7 +295,7 @@ public final class AccountContextImpl: AccountContext { public func applyMaxReadIndex(for location: ChatLocation, contextHolder: Atomic, messageIndex: MessageIndex) { switch location { case .peer: - let _ = applyMaxReadIndexInteractively(postbox: self.account.postbox, stateManager: self.account.stateManager, index: messageIndex).start() + let _ = self.engine.messages.applyMaxReadIndexInteractively(index: messageIndex).start() case let .replyThread(data): let context = chatLocationContext(holder: contextHolder, account: self.account, data: data) context.applyMaxReadIndex(messageIndex: messageIndex) diff --git a/submodules/TelegramUI/Sources/AppDelegate.swift b/submodules/TelegramUI/Sources/AppDelegate.swift index fa1f30b5f8..9b35f62a39 100644 --- a/submodules/TelegramUI/Sources/AppDelegate.swift +++ b/submodules/TelegramUI/Sources/AppDelegate.swift @@ -1972,7 +1972,7 @@ final class SharedApplicationContext { |> deliverOnMainQueue |> mapToSignal { account -> Signal in if let messageId = messageIdFromNotification(peerId: peerId, notification: response.notification) { - let _ = applyMaxReadIndexInteractively(postbox: account.postbox, stateManager: account.stateManager, index: MessageIndex(id: messageId, timestamp: 0)).start() + let _ = TelegramEngine(account: account).messages.applyMaxReadIndexInteractively(index: MessageIndex(id: messageId, timestamp: 0)).start() } return enqueueMessages(account: account, peerId: peerId, messages: [EnqueueMessage.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]) |> map { messageIds -> MessageId? in diff --git a/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift b/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift index 4854c1d83d..4d6e9c69b4 100644 --- a/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift +++ b/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift @@ -110,7 +110,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail if let currentController = currentController { controller = currentController } else { - controller = AuthorizationSequenceSplashController(accountManager: self.sharedContext.accountManager, postbox: self.account.postbox, network: self.account.network, theme: self.presentationData.theme) + controller = AuthorizationSequenceSplashController(accountManager: self.sharedContext.accountManager, account: self.account, theme: self.presentationData.theme) controller.nextPressed = { [weak self] strings in if let strongSelf = self { if let strings = strings { diff --git a/submodules/TelegramUI/Sources/AuthorizationSequenceSplashController.swift b/submodules/TelegramUI/Sources/AuthorizationSequenceSplashController.swift index 184601231f..26cc9a83cd 100644 --- a/submodules/TelegramUI/Sources/AuthorizationSequenceSplashController.swift +++ b/submodules/TelegramUI/Sources/AuthorizationSequenceSplashController.swift @@ -17,8 +17,7 @@ final class AuthorizationSequenceSplashController: ViewController { } private let accountManager: AccountManager - private let postbox: Postbox - private let network: Network + private let account: UnauthorizedAccount private let theme: PresentationTheme private let controller: RMIntroViewController @@ -30,14 +29,13 @@ final class AuthorizationSequenceSplashController: ViewController { private let suggestedLocalization = Promise() private let activateLocalizationDisposable = MetaDisposable() - init(accountManager: AccountManager, postbox: Postbox, network: Network, theme: PresentationTheme) { + init(accountManager: AccountManager, account: UnauthorizedAccount, theme: PresentationTheme) { self.accountManager = accountManager - self.postbox = postbox - self.network = network + self.account = account self.theme = theme self.suggestedLocalization.set(.single(nil) - |> then(currentlySuggestedLocalization(network: network, extractKeys: ["Login.ContinueWithLocalization"]))) + |> then(TelegramEngineUnauthorized(account: self.account).localization.currentlySuggestedLocalization(extractKeys: ["Login.ContinueWithLocalization"]))) let suggestedLocalization = self.suggestedLocalization let localizationSignal = SSignal(generator: { subscriber in @@ -176,7 +174,7 @@ final class AuthorizationSequenceSplashController: ViewController { } if let suggestedCode = suggestedCode { - _ = markSuggestedLocalizationAsSeenInteractively(postbox: strongSelf.postbox, languageCode: suggestedCode).start() + _ = TelegramEngineUnauthorized(account: strongSelf.account).localization.markSuggestedLocalizationAsSeenInteractively(languageCode: suggestedCode).start() } if currentCode == code { @@ -186,9 +184,8 @@ final class AuthorizationSequenceSplashController: ViewController { strongSelf.controller.isEnabled = false let accountManager = strongSelf.accountManager - let postbox = strongSelf.postbox - strongSelf.activateLocalizationDisposable.set(downloadAndApplyLocalization(accountManager: accountManager, postbox: postbox, network: strongSelf.network, languageCode: code).start(completed: { + strongSelf.activateLocalizationDisposable.set(TelegramEngineUnauthorized(account: strongSelf.account).localization.downloadAndApplyLocalization(accountManager: accountManager, languageCode: code).start(completed: { let _ = (accountManager.transaction { transaction -> PresentationStrings? in let localizationSettings: LocalizationSettings? if let current = transaction.getSharedData(SharedDataKeys.localizationSettings) as? LocalizationSettings { diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index c3f0a7eea9..67a766b535 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -1216,9 +1216,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } - let account = strongSelf.context.account + let context = strongSelf.context if requiresPassword { - strongSelf.messageActionCallbackDisposable.set(((requestMessageActionCallbackPasswordCheck(account: account, messageId: messageId, isGame: isGame, data: data) + strongSelf.messageActionCallbackDisposable.set(((strongSelf.context.engine.messages.requestMessageActionCallbackPasswordCheck(messageId: messageId, isGame: isGame, data: data) |> afterDisposed { updateProgress() }) @@ -1226,7 +1226,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G let controller = ownershipTransferController(context: context, initialError: error, present: { c, a in strongSelf.present(c, in: .window(.root), with: a) }, commit: { password in - return requestMessageActionCallback(account: account, messageId: messageId, isGame: isGame, password: password, data: data) + return context.engine.messages.requestMessageActionCallback(messageId: messageId, isGame: isGame, password: password, data: data) |> afterDisposed { updateProgress() } @@ -1236,7 +1236,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G strongSelf.present(controller, in: .window(.root)) })) } else { - strongSelf.messageActionCallbackDisposable.set(((requestMessageActionCallback(account: account, messageId: messageId, isGame: isGame, password: nil, data: data) + strongSelf.messageActionCallbackDisposable.set(((context.engine.messages.requestMessageActionCallback(messageId: messageId, isGame: isGame, password: nil, data: data) |> afterDisposed { updateProgress() }) @@ -1269,7 +1269,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return $0 } }) - strongSelf.messageActionUrlAuthDisposable.set(((combineLatest(strongSelf.context.account.postbox.loadedPeerWithId(strongSelf.context.account.peerId), requestMessageActionUrlAuth(account: strongSelf.context.account, subject: subject) |> afterDisposed { + strongSelf.messageActionUrlAuthDisposable.set(((combineLatest(strongSelf.context.account.postbox.loadedPeerWithId(strongSelf.context.account.peerId), strongSelf.context.engine.messages.requestMessageActionUrlAuth(subject: subject) |> afterDisposed { Queue.mainQueue().async { if let strongSelf = self { strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { @@ -1318,7 +1318,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } }) - strongSelf.messageActionUrlAuthDisposable.set(((acceptMessageActionUrlAuth(account: strongSelf.context.account, subject: subject, allowWriteAccess: allowWriteAccess) |> afterDisposed { + strongSelf.messageActionUrlAuthDisposable.set(((strongSelf.context.engine.messages.acceptMessageActionUrlAuth(subject: subject, allowWriteAccess: allowWriteAccess) |> afterDisposed { Queue.mainQueue().async { if let strongSelf = self { strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { @@ -2094,7 +2094,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Delete"), color: theme.actionSheet.destructiveActionTextColor) }, action: { [weak self] controller, f in if let strongSelf = self { - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: [id], type: .forLocalPeer).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: [id], type: .forLocalPeer).start() } f(.dismissWithoutContent) }))) @@ -2325,7 +2325,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } return } else { - let _ = sendScheduledMessageNowInteractively(postbox: strongSelf.context.account.postbox, messageId: messageIds.first!).start() + let _ = strongSelf.context.engine.messages.sendScheduledMessageNowInteractively(messageId: messageIds.first!).start() } } }, editScheduledMessagesTime: { [weak self] messageIds in @@ -2346,7 +2346,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G break } } - strongSelf.editMessageDisposable.set((requestEditMessage(account: strongSelf.context.account, messageId: messageId, text: message.text, media: .keep, entities: entities, disableUrlPreview: false, scheduleTime: time) |> deliverOnMainQueue).start(next: { result in + strongSelf.editMessageDisposable.set((strongSelf.context.engine.messages.requestEditMessage(messageId: messageId, text: message.text, media: .keep, entities: entities, disableUrlPreview: false, scheduleTime: time) |> deliverOnMainQueue).start(next: { result in }, error: { error in })) } @@ -2841,7 +2841,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G |> mapToSignal { isLarge -> Signal in if let isLarge = isLarge { if isLarge { - return context.peerChannelMemberCategoriesContextsManager.recentOnline(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId) + return context.peerChannelMemberCategoriesContextsManager.recentOnline(account: context.account, accountPeerId: context.account.peerId, peerId: peerId) |> map(Optional.init) } else { return context.peerChannelMemberCategoriesContextsManager.recentOnlineSmall(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId) @@ -4995,9 +4995,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return } let _ = requestUpdatePeerIsBlocked(account: strongSelf.context.account, peerId: peer.id, isBlocked: true).start() - let account = strongSelf.context.account - let _ = (strongSelf.context.account.postbox.transaction { transasction -> Void in - deleteAllMessagesWithForwardAuthor(transaction: transasction, mediaBox: account.postbox.mediaBox, peerId: message.id.peerId, forwardAuthorId: peer.id, namespace: Namespaces.Message.Cloud) + let context = strongSelf.context + let _ = (context.account.postbox.transaction { transasction -> Void in + context.engine.messages.deleteAllMessagesWithForwardAuthor(transaction: transasction, peerId: message.id.peerId, forwardAuthorId: peer.id, namespace: Namespaces.Message.Cloud) }).start() let _ = reportRepliesMessage(account: strongSelf.context.account, messageId: message.id, deleteMessage: true, deleteHistory: true, reportSpam: reportSpam).start() }) @@ -5028,10 +5028,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } if isAction && (actions.options == .deleteGlobally || actions.options == .deleteLocally) { - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: actions.options == .deleteLocally ? .forLocalPeer : .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: actions.options == .deleteLocally ? .forLocalPeer : .forEveryone).start() completion(.dismissWithoutContent) } else if (messages.first?.flags.isSending ?? false) { - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forEveryone, deleteAllInGroup: true).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone, deleteAllInGroup: true).start() completion(.dismissWithoutContent) } else { if actions.options.intersection([.deleteLocally, .deleteGlobally]).isEmpty { @@ -5325,7 +5325,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G threadId = makeMessageThreadId(replyThreadMessage.messageId) } - strongSelf.messageIndexDisposable.set((searchMessageIdByTimestamp(account: strongSelf.context.account, peerId: peerId, threadId: threadId, timestamp: timestamp) |> deliverOnMainQueue).start(next: { messageId in + strongSelf.messageIndexDisposable.set((strongSelf.context.engine.messages.searchMessageIdByTimestamp(peerId: peerId, threadId: threadId, timestamp: timestamp) |> deliverOnMainQueue).start(next: { messageId in if let strongSelf = self { strongSelf.loadingMessage.set(.single(nil)) if let messageId = messageId { @@ -7829,7 +7829,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.updateChatPresentationInterfaceState(animated: true, interactive: true, { $0.updatedInterfaceState { $0.withoutSelectionState() } }) case .clearHistory: if case let .peer(peerId) = self.chatLocation { - let account = self.context.account + let context = self.context let beginClear: (InteractiveHistoryClearingType) -> Void = { [weak self] type in guard let strongSelf = self else { @@ -7849,7 +7849,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G strongSelf.present(UndoOverlayController(presentationData: strongSelf.context.sharedContext.currentPresentationData.with { $0 }, content: .removedChat(text: statusText), elevatedLayout: false, action: { value in if value == .commit { - let _ = clearHistoryInteractively(postbox: account.postbox, peerId: peerId, type: type).start(completed: { + let _ = context.engine.messages.clearHistoryInteractively(peerId: peerId, type: type).start(completed: { self?.chatDisplayNode.historyNode.historyAppearsCleared = false }) return true @@ -10076,7 +10076,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.searchDisposable = searchDisposable } - let search = searchMessages(account: self.context.account, location: searchState.location, query: searchState.query, state: nil, limit: limit) + let search = self.context.engine.messages.searchMessages(location: searchState.location, query: searchState.query, state: nil, limit: limit) |> delay(0.2, queue: Queue.mainQueue()) self.searchResult.set(search |> map { (result, state) -> (SearchMessagesResult, SearchMessagesState, SearchMessagesLocation)? in @@ -10130,7 +10130,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G searchDisposable = MetaDisposable() self.searchDisposable = searchDisposable } - searchDisposable.set((searchMessages(account: self.context.account, location: searchState.location, query: searchState.query, state: loadMoreState, limit: limit) + searchDisposable.set((self.context.engine.messages.searchMessages(location: searchState.location, query: searchState.query, state: loadMoreState, limit: limit) |> delay(0.2, queue: Queue.mainQueue()) |> deliverOnMainQueue).start(next: { [weak self] results, updatedState in guard let strongSelf = self else { @@ -11613,13 +11613,13 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if let strongSelf = self { strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { $0.updatedInterfaceState { $0.withoutSelectionState() } }) if actions.contains(3) { - let mediaBox = strongSelf.context.account.postbox.mediaBox - let _ = strongSelf.context.account.postbox.transaction({ transaction -> Void in - deleteAllMessagesWithAuthor(transaction: transaction, mediaBox: mediaBox, peerId: peerId, authorId: author.id, namespace: Namespaces.Message.Cloud) + let context = strongSelf.context + let _ = context.account.postbox.transaction({ transaction -> Void in + context.engine.messages.deleteAllMessagesWithAuthor(transaction: transaction, peerId: peerId, authorId: author.id, namespace: Namespaces.Message.Cloud) }).start() - let _ = clearAuthorHistory(account: strongSelf.context.account, peerId: peerId, memberId: author.id).start() + let _ = strongSelf.context.engine.messages.clearAuthorHistory(peerId: peerId, memberId: author.id).start() } else if actions.contains(0) { - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() } if actions.contains(1) { let _ = removePeerMember(account: strongSelf.context.account, peerId: peerId, memberId: author.id).start() @@ -11657,7 +11657,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G actionSheet?.dismissAnimated() if let strongSelf = self { strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { $0.updatedInterfaceState { $0.withoutSelectionState() } }) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() } })) } @@ -11684,7 +11684,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G contextItems.append(.action(ContextMenuActionItem(text: globalTitle, textColor: .destructive, icon: { _ in nil }, action: { [weak self] _, f in if let strongSelf = self { strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { $0.updatedInterfaceState { $0.withoutSelectionState() } }) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() f(.dismissWithoutContent) } }))) @@ -11692,7 +11692,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G actionSheet?.dismissAnimated() if let strongSelf = self { strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { $0.updatedInterfaceState { $0.withoutSelectionState() } }) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() } })) } @@ -11714,7 +11714,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G contextItems.append(.action(ContextMenuActionItem(text: localOptionText, textColor: .destructive, icon: { _ in nil }, action: { [weak self] _, f in if let strongSelf = self { strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { $0.updatedInterfaceState { $0.withoutSelectionState() } }) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: unsendPersonalMessages ? .forEveryone : .forLocalPeer).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: unsendPersonalMessages ? .forEveryone : .forLocalPeer).start() f(.dismissWithoutContent) } }))) @@ -11722,7 +11722,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G actionSheet?.dismissAnimated() if let strongSelf = self { strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { $0.updatedInterfaceState { $0.withoutSelectionState() } }) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: unsendPersonalMessages ? .forEveryone : .forLocalPeer).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: unsendPersonalMessages ? .forEveryone : .forLocalPeer).start() } })) } diff --git a/submodules/TelegramUI/Sources/ChatHistorySearchContainerNode.swift b/submodules/TelegramUI/Sources/ChatHistorySearchContainerNode.swift index 7f99889553..bfdfe79955 100644 --- a/submodules/TelegramUI/Sources/ChatHistorySearchContainerNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistorySearchContainerNode.swift @@ -194,7 +194,7 @@ final class ChatHistorySearchContainerNode: SearchDisplayControllerContentNode { if let strongSelf = self { let signal: Signal<([ChatHistorySearchEntry], [MessageId: Message])?, NoError> if let query = query, !query.isEmpty { - let foundRemoteMessages: Signal<[Message], NoError> = searchMessages(account: context.account, location: .peer(peerId: peerId, fromId: nil, tags: tagMask, topMsgId: nil, minDate: nil, maxDate: nil), query: query, state: nil) + let foundRemoteMessages: Signal<[Message], NoError> = context.engine.messages.searchMessages(location: .peer(peerId: peerId, fromId: nil, tags: tagMask, topMsgId: nil, minDate: nil, maxDate: nil), query: query, state: nil) |> map { $0.0.messages } |> delay(0.2, queue: Queue.concurrentDefaultQueue()) diff --git a/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift b/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift index 072496df97..4fec8deb0e 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift @@ -182,7 +182,7 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode { case let .fetchStatus(fetchStatus): if let context = self.context, let message = self.message, message.flags.isSending { let _ = context.account.postbox.transaction({ transaction -> Void in - deleteMessages(transaction: transaction, mediaBox: context.account.postbox.mediaBox, ids: [message.id]) + context.engine.messages.deleteMessages(transaction: transaction, ids: [message.id]) }).start() } else { switch fetchStatus { diff --git a/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift b/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift index d65ffa39ca..68466f689c 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift @@ -741,7 +741,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { if item.message.flags.isSending { let messageId = item.message.id let _ = item.context.account.postbox.transaction({ transaction -> Void in - deleteMessages(transaction: transaction, mediaBox: item.context.account.postbox.mediaBox, ids: [messageId]) + item.context.engine.messages.deleteMessages(transaction: transaction, ids: [messageId]) }).start() } else { messageMediaFileCancelInteractiveFetch(context: item.context, messageId: item.message.id, file: file) diff --git a/submodules/TelegramUI/Sources/ChatMessageInteractiveMediaNode.swift b/submodules/TelegramUI/Sources/ChatMessageInteractiveMediaNode.swift index 1f0f32bcbb..2ec2cfbf08 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInteractiveMediaNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInteractiveMediaNode.swift @@ -299,7 +299,7 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio case .Fetching: if let context = self.context, let message = self.message, message.flags.isSending { let _ = context.account.postbox.transaction({ transaction -> Void in - deleteMessages(transaction: transaction, mediaBox: context.account.postbox.mediaBox, ids: [message.id]) + context.engine.messages.deleteMessages(transaction: transaction, ids: [message.id]) }).start() } else if let media = media, let context = self.context, let message = message { if let media = media as? TelegramMediaFile { diff --git a/submodules/TelegramUI/Sources/ChatSearchResultsContollerNode.swift b/submodules/TelegramUI/Sources/ChatSearchResultsContollerNode.swift index 645f19bec5..5a42e01f36 100644 --- a/submodules/TelegramUI/Sources/ChatSearchResultsContollerNode.swift +++ b/submodules/TelegramUI/Sources/ChatSearchResultsContollerNode.swift @@ -256,7 +256,7 @@ class ChatSearchResultsControllerNode: ViewControllerTracingNode, UIScrollViewDe private func loadMore() { self.isLoadingMore = true - self.loadMoreDisposable.set((searchMessages(account: self.context.account, location: self.location, query: self.searchQuery, state: self.searchState) + self.loadMoreDisposable.set((self.context.engine.messages.searchMessages(location: self.location, query: self.searchQuery, state: self.searchState) |> deliverOnMainQueue).start(next: { [weak self] (updatedResult, updatedState) in guard let strongSelf = self else { return diff --git a/submodules/TelegramUI/Sources/ComposeController.swift b/submodules/TelegramUI/Sources/ComposeController.swift index b172d964ee..60ca4c40fa 100644 --- a/submodules/TelegramUI/Sources/ComposeController.swift +++ b/submodules/TelegramUI/Sources/ComposeController.swift @@ -161,7 +161,7 @@ public class ComposeControllerImpl: ViewController, ComposeController { if let strongSelf = self, let (contactPeers, _) = result, case let .peer(peer, _, _) = contactPeers.first { controller?.dismissSearch() controller?.displayNavigationActivity = true - strongSelf.createActionDisposable.set((createSecretChat(account: strongSelf.context.account, peerId: peer.id) |> deliverOnMainQueue).start(next: { peerId in + strongSelf.createActionDisposable.set((strongSelf.context.engine.peers.createSecretChat(peerId: peer.id) |> deliverOnMainQueue).start(next: { peerId in if let strongSelf = self, let controller = controller { controller.displayNavigationActivity = false (controller.navigationController as? NavigationController)?.replaceAllButRootController(ChatControllerImpl(context: strongSelf.context, chatLocation: .peer(peerId)), animated: true) diff --git a/submodules/TelegramUI/Sources/CreateGroupController.swift b/submodules/TelegramUI/Sources/CreateGroupController.swift index 7e34633f85..98bb6cf961 100644 --- a/submodules/TelegramUI/Sources/CreateGroupController.swift +++ b/submodules/TelegramUI/Sources/CreateGroupController.swift @@ -425,7 +425,7 @@ public func createGroupControllerImpl(context: AccountContext, peerIds: [PeerId] let createSignal: Signal switch mode { case .generic: - createSignal = createGroup(account: context.account, title: title, peerIds: peerIds) + createSignal = context.engine.peers.createGroup(title: title, peerIds: peerIds) case .supergroup: createSignal = createSupergroup(account: context.account, title: title, description: nil) |> map(Optional.init) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoData.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoData.swift index b9ff945628..0e4be25a38 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoData.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoData.swift @@ -688,7 +688,7 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen |> mapToSignal { isLarge -> Signal in if let isLarge = isLarge { if isLarge { - return context.peerChannelMemberCategoriesContextsManager.recentOnline(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId) + return context.peerChannelMemberCategoriesContextsManager.recentOnline(account: context.account, accountPeerId: context.account.peerId, peerId: peerId) |> map(Optional.init) } else { return context.peerChannelMemberCategoriesContextsManager.recentOnlineSmall(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 4e78bd5780..6aabd0001d 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -1807,7 +1807,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD c.dismiss(completion: { if let strongSelf = self { strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() } }) }))) @@ -1826,7 +1826,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD c.dismiss(completion: { if let strongSelf = self { strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forLocalPeer).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forLocalPeer).start() } }) }))) @@ -1941,7 +1941,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD c.dismiss(completion: { if let strongSelf = self { strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() } }) }))) @@ -1960,7 +1960,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD c.dismiss(completion: { if let strongSelf = self { strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forLocalPeer).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forLocalPeer).start() } }) }))) @@ -3836,7 +3836,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD guard let strongSelf = self else { return } - var createSignal = createSecretChat(account: strongSelf.context.account, peerId: peerId) + var createSignal = strongSelf.context.engine.peers.createSecretChat(peerId: peerId) var cancelImpl: (() -> Void)? let progressSignal = Signal { subscriber in if let strongSelf = self { @@ -5605,7 +5605,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD actionSheet?.dismissAnimated() if let strongSelf = self { strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forEveryone).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() } })) } @@ -5622,7 +5622,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD actionSheet?.dismissAnimated() if let strongSelf = self { strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone) - let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forLocalPeer).start() + let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forLocalPeer).start() } })) } @@ -7149,7 +7149,7 @@ func presentAddMembers(context: AccountContext, parentController: ViewController }) return .complete() case .groupFull: - let signal = convertGroupToSupergroup(account: context.account, peerId: groupPeer.id) + let signal = context.engine.peers.convertGroupToSupergroup(peerId: groupPeer.id) |> map(Optional.init) |> `catch` { error -> Signal in switch error { diff --git a/submodules/TelegramUI/Sources/SharedNotificationManager.swift b/submodules/TelegramUI/Sources/SharedNotificationManager.swift index 77d8ea8fa5..603a877a6f 100644 --- a/submodules/TelegramUI/Sources/SharedNotificationManager.swift +++ b/submodules/TelegramUI/Sources/SharedNotificationManager.swift @@ -397,7 +397,7 @@ public final class SharedNotificationManager { if !messagesDeleted.isEmpty { let _ = account.postbox.transaction(ignoreDisabled: true, { transaction -> Void in - deleteMessages(transaction: transaction, mediaBox: account.postbox.mediaBox, ids: messagesDeleted) + TelegramEngine(account: account).messages.deleteMessages(transaction: transaction, ids: messagesDeleted) }).start() } diff --git a/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift b/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift index 2f5b294faf..39169aae5d 100644 --- a/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift +++ b/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift @@ -78,7 +78,7 @@ private final class PeerChannelMemberCategoriesContextsManagerImpl { } } - func recentOnline(postbox: Postbox, network: Network, accountPeerId: PeerId, peerId: PeerId, updated: @escaping (Int32) -> Void) -> Disposable { + func recentOnline(account: Account, accountPeerId: PeerId, peerId: PeerId, updated: @escaping (Int32) -> Void) -> Disposable { let context: PeerChannelMembersOnlineContext if let current = self.onlineContexts[peerId] { context = current @@ -88,7 +88,7 @@ private final class PeerChannelMemberCategoriesContextsManagerImpl { self.onlineContexts[peerId] = context let signal = ( - chatOnlineMembers(postbox: postbox, network: network, peerId: peerId) + TelegramEngine(account: account).peers.chatOnlineMembers(peerId: peerId) |> then( .complete() |> delay(30.0, queue: .mainQueue()) @@ -483,7 +483,7 @@ public final class PeerChannelMemberCategoriesContextsManager { } } - public func recentOnline(postbox: Postbox, network: Network, accountPeerId: PeerId, peerId: PeerId) -> Signal { + public func recentOnline(account: Account, accountPeerId: PeerId, peerId: PeerId) -> Signal { return Signal { [weak self] subscriber in guard let strongSelf = self else { subscriber.putNext(0) @@ -491,7 +491,7 @@ public final class PeerChannelMemberCategoriesContextsManager { return EmptyDisposable } let disposable = strongSelf.impl.syncWith({ impl -> Disposable in - return impl.recentOnline(postbox: postbox, network: network, accountPeerId: accountPeerId, peerId: peerId, updated: { value in + return impl.recentOnline(account: account, accountPeerId: accountPeerId, peerId: peerId, updated: { value in subscriber.putNext(value) }) }) diff --git a/submodules/WatchBridge/Sources/WatchRequestHandlers.swift b/submodules/WatchBridge/Sources/WatchRequestHandlers.swift index 968fbc8eb3..d56763ddfd 100644 --- a/submodules/WatchBridge/Sources/WatchRequestHandlers.swift +++ b/submodules/WatchBridge/Sources/WatchRequestHandlers.swift @@ -123,7 +123,7 @@ final class WatchChatMessagesHandler: WatchRequestHandler { |> mapToSignal({ context -> Signal in if let context = context { let messageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: args.messageId) - return applyMaxReadIndexInteractively(postbox: context.account.postbox, stateManager: context.account.stateManager, index: MessageIndex(id: messageId, timestamp: 0)) + return context.engine.messages.applyMaxReadIndexInteractively(index: MessageIndex(id: messageId, timestamp: 0)) } else { return .complete() } @@ -144,7 +144,7 @@ final class WatchChatMessagesHandler: WatchRequestHandler { |> take(1) |> mapToSignal({ context -> Signal<(Message, PresentationData)?, NoError> in if let context = context { - let messageSignal = downloadMessage(postbox: context.account.postbox, network: context.account.network, messageId: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: args.messageId)) + 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 })