diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index d25743fd3a..71a48ce17a 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -2766,7 +2766,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController private func prepareRandomGreetingSticker() { let context = self.context self.preloadedSticker.set(.single(nil) - |> then(randomGreetingSticker(account: context.account) + |> then(context.engine.stickers.randomGreetingSticker() |> map { item in return item?.file })) diff --git a/submodules/ContactListUI/Sources/ContactsController.swift b/submodules/ContactListUI/Sources/ContactsController.swift index 1ec9005311..ddd00d0c2a 100644 --- a/submodules/ContactListUI/Sources/ContactsController.swift +++ b/submodules/ContactListUI/Sources/ContactsController.swift @@ -526,11 +526,10 @@ public class ContactsController: ViewController { }) } - private func prepareRandomGreetingSticker() { let context = self.context self.preloadedSticker.set(.single(nil) - |> then(randomGreetingSticker(account: context.account) + |> then(context.engine.stickers.randomGreetingSticker() |> map { item in return item?.file })) diff --git a/submodules/CountrySelectionUI/Sources/AuthorizationSequenceCountrySelectionController.swift b/submodules/CountrySelectionUI/Sources/AuthorizationSequenceCountrySelectionController.swift index 653cf32759..da30560db6 100644 --- a/submodules/CountrySelectionUI/Sources/AuthorizationSequenceCountrySelectionController.swift +++ b/submodules/CountrySelectionUI/Sources/AuthorizationSequenceCountrySelectionController.swift @@ -69,8 +69,8 @@ private func loadCountryCodes() -> [Country] { private var countryCodes: [Country] = loadCountryCodes() private var countryCodesByPrefix: [String: (Country, Country.CountryCode)] = [:] -public func loadServerCountryCodes(accountManager: AccountManager, network: Network, completion: @escaping () -> Void) { - let _ = (getCountriesList(accountManager: accountManager, network: network, langCode: nil) +public func loadServerCountryCodes(accountManager: AccountManager, engine: TelegramEngineUnauthorized, completion: @escaping () -> Void) { + let _ = (engine.localization.getCountriesList(accountManager: accountManager, langCode: nil) |> deliverOnMainQueue).start(next: { countries in countryCodes = countries @@ -93,6 +93,30 @@ public func loadServerCountryCodes(accountManager: AccountManager, network: Netw }) } +public func loadServerCountryCodes(accountManager: AccountManager, engine: TelegramEngine, completion: @escaping () -> Void) { + let _ = (engine.localization.getCountriesList(accountManager: accountManager, langCode: nil) + |> deliverOnMainQueue).start(next: { countries in + countryCodes = countries + + var countriesByPrefix: [String: (Country, Country.CountryCode)] = [:] + for country in countries { + for code in country.countryCodes { + if !code.prefixes.isEmpty { + for prefix in code.prefixes { + countriesByPrefix["\(code.code)\(prefix)"] = (country, code) + } + } else { + countriesByPrefix[code.code] = (country, code) + } + } + } + countryCodesByPrefix = countriesByPrefix + Queue.mainQueue().async { + completion() + } + }) +} + private final class AuthorizationSequenceCountrySelectionNavigationContentNode: NavigationBarContentNode { private let theme: PresentationTheme private let strings: PresentationStrings diff --git a/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift index 8e3bab9eb4..61111be0e2 100644 --- a/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift @@ -353,7 +353,7 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode { |> delay(0.15, queue: Queue.mainQueue()) let progressDisposable = progressSignal.start() - let signal = stickerPacksAttachedToMedia(account: context.account, media: media) + let signal = context.engine.stickers.stickerPacksAttachedToMedia(media: media) |> afterDisposed { Queue.mainQueue().async { progressDisposable.dispose() diff --git a/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift b/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift index 6d35337792..9423124dc1 100644 --- a/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift @@ -1637,7 +1637,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode { self.isInteractingPromise.set(true) - let signal = stickerPacksAttachedToMedia(account: self.context.account, media: media) + let signal = self.context.engine.stickers.stickerPacksAttachedToMedia(media: media) |> afterDisposed { Queue.mainQueue().async { progressDisposable.dispose() diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacySuggestionContext.swift b/submodules/LegacyMediaPickerUI/Sources/LegacySuggestionContext.swift index 2af3181ce3..22386c4bd0 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacySuggestionContext.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacySuggestionContext.swift @@ -74,7 +74,7 @@ public func legacySuggestionContext(context: AccountContext, peerId: PeerId, cha return SSignal.complete() } return SSignal { subscriber in - let disposable = (searchEmojiKeywords(postbox: context.account.postbox, inputLanguageCode: inputLanguageCode, query: query, completeMatch: query.count < 3) + let disposable = (context.engine.stickers.searchEmojiKeywords(inputLanguageCode: inputLanguageCode, query: query, completeMatch: query.count < 3) |> map { keywords -> [TGAlphacodeEntry] in var result: [TGAlphacodeEntry] = [] for keyword in keywords { diff --git a/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift b/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift index 472cfcc447..9ec05ffc23 100644 --- a/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift +++ b/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift @@ -323,7 +323,7 @@ public func groupStickerPackSetupController(context: AccountContext, peerId: Pee let initialData = Promise() if let currentPackInfo = currentPackInfo { - initialData.set(cachedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: .id(id: currentPackInfo.id.id, accessHash: currentPackInfo.accessHash), forceRemote: false) + initialData.set(context.engine.stickers.cachedStickerPack(reference: .id(id: currentPackInfo.id.id, accessHash: currentPackInfo.accessHash), forceRemote: false) |> map { result -> InitialStickerPackData? in switch result { case .none: @@ -363,7 +363,7 @@ public func groupStickerPackSetupController(context: AccountContext, peerId: Pee } } return .single((searchText, .searching)) - |> then((loadedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: .name(searchText.lowercased()), forceActualized: false) |> delay(0.3, queue: Queue.concurrentDefaultQueue())) + |> then((context.engine.stickers.loadedStickerPack(reference: .name(searchText.lowercased()), forceActualized: false) |> delay(0.3, queue: Queue.concurrentDefaultQueue())) |> mapToSignal { value -> Signal<(String, GroupStickerPackSearchState), NoError> in switch value { case .fetching: diff --git a/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift b/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift index 3e25abcabf..830ea6110b 100644 --- a/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift +++ b/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift @@ -90,7 +90,7 @@ final class ChangePhoneNumberController: ViewController, MFMailComposeViewContro } } - loadServerCountryCodes(accountManager: self.context.sharedContext.accountManager, network: self.context.account.network, completion: { [weak self] in + loadServerCountryCodes(accountManager: self.context.sharedContext.accountManager, engine: self.context.engine, completion: { [weak self] in if let strongSelf = self { strongSelf.controllerNode.updateCountryCode() } diff --git a/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift index 84d5b2a096..9ab2596ff6 100644 --- a/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift @@ -268,7 +268,7 @@ public func archivedStickerPacksController(context: AccountContext, mode: Archiv namespace = .masks } let stickerPacks = Promise<[ArchivedStickerPackItem]?>() - stickerPacks.set(.single(archived) |> then(archivedStickerPacks(account: context.account, namespace: namespace) |> map(Optional.init))) + stickerPacks.set(.single(archived) |> then(context.engine.stickers.archivedStickerPacks(namespace: namespace) |> map(Optional.init))) actionsDisposable.add(stickerPacks.get().start(next: { packs in updatedPacks(packs) @@ -302,17 +302,16 @@ public func archivedStickerPacksController(context: AccountContext, mode: Archiv if !add { return } - let _ = (loadedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) + let _ = (context.engine.stickers.loadedStickerPack(reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) |> mapToSignal { result -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem]), NoError> in switch result { case let .result(info, items, installed): if installed { return .complete() } else { - return addStickerPackInteractively(postbox: context.account.postbox, info: info, items: items) + return context.engine.stickers.addStickerPackInteractively(info: info, items: items) |> ignoreValues |> mapToSignal { _ -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem]), NoError> in - return .complete() } |> then(.single((info, items))) } @@ -336,7 +335,7 @@ public func archivedStickerPacksController(context: AccountContext, mode: Archiv } } - presentControllerImpl?(UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, account: context.account), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { _ in + presentControllerImpl?(UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, context: context), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { _ in return true }), nil) @@ -390,7 +389,7 @@ public func archivedStickerPacksController(context: AccountContext, mode: Archiv return .complete() } - removePackDisposables.set((removeArchivedStickerPack(account: context.account, info: info) |> then(applyPacks) |> deliverOnMainQueue).start(completed: { + removePackDisposables.set((context.engine.stickers.removeArchivedStickerPack(info: info) |> then(applyPacks) |> deliverOnMainQueue).start(completed: { updateState { state in var removingPackIds = state.removingPackIds removingPackIds.remove(info.id) diff --git a/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift index f98650abec..b460f6c795 100644 --- a/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift @@ -180,14 +180,14 @@ public func featuredStickerPacksController(context: AccountContext) -> ViewContr let arguments = FeaturedStickerPacksControllerArguments(account: context.account, openStickerPack: { info in presentStickerPackController?(info) }, addPack: { info in - let _ = (loadedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) + let _ = (context.engine.stickers.loadedStickerPack(reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) |> mapToSignal { result -> Signal in switch result { case let .result(info, items, installed): if installed { return .complete() } else { - return addStickerPackInteractively(postbox: context.account.postbox, info: info, items: items) + return context.engine.stickers.addStickerPackInteractively(info: info, items: items) } case .fetching: break @@ -254,7 +254,7 @@ public func featuredStickerPacksController(context: AccountContext) -> ViewContr if !unreadIds.isEmpty { alreadyReadIds.formUnion(Set(unreadIds)) - let _ = markFeaturedStickerPacksAsSeenInteractively(postbox: context.account.postbox, ids: unreadIds).start() + let _ = context.engine.stickers.markFeaturedStickerPacksAsSeenInteractively(ids: unreadIds).start() } } diff --git a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift index 54ee4d0495..c5d62f21f0 100644 --- a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift @@ -532,7 +532,7 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta controller?.dismissAnimated() } let removeAction: (RemoveStickerPackOption) -> Void = { action in - let _ = (removeStickerPackInteractively(postbox: context.account.postbox, id: archivedItem.info.id, option: action) + let _ = (context.engine.stickers.removeStickerPackInteractively(id: archivedItem.info.id, option: action) |> deliverOnMainQueue).start(next: { indexAndItems in guard let (positionInList, items) = indexAndItems else { return @@ -548,9 +548,9 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta } } - navigationControllerImpl?()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: action == .archive ? presentationData.strings.StickerPackActionInfo_ArchivedTitle : presentationData.strings.StickerPackActionInfo_RemovedTitle, text: presentationData.strings.StickerPackActionInfo_RemovedText(archivedItem.info.title).0, undo: true, info: archivedItem.info, topItem: archivedItem.topItems.first, account: context.account), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { action in + navigationControllerImpl?()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: action == .archive ? presentationData.strings.StickerPackActionInfo_ArchivedTitle : presentationData.strings.StickerPackActionInfo_RemovedTitle, text: presentationData.strings.StickerPackActionInfo_RemovedText(archivedItem.info.title).0, undo: true, info: archivedItem.info, topItem: archivedItem.topItems.first, context: context), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { action in if case .undo = action { - let _ = addStickerPackInteractively(postbox: context.account.postbox, info: archivedItem.info, items: items, positionInList: positionInList).start() + let _ = context.engine.stickers.addStickerPackInteractively(info: archivedItem.info, items: items, positionInList: positionInList).start() } return true })) @@ -655,10 +655,10 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta switch mode { case .general, .modal: featured.set(context.account.viewTracker.featuredStickerPacks()) - archivedPromise.set(.single(archivedPacks) |> then(archivedStickerPacks(account: context.account) |> map(Optional.init))) + archivedPromise.set(.single(archivedPacks) |> then(context.engine.stickers.archivedStickerPacks() |> map(Optional.init))) case .masks: featured.set(.single([])) - archivedPromise.set(.single(nil) |> then(archivedStickerPacks(account: context.account, namespace: .masks) |> map(Optional.init))) + archivedPromise.set(.single(nil) |> then(context.engine.stickers.archivedStickerPacks(namespace: .masks) |> map(Optional.init))) } var previousPackCount: Int? @@ -717,7 +717,7 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta } } - let _ = removeStickerPacksInteractively(postbox: context.account.postbox, ids: packIds, option: .delete).start() + let _ = context.engine.stickers.removeStickerPacksInteractively(ids: packIds, option: .delete).start() })) actionSheet.setItemGroups([ActionSheetItemGroup(items: items), ActionSheetItemGroup(items: [ ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in @@ -742,7 +742,7 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta } } - let _ = removeStickerPacksInteractively(postbox: context.account.postbox, ids: packIds, option: .archive).start() + let _ = context.engine.stickers.removeStickerPacksInteractively(ids: packIds, option: .archive).start() })) actionSheet.setItemGroups([ActionSheetItemGroup(items: items), ActionSheetItemGroup(items: [ ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in @@ -954,13 +954,13 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta } switch action { case .add: - navigationControllerImpl?()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, account: context.account), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { _ in + navigationControllerImpl?()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, context: context), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { _ in return true })) case let .remove(positionInList): - navigationControllerImpl?()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_RemovedTitle, text: presentationData.strings.StickerPackActionInfo_RemovedText(info.title).0, undo: true, info: info, topItem: items.first, account: context.account), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { action in + navigationControllerImpl?()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_RemovedTitle, text: presentationData.strings.StickerPackActionInfo_RemovedText(info.title).0, undo: true, info: info, topItem: items.first, context: context), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { action in if case .undo = action { - let _ = addStickerPackInteractively(postbox: context.account.postbox, info: info, items: items, positionInList: positionInList).start() + let _ = context.engine.stickers.addStickerPackInteractively(info: info, items: items, positionInList: positionInList).start() } return true })) diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift index 91a7c85bff..aa483d713b 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift @@ -82,7 +82,7 @@ public final class StickerPackPreviewController: ViewController, StandalonePrese self.acceptsFocusWhenInOverlay = true self.statusBar.statusBarStyle = .Ignore - self.stickerPackContents.set(loadedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: stickerPack, forceActualized: true)) + self.stickerPackContents.set(context.engine.stickers.loadedStickerPack(reference: stickerPack, forceActualized: true)) self.presentationDataDisposable = (context.sharedContext.presentationData |> deliverOnMainQueue).start(next: { [weak self] presentationData in diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift index e4198bd782..32f0b8cf59 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift @@ -521,7 +521,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol switch stickerPack { case let .result(info, items, installed): if installed { - let _ = (removeStickerPackInteractively(postbox: self.context.account.postbox, id: info.id, option: .delete) + let _ = (self.context.engine.stickers.removeStickerPackInteractively(id: info.id, option: .delete) |> deliverOnMainQueue).start(next: { [weak self] indexAndItems in guard let strongSelf = self, let (positionInList, _) = indexAndItems else { return @@ -532,7 +532,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol self.updateStickerPack(.result(info: info, items: items, installed: false), stickerSettings: stickerSettings) } } else { - let _ = addStickerPackInteractively(postbox: self.context.account.postbox, info: info, items: items).start() + let _ = self.context.engine.stickers.addStickerPackInteractively(info: info, items: items).start() if !dismissOnAction { self.updateStickerPack(.result(info: info, items: items, installed: true), stickerSettings: stickerSettings) } diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackScreen.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackScreen.swift index 56fdd49e00..628ac687b3 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackScreen.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackScreen.swift @@ -238,7 +238,7 @@ private final class StickerPackContainer: ASDisplayNode { return updatedOffset } - self.itemsDisposable = (loadedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: stickerPack, forceActualized: false) + self.itemsDisposable = (context.engine.stickers.loadedStickerPack(reference: stickerPack, forceActualized: false) |> deliverOnMainQueue).start(next: { [weak self] contents in guard let strongSelf = self else { return @@ -340,9 +340,9 @@ private final class StickerPackContainer: ASDisplayNode { return } if installed { - let _ = removeStickerPackInteractively(postbox: strongSelf.context.account.postbox, id: info.id, option: .delete).start() + let _ = strongSelf.context.engine.stickers.removeStickerPackInteractively(id: info.id, option: .delete).start() } else { - let _ = addStickerPackInteractively(postbox: strongSelf.context.account.postbox, info: info, items: items).start() + let _ = strongSelf.context.engine.stickers.addStickerPackInteractively(info: info, items: items).start() } switch strongSelf.decideNextAction(strongSelf, installed ? .remove : .add) { diff --git a/submodules/TelegramCore/Sources/PeerSpecificStickerPack.swift b/submodules/TelegramCore/Sources/PeerSpecificStickerPack.swift index 0a9cea6eb7..acd61c4511 100644 --- a/submodules/TelegramCore/Sources/PeerSpecificStickerPack.swift +++ b/submodules/TelegramCore/Sources/PeerSpecificStickerPack.swift @@ -31,7 +31,7 @@ public func peerSpecificStickerPack(postbox: Postbox, network: Network, peerId: return signal |> mapToSignal { info, canInstall -> Signal in if let info = info.info { - return cachedStickerPack(postbox: postbox, network: network, reference: .id(id: info.id.id, accessHash: info.accessHash), forceRemote: false) + return _internal_cachedStickerPack(postbox: postbox, network: network, reference: .id(id: info.id.id, accessHash: info.accessHash), forceRemote: false) |> map { result -> PeerSpecificStickerPackData in if case let .result(info, items, _) = result { return PeerSpecificStickerPackData(packInfo: (info, items), canSetup: canInstall) diff --git a/submodules/TelegramCore/Sources/State/ManagedAnimatedEmojiUpdates.swift b/submodules/TelegramCore/Sources/State/ManagedAnimatedEmojiUpdates.swift index bb16cf50fa..1577d99a51 100644 --- a/submodules/TelegramCore/Sources/State/ManagedAnimatedEmojiUpdates.swift +++ b/submodules/TelegramCore/Sources/State/ManagedAnimatedEmojiUpdates.swift @@ -5,7 +5,7 @@ import TelegramApi import MtProtoKit func managedAnimatedEmojiUpdates(postbox: Postbox, network: Network) -> Signal { - let poll = loadedStickerPack(postbox: postbox, network: network, reference: .animatedEmoji, forceActualized: true) + let poll = _internal_loadedStickerPack(postbox: postbox, network: network, reference: .animatedEmoji, forceActualized: true) |> mapToSignal { _ -> Signal in return .complete() } diff --git a/submodules/TelegramCore/Sources/StickerManagement.swift b/submodules/TelegramCore/Sources/State/StickerManagement.swift similarity index 100% rename from submodules/TelegramCore/Sources/StickerManagement.swift rename to submodules/TelegramCore/Sources/State/StickerManagement.swift diff --git a/submodules/TelegramCore/Sources/Countries.swift b/submodules/TelegramCore/Sources/TelegramEngine/Localization/Countries.swift similarity index 97% rename from submodules/TelegramCore/Sources/Countries.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Localization/Countries.swift index 6ba3de2611..42fd67735d 100644 --- a/submodules/TelegramCore/Sources/Countries.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Localization/Countries.swift @@ -102,7 +102,7 @@ public final class CountriesList: PreferencesEntry, Equatable { } -public func getCountriesList(accountManager: AccountManager, network: Network, langCode: String?, forceUpdate: Bool = false) -> Signal<[Country], NoError> { +func _internal_getCountriesList(accountManager: AccountManager, network: Network, langCode: String?, forceUpdate: Bool = false) -> Signal<[Country], NoError> { let fetch: ([Country]?, Int32?) -> Signal<[Country], NoError> = { current, hash in return network.request(Api.functions.help.getCountriesList(langCode: langCode ?? "", hash: hash ?? 0)) |> retryRequest diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift b/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift new file mode 100644 index 0000000000..3f35e99178 --- /dev/null +++ b/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift @@ -0,0 +1,30 @@ +import SwiftSignalKit +import Postbox + +public extension TelegramEngine { + final class Localization { + private let account: Account + + init(account: Account) { + self.account = account + } + + 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 extension TelegramEngineUnauthorized { + final class Localization { + private let account: UnauthorizedAccount + + init(account: UnauthorizedAccount) { + self.account = account + } + + 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) + } + } +} diff --git a/submodules/TelegramCore/Sources/TelegramEngine/PeerManagement/TelegramEnginePeerManagement.swift b/submodules/TelegramCore/Sources/TelegramEngine/PeerManagement/TelegramEnginePeerManagement.swift new file mode 100644 index 0000000000..112d788c1d --- /dev/null +++ b/submodules/TelegramCore/Sources/TelegramEngine/PeerManagement/TelegramEnginePeerManagement.swift @@ -0,0 +1,13 @@ +import SwiftSignalKit + +public extension TelegramEngine { + final class PeerManagement { + private let account: Account + + init(account: Account) { + self.account = account + } + + + } +} diff --git a/submodules/TelegramCore/Sources/RequestSecureIdForm.swift b/submodules/TelegramCore/Sources/TelegramEngine/SecureId/RequestSecureIdForm.swift similarity index 100% rename from submodules/TelegramCore/Sources/RequestSecureIdForm.swift rename to submodules/TelegramCore/Sources/TelegramEngine/SecureId/RequestSecureIdForm.swift diff --git a/submodules/TelegramCore/Sources/ArchivedStickerPacks.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/ArchivedStickerPacks.swift similarity index 87% rename from submodules/TelegramCore/Sources/ArchivedStickerPacks.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Stickers/ArchivedStickerPacks.swift index 5ffd9cb9b8..dac1149970 100644 --- a/submodules/TelegramCore/Sources/ArchivedStickerPacks.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/ArchivedStickerPacks.swift @@ -29,7 +29,7 @@ public final class ArchivedStickerPackItem { } } -public func archivedStickerPacks(account: Account, namespace: ArchivedStickerPacksNamespace = .stickers) -> Signal<[ArchivedStickerPackItem], NoError> { +func _internal_archivedStickerPacks(account: Account, namespace: ArchivedStickerPacksNamespace = .stickers) -> Signal<[ArchivedStickerPackItem], NoError> { var flags: Int32 = 0 if case .masks = namespace { flags |= 1 << 0 @@ -50,7 +50,7 @@ public func archivedStickerPacks(account: Account, namespace: ArchivedStickerPac } } -public func removeArchivedStickerPack(account: Account, info: StickerPackCollectionInfo) -> Signal { +func _internal_removeArchivedStickerPack(account: Account, info: StickerPackCollectionInfo) -> Signal { return account.network.request(Api.functions.messages.uninstallStickerSet(stickerset: Api.InputStickerSet.inputStickerSetID(id: info.id.id, accessHash: info.accessHash))) |> `catch` { _ -> Signal in return .single(.boolFalse) diff --git a/submodules/TelegramCore/Sources/CachedStickerPack.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift similarity index 98% rename from submodules/TelegramCore/Sources/CachedStickerPack.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift index 3362bb657f..f9b31ebe8a 100644 --- a/submodules/TelegramCore/Sources/CachedStickerPack.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift @@ -36,7 +36,7 @@ func cacheStickerPack(transaction: Transaction, info: StickerPackCollectionInfo, } } -public func cachedStickerPack(postbox: Postbox, network: Network, reference: StickerPackReference, forceRemote: Bool) -> Signal { +func _internal_cachedStickerPack(postbox: Postbox, network: Network, reference: StickerPackReference, forceRemote: Bool) -> Signal { return postbox.transaction { transaction -> CachedStickerPackResult? in if let (info, items, local) = cachedStickerPack(transaction: transaction, reference: reference) { if local { diff --git a/submodules/TelegramCore/Sources/EmojiKeywords.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/EmojiKeywords.swift similarity index 96% rename from submodules/TelegramCore/Sources/EmojiKeywords.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Stickers/EmojiKeywords.swift index 03f7d35eb8..7dd137a10f 100644 --- a/submodules/TelegramCore/Sources/EmojiKeywords.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/EmojiKeywords.swift @@ -11,7 +11,7 @@ private enum SearchEmojiKeywordsIntermediateResult { case completed([EmojiKeywordItem]) } -public func searchEmojiKeywords(postbox: Postbox, inputLanguageCode: String, query: String, completeMatch: Bool) -> Signal<[EmojiKeywordItem], NoError> { +func _internal_searchEmojiKeywords(postbox: Postbox, inputLanguageCode: String, query: String, completeMatch: Bool) -> Signal<[EmojiKeywordItem], NoError> { guard !query.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return .single([]) } diff --git a/submodules/TelegramCore/Sources/LoadedStickerPack.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/LoadedStickerPack.swift similarity index 93% rename from submodules/TelegramCore/Sources/LoadedStickerPack.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Stickers/LoadedStickerPack.swift index 53eb8104a4..f3349c812e 100644 --- a/submodules/TelegramCore/Sources/LoadedStickerPack.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/LoadedStickerPack.swift @@ -95,8 +95,8 @@ func updatedRemoteStickerPack(postbox: Postbox, network: Network, reference: Sti } } -public func loadedStickerPack(postbox: Postbox, network: Network, reference: StickerPackReference, forceActualized: Bool) -> Signal { - return cachedStickerPack(postbox: postbox, network: network, reference: reference, forceRemote: forceActualized) +func _internal_loadedStickerPack(postbox: Postbox, network: Network, reference: StickerPackReference, forceActualized: Bool) -> Signal { + return _internal_cachedStickerPack(postbox: postbox, network: network, reference: reference, forceRemote: forceActualized) |> map { result -> LoadedStickerPack in switch result { case .none: diff --git a/submodules/TelegramCore/Sources/SearchStickers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/SearchStickers.swift similarity index 96% rename from submodules/TelegramCore/Sources/SearchStickers.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Stickers/SearchStickers.swift index 2d42049bd2..248e79ee64 100644 --- a/submodules/TelegramCore/Sources/SearchStickers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/SearchStickers.swift @@ -58,7 +58,7 @@ public struct SearchStickersScope: OptionSet { public static let remote = SearchStickersScope(rawValue: 1 << 1) } -public func randomGreetingSticker(account: Account) -> Signal { +func _internal_randomGreetingSticker(account: Account) -> Signal { return account.postbox.transaction { transaction -> FoundStickerItem? in var stickerItems: [FoundStickerItem] = [] for entry in transaction.getOrderedListItems(collectionId: Namespaces.OrderedItemList.CloudGreetingStickers) { @@ -70,7 +70,7 @@ public func randomGreetingSticker(account: Account) -> Signal Signal<[FoundStickerItem], NoError> { +func _internal_searchStickers(account: Account, query: String, scope: SearchStickersScope = [.installed, .remote]) -> Signal<[FoundStickerItem], NoError> { if scope.isEmpty { return .single([]) } @@ -265,7 +265,7 @@ public struct FoundStickerSets { } } -public func searchStickerSetsRemotely(network: Network, query: String) -> Signal { +func _internal_searchStickerSetsRemotely(network: Network, query: String) -> Signal { return network.request(Api.functions.messages.searchStickerSets(flags: 0, q: query, hash: 0)) |> mapError {_ in} |> mapToSignal { value in @@ -291,7 +291,7 @@ public func searchStickerSetsRemotely(network: Network, query: String) -> Signal } } -public func searchStickerSets(postbox: Postbox, query: String) -> Signal { +func _internal_searchStickerSets(postbox: Postbox, query: String) -> Signal { return postbox.transaction { transaction -> Signal in let infos = transaction.getItemCollectionsInfos(namespace: Namespaces.ItemCollection.CloudStickerPacks) @@ -324,7 +324,7 @@ public func searchStickerSets(postbox: Postbox, query: String) -> Signal switchToLatest } -public func searchGifs(account: Account, query: String, nextOffset: String = "") -> Signal { +func _internal_searchGifs(account: Account, query: String, nextOffset: String = "") -> Signal { return account.postbox.transaction { transaction -> String in let configuration = currentSearchBotsConfiguration(transaction: transaction) return configuration.gifBotUsername ?? "gif" diff --git a/submodules/TelegramCore/Sources/StickerPack.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerPack.swift similarity index 98% rename from submodules/TelegramCore/Sources/StickerPack.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerPack.swift index 921b580e6e..61e247260f 100644 --- a/submodules/TelegramCore/Sources/StickerPack.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerPack.swift @@ -58,7 +58,7 @@ extension StickerPackCollectionInfo { } } -public func stickerPacksAttachedToMedia(account: Account, media: AnyMediaReference) -> Signal<[StickerPackReference], NoError> { +func _internal_stickerPacksAttachedToMedia(account: Account, media: AnyMediaReference) -> Signal<[StickerPackReference], NoError> { let inputMedia: Api.InputStickeredMedia let resourceReference: MediaResourceReference if let imageReference = media.concrete(TelegramMediaImage.self), let reference = imageReference.media.reference, case let .cloud(imageId, accessHash, fileReference) = reference, let representation = largestImageRepresentation(imageReference.media.representations) { diff --git a/submodules/TelegramCore/Sources/StickerPackInteractiveOperations.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerPackInteractiveOperations.swift similarity index 86% rename from submodules/TelegramCore/Sources/StickerPackInteractiveOperations.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerPackInteractiveOperations.swift index d923975fe1..1a4d0f8c21 100644 --- a/submodules/TelegramCore/Sources/StickerPackInteractiveOperations.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/StickerPackInteractiveOperations.swift @@ -4,7 +4,7 @@ import SwiftSignalKit import SyncCore -public func addStickerPackInteractively(postbox: Postbox, info: StickerPackCollectionInfo, items: [ItemCollectionItem], positionInList: Int? = nil) -> Signal { +func _internal_addStickerPackInteractively(postbox: Postbox, info: StickerPackCollectionInfo, items: [ItemCollectionItem], positionInList: Int? = nil) -> Signal { return postbox.transaction { transaction -> Void in let namespace: SynchronizeInstalledStickerPacksOperationNamespace? switch info.id.namespace { @@ -44,11 +44,11 @@ public enum RemoveStickerPackOption { case archive } -public func removeStickerPackInteractively(postbox: Postbox, id: ItemCollectionId, option: RemoveStickerPackOption) -> Signal<(Int, [ItemCollectionItem])?, NoError> { - return removeStickerPacksInteractively(postbox: postbox, ids: [id], option: option) +func _internal_removeStickerPackInteractively(postbox: Postbox, id: ItemCollectionId, option: RemoveStickerPackOption) -> Signal<(Int, [ItemCollectionItem])?, NoError> { + return _internal_removeStickerPacksInteractively(postbox: postbox, ids: [id], option: option) } -public func removeStickerPacksInteractively(postbox: Postbox, ids: [ItemCollectionId], option: RemoveStickerPackOption) -> Signal<(Int, [ItemCollectionItem])?, NoError> { +func _internal_removeStickerPacksInteractively(postbox: Postbox, ids: [ItemCollectionId], option: RemoveStickerPackOption) -> Signal<(Int, [ItemCollectionItem])?, NoError> { return postbox.transaction { transaction -> (Int, [ItemCollectionItem])? in var commonNamespace: SynchronizeInstalledStickerPacksOperationNamespace? for id in ids { @@ -91,7 +91,7 @@ public func removeStickerPacksInteractively(postbox: Postbox, ids: [ItemCollecti } } -public func markFeaturedStickerPacksAsSeenInteractively(postbox: Postbox, ids: [ItemCollectionId]) -> Signal { +func _internal_markFeaturedStickerPacksAsSeenInteractively(postbox: Postbox, ids: [ItemCollectionId]) -> Signal { return postbox.transaction { transaction -> Void in let idsSet = Set(ids) var items = transaction.getOrderedListItems(collectionId: Namespaces.OrderedItemList.CloudFeaturedStickerPacks) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/TelegramEngineStickers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/TelegramEngineStickers.swift new file mode 100644 index 0000000000..72b4e64009 --- /dev/null +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/TelegramEngineStickers.swift @@ -0,0 +1,73 @@ +import SwiftSignalKit +import SyncCore +import Postbox + +public extension TelegramEngine { + final class Stickers { + private let account: Account + + init(account: Account) { + self.account = account + } + + public func archivedStickerPacks(namespace: ArchivedStickerPacksNamespace = .stickers) -> Signal<[ArchivedStickerPackItem], NoError> { + return _internal_archivedStickerPacks(account: account, namespace: namespace) + } + + public func removeArchivedStickerPack(info: StickerPackCollectionInfo) -> Signal { + return _internal_removeArchivedStickerPack(account: self.account, info: info) + } + + public func cachedStickerPack(reference: StickerPackReference, forceRemote: Bool) -> Signal { + return _internal_cachedStickerPack(postbox: self.account.postbox, network: self.account.network, reference: reference, forceRemote: forceRemote) + } + + public func loadedStickerPack(reference: StickerPackReference, forceActualized: Bool) -> Signal { + return _internal_loadedStickerPack(postbox: self.account.postbox, network: self.account.network, reference: reference, forceActualized: forceActualized) + } + + public func randomGreetingSticker() -> Signal { + return _internal_randomGreetingSticker(account: self.account) + } + + public func searchStickers(query: String, scope: SearchStickersScope = [.installed, .remote]) -> Signal<[FoundStickerItem], NoError> { + return _internal_searchStickers(account: self.account, query: query, scope: scope) + } + + public func searchStickerSetsRemotely(query: String) -> Signal { + return _internal_searchStickerSetsRemotely(network: self.account.network, query: query) + } + + public func searchStickerSets(query: String) -> Signal { + return _internal_searchStickerSets(postbox: self.account.postbox, query: query) + } + + public func searchGifs(query: String, nextOffset: String = "") -> Signal { + return _internal_searchGifs(account: self.account, query: query, nextOffset: nextOffset) + } + + public func addStickerPackInteractively(info: StickerPackCollectionInfo, items: [ItemCollectionItem], positionInList: Int? = nil) -> Signal { + return _internal_addStickerPackInteractively(postbox: self.account.postbox, info: info, items: items, positionInList: positionInList) + } + + public func removeStickerPackInteractively(id: ItemCollectionId, option: RemoveStickerPackOption) -> Signal<(Int, [ItemCollectionItem])?, NoError> { + return _internal_removeStickerPackInteractively(postbox: self.account.postbox, id: id, option: option) + } + + public func removeStickerPacksInteractively(ids: [ItemCollectionId], option: RemoveStickerPackOption) -> Signal<(Int, [ItemCollectionItem])?, NoError> { + return _internal_removeStickerPacksInteractively(postbox: self.account.postbox, ids: ids, option: option) + } + + public func markFeaturedStickerPacksAsSeenInteractively(ids: [ItemCollectionId]) -> Signal { + return _internal_markFeaturedStickerPacksAsSeenInteractively(postbox: self.account.postbox, ids: ids) + } + + public func searchEmojiKeywords(inputLanguageCode: String, query: String, completeMatch: Bool) -> Signal<[EmojiKeywordItem], NoError> { + return _internal_searchEmojiKeywords(postbox: self.account.postbox, inputLanguageCode: inputLanguageCode, query: query, completeMatch: completeMatch) + } + + public func stickerPacksAttachedToMedia(media: AnyMediaReference) -> Signal<[StickerPackReference], NoError> { + return _internal_stickerPacksAttachedToMedia(account: self.account, media: media) + } + } +} diff --git a/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift b/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift index 78e12fc07f..2389f19737 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/TelegramEngine.swift @@ -31,6 +31,18 @@ public final class TelegramEngine { public lazy var accountData: AccountData = { return AccountData(account: self.account) }() + + public lazy var stickers: Stickers = { + return Stickers(account: self.account) + }() + + public lazy var peerManagement: PeerManagement = { + return PeerManagement(account: self.account) + }() + + public lazy var localization: Localization = { + return Localization(account: self.account) + }() } public final class TelegramEngineUnauthorized { @@ -43,4 +55,8 @@ public final class TelegramEngineUnauthorized { public lazy var auth: Auth = { return Auth(account: self.account) }() + + public lazy var localization: Localization = { + return Localization(account: self.account) + }() } diff --git a/submodules/TelegramUI/Sources/AuthorizationSequencePhoneEntryController.swift b/submodules/TelegramUI/Sources/AuthorizationSequencePhoneEntryController.swift index 3b44aa35aa..8bada79ec5 100644 --- a/submodules/TelegramUI/Sources/AuthorizationSequencePhoneEntryController.swift +++ b/submodules/TelegramUI/Sources/AuthorizationSequencePhoneEntryController.swift @@ -140,7 +140,7 @@ final class AuthorizationSequencePhoneEntryController: ViewController { self?.nextPressed() } - loadServerCountryCodes(accountManager: sharedContext.accountManager, network: account.network, completion: { [weak self] in + loadServerCountryCodes(accountManager: sharedContext.accountManager, engine: TelegramEngineUnauthorized(account: self.account), completion: { [weak self] in if let strongSelf = self { strongSelf.controllerNode.updateCountryCode() } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index a8b79da018..57b01bc1d3 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -829,7 +829,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G break } } - let _ = combineLatest(queue: .mainQueue(), contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState: strongSelf.presentationInterfaceState, context: strongSelf.context, messages: updatedMessages, controllerInteraction: strongSelf.controllerInteraction, selectAll: selectAll, interfaceInteraction: strongSelf.interfaceInteraction), loadedStickerPack(postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, reference: .animatedEmoji, forceActualized: false), ApplicationSpecificNotice.getChatTextSelectionTips(accountManager: strongSelf.context.sharedContext.accountManager) + let _ = combineLatest(queue: .mainQueue(), contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState: strongSelf.presentationInterfaceState, context: strongSelf.context, messages: updatedMessages, controllerInteraction: strongSelf.controllerInteraction, selectAll: selectAll, interfaceInteraction: strongSelf.interfaceInteraction), strongSelf.context.engine.stickers.loadedStickerPack(reference: .animatedEmoji, forceActualized: false), ApplicationSpecificNotice.getChatTextSelectionTips(accountManager: strongSelf.context.sharedContext.accountManager) ).start(next: { actions, animatedEmojiStickers, chatTextSelectionTips in guard let strongSelf = self, !actions.isEmpty else { return @@ -6144,7 +6144,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G |> switchToLatest |> deliverOnMainQueue).start(next: { [weak self] added in if let strongSelf = self { - strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .sticker(account: strongSelf.context.account, file: stickerFile, text: added ? strongSelf.presentationData.strings.Conversation_StickerAddedToFavorites : strongSelf.presentationData.strings.Conversation_StickerRemovedFromFavorites), elevatedLayout: false, action: { _ in return false }), in: .current) + strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .sticker(context: strongSelf.context, file: stickerFile, text: added ? strongSelf.presentationData.strings.Conversation_StickerAddedToFavorites : strongSelf.presentationData.strings.Conversation_StickerRemovedFromFavorites), elevatedLayout: false, action: { _ in return false }), in: .current) } }) } @@ -9436,7 +9436,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } if let value = value { - self.present(UndoOverlayController(presentationData: self.presentationData, content: .dice(dice: dice, account: self.context.account, text: value, action: canSendMessagesToChat(self.presentationInterfaceState) ? self.presentationData.strings.Conversation_SendDice : nil), elevatedLayout: false, action: { [weak self] action in + self.present(UndoOverlayController(presentationData: self.presentationData, content: .dice(dice: dice, context: self.context, text: value, action: canSendMessagesToChat(self.presentationInterfaceState) ? self.presentationData.strings.Conversation_SendDice : nil), elevatedLayout: false, action: { [weak self] action in if let strongSelf = self, canSendMessagesToChat(strongSelf.presentationInterfaceState), action == .undo { strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: AnyMediaReference.standalone(media: TelegramMediaDice(emoji: dice.emoji)), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]) } diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 24aafe741c..b987887b6a 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -729,7 +729,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { private func updateIsEmpty(_ emptyType: ChatHistoryNodeLoadState.EmptyType?, animated: Bool) { self.emptyType = emptyType if let emptyType = emptyType, self.emptyNode == nil { - let emptyNode = ChatEmptyNode(account: self.context.account, interaction: self.interfaceInteraction) + let emptyNode = ChatEmptyNode(context: self.context, interaction: self.interfaceInteraction) if let (size, insets) = self.validEmptyNodeLayout { emptyNode.updateLayout(interfaceState: self.chatPresentationInterfaceState, emptyType: emptyType, size: size, insets: insets, transition: .immediate) } diff --git a/submodules/TelegramUI/Sources/ChatEmptyNode.swift b/submodules/TelegramUI/Sources/ChatEmptyNode.swift index 76bf2723ba..18976ae21f 100644 --- a/submodules/TelegramUI/Sources/ChatEmptyNode.swift +++ b/submodules/TelegramUI/Sources/ChatEmptyNode.swift @@ -10,6 +10,7 @@ import TelegramPresentationData import AppBundle import LocalizedPeerData import TelegramStringFormatting +import AccountContext private protocol ChatEmptyNodeContent { func updateLayout(interfaceState: ChatPresentationInterfaceState, size: CGSize, transition: ContainedViewLayoutTransition) -> CGSize @@ -67,7 +68,7 @@ private final class ChatEmptyNodeRegularChatContent: ASDisplayNode, ChatEmptyNod } private final class ChatEmptyNodeGreetingChatContent: ASDisplayNode, ChatEmptyNodeContent, UIGestureRecognizerDelegate { - private let account: Account + private let context: AccountContext private let interaction: ChatPanelInterfaceInteraction? private let titleNode: ImmediateTextNode @@ -92,8 +93,8 @@ private final class ChatEmptyNodeGreetingChatContent: ASDisplayNode, ChatEmptyNo } } - init(account: Account, interaction: ChatPanelInterfaceInteraction?) { - self.account = account + init(context: AccountContext, interaction: ChatPanelInterfaceInteraction?) { + self.context = context self.interaction = interaction self.titleNode = ImmediateTextNode() @@ -162,7 +163,7 @@ private final class ChatEmptyNodeGreetingChatContent: ASDisplayNode, ChatEmptyNo if let preloadedSticker = interfaceState.greetingData?.sticker { sticker = .single(preloadedSticker) } else { - sticker = randomGreetingSticker(account: self.account) + sticker = self.context.engine.stickers.randomGreetingSticker() |> map { item -> TelegramMediaFile? in return item?.file } @@ -195,7 +196,7 @@ private final class ChatEmptyNodeGreetingChatContent: ASDisplayNode, ChatEmptyNo let index = ItemCollectionItemIndex(index: 0, id: 0) let collectionId = ItemCollectionId(namespace: 0, id: 0) let stickerPackItem = StickerPackItem(index: index, file: sticker, indexKeys: []) - let item = ChatMediaInputStickerGridItem(account: strongSelf.account, collectionId: collectionId, stickerPackInfo: nil, index: ItemCollectionViewEntryIndex(collectionIndex: 0, collectionId: collectionId, itemIndex: index), stickerItem: stickerPackItem, canManagePeerSpecificPack: nil, interfaceInteraction: nil, inputNodeInteraction: inputNodeInteraction, hasAccessory: false, theme: interfaceState.theme, large: true, selected: {}) + let item = ChatMediaInputStickerGridItem(account: strongSelf.context.account, collectionId: collectionId, stickerPackInfo: nil, index: ItemCollectionViewEntryIndex(collectionIndex: 0, collectionId: collectionId, itemIndex: index), stickerItem: stickerPackItem, canManagePeerSpecificPack: nil, interfaceInteraction: nil, inputNodeInteraction: inputNodeInteraction, hasAccessory: false, theme: interfaceState.theme, large: true, selected: {}) strongSelf.stickerItem = item strongSelf.stickerNode.updateLayout(item: item, size: stickerSize, isVisible: true, synchronousLoads: true) strongSelf.stickerNode.isVisibleInGrid = true @@ -234,7 +235,7 @@ private final class ChatEmptyNodeGreetingChatContent: ASDisplayNode, ChatEmptyNo } private final class ChatEmptyNodeNearbyChatContent: ASDisplayNode, ChatEmptyNodeContent, UIGestureRecognizerDelegate { - private let account: Account + private let context: AccountContext private let interaction: ChatPanelInterfaceInteraction? private let titleNode: ImmediateTextNode @@ -259,8 +260,8 @@ private final class ChatEmptyNodeNearbyChatContent: ASDisplayNode, ChatEmptyNode } } - init(account: Account, interaction: ChatPanelInterfaceInteraction?) { - self.account = account + init(context: AccountContext, interaction: ChatPanelInterfaceInteraction?) { + self.context = context self.interaction = interaction self.titleNode = ImmediateTextNode() @@ -339,7 +340,7 @@ private final class ChatEmptyNodeNearbyChatContent: ASDisplayNode, ChatEmptyNode if let preloadedSticker = interfaceState.greetingData?.sticker { sticker = .single(preloadedSticker) } else { - sticker = randomGreetingSticker(account: self.account) + sticker = self.context.engine.stickers.randomGreetingSticker() |> map { item -> TelegramMediaFile? in return item?.file } @@ -372,7 +373,7 @@ private final class ChatEmptyNodeNearbyChatContent: ASDisplayNode, ChatEmptyNode let index = ItemCollectionItemIndex(index: 0, id: 0) let collectionId = ItemCollectionId(namespace: 0, id: 0) let stickerPackItem = StickerPackItem(index: index, file: sticker, indexKeys: []) - let item = ChatMediaInputStickerGridItem(account: strongSelf.account, collectionId: collectionId, stickerPackInfo: nil, index: ItemCollectionViewEntryIndex(collectionIndex: 0, collectionId: collectionId, itemIndex: index), stickerItem: stickerPackItem, canManagePeerSpecificPack: nil, interfaceInteraction: nil, inputNodeInteraction: inputNodeInteraction, hasAccessory: false, theme: interfaceState.theme, large: true, selected: {}) + let item = ChatMediaInputStickerGridItem(account: strongSelf.context.account, collectionId: collectionId, stickerPackInfo: nil, index: ItemCollectionViewEntryIndex(collectionIndex: 0, collectionId: collectionId, itemIndex: index), stickerItem: stickerPackItem, canManagePeerSpecificPack: nil, interfaceInteraction: nil, inputNodeInteraction: inputNodeInteraction, hasAccessory: false, theme: interfaceState.theme, large: true, selected: {}) strongSelf.stickerItem = item strongSelf.stickerNode.updateLayout(item: item, size: stickerSize, isVisible: true, synchronousLoads: true) strongSelf.stickerNode.isVisibleInGrid = true @@ -783,7 +784,7 @@ private enum ChatEmptyNodeContentType { } final class ChatEmptyNode: ASDisplayNode { - private let account: Account + private let context: AccountContext private let interaction: ChatPanelInterfaceInteraction? private let backgroundNode: ASImageNode @@ -793,8 +794,8 @@ final class ChatEmptyNode: ASDisplayNode { private var content: (ChatEmptyNodeContentType, ASDisplayNode & ChatEmptyNodeContent)? - init(account: Account, interaction: ChatPanelInterfaceInteraction?) { - self.account = account + init(context: AccountContext, interaction: ChatPanelInterfaceInteraction?) { + self.context = context self.interaction = interaction self.backgroundNode = ASImageNode() @@ -827,7 +828,7 @@ final class ChatEmptyNode: ASDisplayNode { if case .replyThread = interfaceState.chatLocation { contentType = .regular } else if let peer = interfaceState.renderedPeer?.peer, !isScheduledMessages { - if peer.id == self.account.peerId { + if peer.id == self.context.account.peerId { contentType = .cloud } else if let _ = peer as? TelegramSecretChat { contentType = .secret @@ -872,9 +873,9 @@ final class ChatEmptyNode: ASDisplayNode { case .cloud: node = ChatEmptyNodeCloudChatContent() case .peerNearby: - node = ChatEmptyNodeNearbyChatContent(account: self.account, interaction: self.interaction) + node = ChatEmptyNodeNearbyChatContent(context: self.context, interaction: self.interaction) case .greeting: - node = ChatEmptyNodeGreetingChatContent(account: self.account, interaction: self.interaction) + node = ChatEmptyNodeGreetingChatContent(context: self.context, interaction: self.interaction) } self.content = (contentType, node) self.addSubnode(node) diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index 7cbaa46064..df6b000234 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -790,7 +790,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { } |> distinctUntilChanged - let animatedEmojiStickers = loadedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: .animatedEmoji, forceActualized: false) + let animatedEmojiStickers = context.engine.stickers.loadedStickerPack(reference: .animatedEmoji, forceActualized: false) |> map { animatedEmoji -> [String: [StickerPackItem]] in var animatedEmojiStickers: [String: [StickerPackItem]] = [:] switch animatedEmoji { diff --git a/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift b/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift index 247c66f51f..bd0f80f701 100644 --- a/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift +++ b/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift @@ -127,7 +127,7 @@ private func updatedContextQueryResultStateForQuery(context: AccountContext, pee case .installed: scope = [.installed] } - return searchStickers(account: context.account, query: query.basicEmoji.0, scope: scope) + return context.engine.stickers.searchStickers(query: query.basicEmoji.0, scope: scope) |> castError(ChatContextQueryError.self) } |> map { stickers -> (ChatPresentationInputQueryResult?) -> ChatPresentationInputQueryResult? in @@ -338,13 +338,13 @@ private func updatedContextQueryResultStateForQuery(context: AccountContext, pee return signal |> then(contextBot) case let .emojiSearch(query, languageCode, range): - var signal = searchEmojiKeywords(postbox: context.account.postbox, inputLanguageCode: languageCode, query: query, completeMatch: query.count < 2) + var signal = context.engine.stickers.searchEmojiKeywords(inputLanguageCode: languageCode, query: query, completeMatch: query.count < 2) if !languageCode.lowercased().hasPrefix("en") { signal = signal |> mapToSignal { keywords in return .single(keywords) |> then( - searchEmojiKeywords(postbox: context.account.postbox, inputLanguageCode: "en-US", query: query, completeMatch: query.count < 3) + context.engine.stickers.searchEmojiKeywords(inputLanguageCode: "en-US", query: query, completeMatch: query.count < 3) |> map { englishKeywords in return keywords + englishKeywords } diff --git a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift index 1b578216d4..918ba77da0 100644 --- a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift +++ b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift @@ -783,14 +783,14 @@ final class ChatMediaInputNode: ChatInputNode { guard let strongSelf = self, let info = info as? StickerPackCollectionInfo else { return } - let _ = (loadedStickerPack(postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) + let _ = (context.engine.stickers.loadedStickerPack(reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) |> mapToSignal { result -> Signal in switch result { case let .result(info, items, installed): if installed { return .complete() } else { - return addStickerPackInteractively(postbox: strongSelf.context.account.postbox, info: info, items: items) + return context.engine.stickers.addStickerPackInteractively(info: info, items: items) } case .fetching: break diff --git a/submodules/TelegramUI/Sources/ChatMediaInputTrendingPane.swift b/submodules/TelegramUI/Sources/ChatMediaInputTrendingPane.swift index dd111fbed5..d8b37e863b 100644 --- a/submodules/TelegramUI/Sources/ChatMediaInputTrendingPane.swift +++ b/submodules/TelegramUI/Sources/ChatMediaInputTrendingPane.swift @@ -245,23 +245,22 @@ final class ChatMediaInputTrendingPane: ChatMediaInputPane { let interaction = TrendingPaneInteraction(installPack: { [weak self] info in if let strongSelf = self, let info = info as? StickerPackCollectionInfo { - let account = strongSelf.context.account - var installSignal = loadedStickerPack(postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) + let context = strongSelf.context + var installSignal = context.engine.stickers.loadedStickerPack(reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) |> mapToSignal { result -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem]), NoError> in switch result { case let .result(info, items, installed): if installed { return .complete() } else { - return preloadedStickerPackThumbnail(account: account, info: info, items: items) + return preloadedStickerPackThumbnail(account: context.account, info: info, items: items) |> filter { $0 } |> ignoreValues |> then( - addStickerPackInteractively(postbox: strongSelf.context.account.postbox, info: info, items: items) + context.engine.stickers.addStickerPackInteractively(info: info, items: items) |> ignoreValues ) |> mapToSignal { _ -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem]), NoError> in - return .complete() } |> then(.single((info, items))) } @@ -273,8 +272,7 @@ final class ChatMediaInputTrendingPane: ChatMediaInputPane { return .complete() } |> deliverOnMainQueue - - let context = strongSelf.context + var cancelImpl: (() -> Void)? let progressSignal = Signal { subscriber in let presentationData = context.sharedContext.currentPresentationData.with { $0 } @@ -318,7 +316,7 @@ final class ChatMediaInputTrendingPane: ChatMediaInputPane { } let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } - strongSelf.controllerInteraction.navigationController()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, account: strongSelf.context.account), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { _ in + strongSelf.controllerInteraction.navigationController()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, context: strongSelf.context), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { _ in return true })) })) diff --git a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift index a91b68606a..c310d8f781 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift @@ -679,7 +679,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode func animateReplyPanel(sourceReplyPanel: ChatMessageTransitionNode.ReplyPanel, transition: ContainedViewLayoutTransition) { if let replyInfoNode = self.replyInfoNode { let localRect = self.mainContextSourceNode.contentNode.view.convert(sourceReplyPanel.relativeSourceRect, to: replyInfoNode.view) - replyInfoNode.animateFromInputPanel(sourceReplyPanel: sourceReplyPanel, localRect: localRect, transition: transition) + let _ = replyInfoNode.animateFromInputPanel(sourceReplyPanel: sourceReplyPanel, localRect: localRect, transition: transition) } } diff --git a/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift index 9188c4a238..0fc5da0fe8 100644 --- a/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift @@ -644,10 +644,10 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode { func animateFrom(sourceView: UIView, widthDifference: CGFloat, transition: ContainedViewLayoutTransition) { self.view.addSubview(sourceView) - sourceView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false, completion: { [weak sourceView] _ in + sourceView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.1, removeOnCompletion: false, completion: { [weak sourceView] _ in sourceView?.removeFromSuperview() }) - self.textNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) + self.textNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.08) let offset = CGPoint( x: sourceView.frame.minX - (self.textNode.frame.minX - 0.0), diff --git a/submodules/TelegramUI/Sources/EmojiResources.swift b/submodules/TelegramUI/Sources/EmojiResources.swift index 730c085b42..4396a939f9 100644 --- a/submodules/TelegramUI/Sources/EmojiResources.swift +++ b/submodules/TelegramUI/Sources/EmojiResources.swift @@ -9,6 +9,7 @@ import WebPBinding import MediaResources import Emoji import AppBundle +import AccountContext public struct EmojiThumbnailResourceId: MediaResourceId { public let emoji: String @@ -284,17 +285,17 @@ private final class Buffer { var data = Data() } -func fetchEmojiSpriteResource(postbox: Postbox, network: Network, resource: EmojiSpriteResource) -> Signal { +func fetchEmojiSpriteResource(account: Account, resource: EmojiSpriteResource) -> Signal { let packName = "P\(resource.packId)_by_AEStickerBot" - return loadedStickerPack(postbox: postbox, network: network, reference: .name(packName), forceActualized: false) + return TelegramEngine(account: account).stickers.loadedStickerPack(reference: .name(packName), forceActualized: false) |> castError(MediaResourceDataFetchError.self) |> mapToSignal { result -> Signal in switch result { case let .result(_, items, _): if let sticker = items[Int(resource.stickerId)] as? StickerPackItem { return Signal { subscriber in - guard let fetchResource = postbox.mediaBox.fetchResource else { + guard let fetchResource = account.postbox.mediaBox.fetchResource else { return EmptyDisposable } diff --git a/submodules/TelegramUI/Sources/FeaturedStickersScreen.swift b/submodules/TelegramUI/Sources/FeaturedStickersScreen.swift index 44b44075f2..b6a8681938 100644 --- a/submodules/TelegramUI/Sources/FeaturedStickersScreen.swift +++ b/submodules/TelegramUI/Sources/FeaturedStickersScreen.swift @@ -258,7 +258,7 @@ private final class FeaturedStickersScreenNode: ViewControllerTracingNode { } } if !addedRead.isEmpty { - let _ = markFeaturedStickerPacksAsSeenInteractively(postbox: strongSelf.context.account.postbox, ids: addedRead).start() + let _ = strongSelf.context.engine.stickers.markFeaturedStickerPacksAsSeenInteractively(ids: addedRead).start() } if bottomIndex >= strongSelf.gridNode.items.count - 15 { @@ -295,84 +295,9 @@ private final class FeaturedStickersScreenNode: ViewControllerTracingNode { } let account = strongSelf.context.account if install { - let _ = addStickerPackInteractively(postbox: strongSelf.context.account.postbox, info: info, items: []).start() - /*var installSignal = loadedStickerPack(postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) - |> mapToSignal { result -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem]), NoError> in - switch result { - case let .result(info, items, installed): - if installed { - return .complete() - } else { - return preloadedStickerPackThumbnail(account: account, info: info, items: items) - |> filter { $0 } - |> ignoreValues - |> then( - addStickerPackInteractively(postbox: strongSelf.context.account.postbox, info: info, items: items) - |> ignoreValues - ) - |> mapToSignal { _ -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem]), NoError> in - } - |> then(.single((info, items))) - } - case .fetching: - break - case .none: - break - } - return .complete() - } - |> deliverOnMainQueue - - let context = strongSelf.context - var cancelImpl: (() -> Void)? - let progressSignal = Signal { subscriber in - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: { - cancelImpl?() - })) - self?.controller?.present(controller, in: .window(.root)) - return ActionDisposable { [weak controller] in - Queue.mainQueue().async() { - controller?.dismiss() - } - } - } - |> runOn(Queue.mainQueue()) - |> delay(1.0, queue: Queue.mainQueue()) - let progressDisposable = progressSignal.start() - - installSignal = installSignal - |> afterDisposed { - Queue.mainQueue().async { - progressDisposable.dispose() - } - } - cancelImpl = { - self?.installDisposable.set(nil) - } - - strongSelf.installDisposable.set(installSignal.start(next: { info, items in - guard let strongSelf = self else { - return - } - - /*var animateInAsReplacement = false - if let navigationController = strongSelf.controllerInteraction.navigationController() { - for controller in navigationController.overlayControllers { - if let controller = controller as? UndoOverlayController { - controller.dismissWithCommitActionAndReplacementAnimation() - animateInAsReplacement = true - } - } - } - - let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } - strongSelf.controllerInteraction.navigationController()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, account: strongSelf.context.account), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { _ in - return true - }))*/ - }))*/ + let _ = strongSelf.context.engine.stickers.addStickerPackInteractively(info: info, items: []).start() } else { - let _ = (removeStickerPackInteractively(postbox: account.postbox, id: info.id, option: .delete) + let _ = (strongSelf.context.engine.stickers.removeStickerPackInteractively(id: info.id, option: .delete) |> deliverOnMainQueue).start(next: { _ in }) } @@ -1165,85 +1090,9 @@ private final class FeaturedPaneSearchContentNode: ASDisplayNode { } let account = strongSelf.context.account if install { - let _ = addStickerPackInteractively(postbox: strongSelf.context.account.postbox, info: info, items: []).start() - /*var installSignal = loadedStickerPack(postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) - |> mapToSignal { result -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem]), NoError> in - switch result { - case let .result(info, items, installed): - if installed { - return .complete() - } else { - return preloadedStickerPackThumbnail(account: account, info: info, items: items) - |> filter { $0 } - |> ignoreValues - |> then( - addStickerPackInteractively(postbox: strongSelf.context.account.postbox, info: info, items: items) - |> ignoreValues - ) - |> mapToSignal { _ -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem]), NoError> in - return .complete() - } - |> then(.single((info, items))) - } - case .fetching: - break - case .none: - break - } - return .complete() - } - |> deliverOnMainQueue - - let context = strongSelf.context - var cancelImpl: (() -> Void)? - let progressSignal = Signal { subscriber in - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: { - cancelImpl?() - })) - self?.controller?.present(controller, in: .window(.root)) - return ActionDisposable { [weak controller] in - Queue.mainQueue().async() { - controller?.dismiss() - } - } - } - |> runOn(Queue.mainQueue()) - |> delay(0.12, queue: Queue.mainQueue()) - let progressDisposable = progressSignal.start() - - installSignal = installSignal - |> afterDisposed { - Queue.mainQueue().async { - progressDisposable.dispose() - } - } - cancelImpl = { - self?.installDisposable.set(nil) - } - - strongSelf.installDisposable.set(installSignal.start(next: { info, items in - guard let strongSelf = self else { - return - } - - var animateInAsReplacement = false - if let navigationController = strongSelf.controller?.navigationController as? NavigationController { - for controller in navigationController.overlayControllers { - if let controller = controller as? UndoOverlayController { - controller.dismissWithCommitActionAndReplacementAnimation() - animateInAsReplacement = true - } - } - } - - let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } - /*strongSelf.controllerInteraction.navigationController()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, account: strongSelf.context.account), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { _ in - return true - }))*/ - }))*/ + let _ = strongSelf.context.engine.stickers.addStickerPackInteractively(info: info, items: []).start() } else { - let _ = (removeStickerPackInteractively(postbox: account.postbox, id: info.id, option: .delete) + let _ = (strongSelf.context.engine.stickers.removeStickerPackInteractively(id: info.id, option: .delete) |> deliverOnMainQueue).start(next: { _ in }) } @@ -1268,22 +1117,22 @@ private final class FeaturedPaneSearchContentNode: ASDisplayNode { func updateText(_ text: String, languageCode: String?) { let signal: Signal<([(String?, FoundStickerItem)], FoundStickerSets, Bool, FoundStickerSets?)?, NoError> if !text.isEmpty { - let account = self.context.account + let context = self.context let stickers: Signal<[(String?, FoundStickerItem)], NoError> = Signal { subscriber in var signals: Signal<[Signal<(String?, [FoundStickerItem]), NoError>], NoError> = .single([]) let query = text.trimmingCharacters(in: .whitespacesAndNewlines) if query.isSingleEmoji { - signals = .single([searchStickers(account: account, query: text.basicEmoji.0) + signals = .single([context.engine.stickers.searchStickers(query: text.basicEmoji.0) |> map { (nil, $0) }]) } else if query.count > 1, let languageCode = languageCode, !languageCode.isEmpty && languageCode != "emoji" { - var signal = searchEmojiKeywords(postbox: account.postbox, inputLanguageCode: languageCode, query: query.lowercased(), completeMatch: query.count < 3) + var signal = context.engine.stickers.searchEmojiKeywords(inputLanguageCode: languageCode, query: query.lowercased(), completeMatch: query.count < 3) if !languageCode.lowercased().hasPrefix("en") { signal = signal |> mapToSignal { keywords in return .single(keywords) |> then( - searchEmojiKeywords(postbox: account.postbox, inputLanguageCode: "en-US", query: query.lowercased(), completeMatch: query.count < 3) + context.engine.stickers.searchEmojiKeywords(inputLanguageCode: "en-US", query: query.lowercased(), completeMatch: query.count < 3) |> map { englishKeywords in return keywords + englishKeywords } @@ -1296,7 +1145,7 @@ private final class FeaturedPaneSearchContentNode: ASDisplayNode { var signals: [Signal<(String?, [FoundStickerItem]), NoError>] = [] let emoticons = keywords.flatMap { $0.emoticons } for emoji in emoticons { - signals.append(searchStickers(account: self.context.account, query: emoji.basicEmoji.0) + signals.append(context.engine.stickers.searchStickers(query: emoji.basicEmoji.0) |> take(1) |> map { (emoji, $0) }) } @@ -1320,8 +1169,8 @@ private final class FeaturedPaneSearchContentNode: ASDisplayNode { }) } - let local = searchStickerSets(postbox: context.account.postbox, query: text) - let remote = searchStickerSetsRemotely(network: context.account.network, query: text) + let local = context.engine.stickers.searchStickerSets(query: text) + let remote = context.engine.stickers.searchStickerSetsRemotely(query: text) |> delay(0.2, queue: Queue.mainQueue()) let rawPacks = local |> mapToSignal { result -> Signal<(FoundStickerSets, Bool, FoundStickerSets?), NoError> in diff --git a/submodules/TelegramUI/Sources/ManagedDiceAnimationNode.swift b/submodules/TelegramUI/Sources/ManagedDiceAnimationNode.swift index add33bf816..6fb6235cb3 100644 --- a/submodules/TelegramUI/Sources/ManagedDiceAnimationNode.swift +++ b/submodules/TelegramUI/Sources/ManagedDiceAnimationNode.swift @@ -137,7 +137,7 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick let appConfiguration: AppConfiguration = preferencesView.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue return InteractiveEmojiConfiguration.with(appConfiguration: appConfiguration) }) - self.emojis.set(loadedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: .dice(emoji), forceActualized: false) + self.emojis.set(context.engine.stickers.loadedStickerPack(reference: .dice(emoji), forceActualized: false) |> mapToSignal { stickerPack -> Signal<[TelegramMediaFile], NoError> in switch stickerPack { case let .result(_, items, _): diff --git a/submodules/TelegramUI/Sources/OpenChatMessage.swift b/submodules/TelegramUI/Sources/OpenChatMessage.swift index 87d8774376..01809d3e85 100644 --- a/submodules/TelegramUI/Sources/OpenChatMessage.swift +++ b/submodules/TelegramUI/Sources/OpenChatMessage.swift @@ -92,13 +92,13 @@ func openChatMessageImpl(_ params: OpenChatMessageParams) -> Bool { } switch action { case .add: - params.navigationController?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, account: params.context.account), elevatedLayout: true, animateInAsReplacement: animateInAsReplacement, action: { _ in + params.navigationController?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, context: params.context), elevatedLayout: true, animateInAsReplacement: animateInAsReplacement, action: { _ in return true })) case let .remove(positionInList): - params.navigationController?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_RemovedTitle, text: presentationData.strings.StickerPackActionInfo_RemovedText(info.title).0, undo: true, info: info, topItem: items.first, account: params.context.account), elevatedLayout: true, animateInAsReplacement: animateInAsReplacement, action: { action in + params.navigationController?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_RemovedTitle, text: presentationData.strings.StickerPackActionInfo_RemovedText(info.title).0, undo: true, info: info, topItem: items.first, context: params.context), elevatedLayout: true, animateInAsReplacement: animateInAsReplacement, action: { action in if case .undo = action { - let _ = addStickerPackInteractively(postbox: params.context.account.postbox, info: info, items: items, positionInList: positionInList).start() + let _ = params.context.engine.stickers.addStickerPackInteractively(info: info, items: items, positionInList: positionInList).start() } return true })) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 5eaa752756..0b3e65b2d6 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -2733,7 +2733,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD |> map(Optional.init) )) self.privacySettings.set(.single(nil) |> then(requestAccountPrivacySettings(account: context.account) |> map(Optional.init))) - self.archivedPacks.set(.single(nil) |> then(archivedStickerPacks(account: context.account) |> map(Optional.init))) + self.archivedPacks.set(.single(nil) |> then(context.engine.stickers.archivedStickerPacks() |> map(Optional.init))) self.hasPassport.set(.single(false) |> then(twoStepAuthData(context.account.network) |> map { value -> Bool in return value.hasSecretValues @@ -2834,7 +2834,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD self.preloadHistoryDisposable.set(self.context.account.addAdditionalPreloadHistoryPeerId(peerId: peerId)) self.preloadedSticker.set(.single(nil) - |> then(randomGreetingSticker(account: context.account) + |> then(context.engine.stickers.randomGreetingSticker() |> map { item in return item?.file })) diff --git a/submodules/TelegramUI/Sources/PrefetchManager.swift b/submodules/TelegramUI/Sources/PrefetchManager.swift index c91153056f..9ea80fb61b 100644 --- a/submodules/TelegramUI/Sources/PrefetchManager.swift +++ b/submodules/TelegramUI/Sources/PrefetchManager.swift @@ -52,7 +52,7 @@ private final class PrefetchManagerImpl { return view.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue } - let orderedPreloadMedia = combineLatest(account.viewTracker.orderedPreloadMedia, loadedStickerPack(postbox: account.postbox, network: account.network, reference: .animatedEmoji, forceActualized: false), appConfiguration) + let orderedPreloadMedia = combineLatest(account.viewTracker.orderedPreloadMedia, TelegramEngine(account: account).stickers.loadedStickerPack(reference: .animatedEmoji, forceActualized: false), appConfiguration) |> map { orderedPreloadMedia, stickerPack, appConfiguration -> [PrefetchMediaItem] in let emojiSounds = AnimatedEmojiSoundsConfiguration.with(appConfiguration: appConfiguration, account: account) let chatHistoryMediaItems = orderedPreloadMedia.map { PrefetchMediaItem.chatHistory($0) } diff --git a/submodules/TelegramUI/Sources/StickerPaneSearchContentNode.swift b/submodules/TelegramUI/Sources/StickerPaneSearchContentNode.swift index 6f585cf323..14c25e6392 100644 --- a/submodules/TelegramUI/Sources/StickerPaneSearchContentNode.swift +++ b/submodules/TelegramUI/Sources/StickerPaneSearchContentNode.swift @@ -238,24 +238,23 @@ final class StickerPaneSearchContentNode: ASDisplayNode, PaneSearchContentNode { guard let strongSelf = self else { return } - let account = strongSelf.context.account + let context = strongSelf.context if install { - var installSignal = loadedStickerPack(postbox: strongSelf.context.account.postbox, network: strongSelf.context.account.network, reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) + var installSignal = strongSelf.context.engine.stickers.loadedStickerPack(reference: .id(id: info.id.id, accessHash: info.accessHash), forceActualized: false) |> mapToSignal { result -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem]), NoError> in switch result { case let .result(info, items, installed): if installed { return .complete() } else { - return preloadedStickerPackThumbnail(account: account, info: info, items: items) + return preloadedStickerPackThumbnail(account: context.account, info: info, items: items) |> filter { $0 } |> ignoreValues |> then( - addStickerPackInteractively(postbox: strongSelf.context.account.postbox, info: info, items: items) + context.engine.stickers.addStickerPackInteractively(info: info, items: items) |> ignoreValues ) |> mapToSignal { _ -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem]), NoError> in - return .complete() } |> then(.single((info, items))) } @@ -312,12 +311,12 @@ final class StickerPaneSearchContentNode: ASDisplayNode, PaneSearchContentNode { } let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } - strongSelf.controllerInteraction.navigationController()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, account: strongSelf.context.account), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { _ in + strongSelf.controllerInteraction.navigationController()?.presentOverlay(controller: UndoOverlayController(presentationData: presentationData, content: .stickersModified(title: presentationData.strings.StickerPackActionInfo_AddedTitle, text: presentationData.strings.StickerPackActionInfo_AddedText(info.title).0, undo: false, info: info, topItem: items.first, context: strongSelf.context), elevatedLayout: false, animateInAsReplacement: animateInAsReplacement, action: { _ in return true })) })) } else { - let _ = (removeStickerPackInteractively(postbox: account.postbox, id: info.id, option: .delete) + let _ = (context.engine.stickers.removeStickerPackInteractively(id: info.id, option: .delete) |> deliverOnMainQueue).start(next: { _ in }) } @@ -343,22 +342,22 @@ final class StickerPaneSearchContentNode: ASDisplayNode, PaneSearchContentNode { func updateText(_ text: String, languageCode: String?) { let signal: Signal<([(String?, FoundStickerItem)], FoundStickerSets, Bool, FoundStickerSets?)?, NoError> if !text.isEmpty { - let account = self.context.account + let context = self.context let stickers: Signal<[(String?, FoundStickerItem)], NoError> = Signal { subscriber in var signals: Signal<[Signal<(String?, [FoundStickerItem]), NoError>], NoError> = .single([]) let query = text.trimmingCharacters(in: .whitespacesAndNewlines) if query.isSingleEmoji { - signals = .single([searchStickers(account: account, query: text.basicEmoji.0) + signals = .single([context.engine.stickers.searchStickers(query: text.basicEmoji.0) |> map { (nil, $0) }]) } else if query.count > 1, let languageCode = languageCode, !languageCode.isEmpty && languageCode != "emoji" { - var signal = searchEmojiKeywords(postbox: account.postbox, inputLanguageCode: languageCode, query: query.lowercased(), completeMatch: query.count < 3) + var signal = context.engine.stickers.searchEmojiKeywords(inputLanguageCode: languageCode, query: query.lowercased(), completeMatch: query.count < 3) if !languageCode.lowercased().hasPrefix("en") { signal = signal |> mapToSignal { keywords in return .single(keywords) |> then( - searchEmojiKeywords(postbox: account.postbox, inputLanguageCode: "en-US", query: query.lowercased(), completeMatch: query.count < 3) + context.engine.stickers.searchEmojiKeywords(inputLanguageCode: "en-US", query: query.lowercased(), completeMatch: query.count < 3) |> map { englishKeywords in return keywords + englishKeywords } @@ -371,7 +370,7 @@ final class StickerPaneSearchContentNode: ASDisplayNode, PaneSearchContentNode { var signals: [Signal<(String?, [FoundStickerItem]), NoError>] = [] let emoticons = keywords.flatMap { $0.emoticons } for emoji in emoticons { - signals.append(searchStickers(account: self.context.account, query: emoji.basicEmoji.0) + signals.append(context.engine.stickers.searchStickers(query: emoji.basicEmoji.0) |> take(1) |> map { (emoji, $0) }) } @@ -395,8 +394,8 @@ final class StickerPaneSearchContentNode: ASDisplayNode, PaneSearchContentNode { }) } - let local = searchStickerSets(postbox: context.account.postbox, query: text) - let remote = searchStickerSetsRemotely(network: context.account.network, query: text) + let local = context.engine.stickers.searchStickerSets(query: text) + let remote = context.engine.stickers.searchStickerSetsRemotely(query: text) |> delay(0.2, queue: Queue.mainQueue()) let rawPacks = local |> mapToSignal { result -> Signal<(FoundStickerSets, Bool, FoundStickerSets?), NoError> in diff --git a/submodules/TelegramUI/Sources/TelegramAccountAuxiliaryMethods.swift b/submodules/TelegramUI/Sources/TelegramAccountAuxiliaryMethods.swift index ecb2de7a00..1eced6852a 100644 --- a/submodules/TelegramUI/Sources/TelegramAccountAuxiliaryMethods.swift +++ b/submodules/TelegramUI/Sources/TelegramAccountAuxiliaryMethods.swift @@ -36,7 +36,7 @@ public let telegramAccountAuxiliaryMethods = AccountAuxiliaryMethods(updatePeerC } else if let resource = resource as? OpenInAppIconResource { return fetchOpenInAppIconResource(resource: resource) } else if let resource = resource as? EmojiSpriteResource { - return fetchEmojiSpriteResource(postbox: account.postbox, network: account.network, resource: resource) + return fetchEmojiSpriteResource(account: account, resource: resource) } else if let resource = resource as? VenueIconResource { return fetchVenueIconResource(account: account, resource: resource) } diff --git a/submodules/UndoUI/Sources/UndoOverlayController.swift b/submodules/UndoUI/Sources/UndoOverlayController.swift index 76d927a634..124e6d17a8 100644 --- a/submodules/UndoUI/Sources/UndoOverlayController.swift +++ b/submodules/UndoUI/Sources/UndoOverlayController.swift @@ -17,8 +17,8 @@ public enum UndoOverlayContent { case emoji(path: String, text: String) case swipeToReply(title: String, text: String) case actionSucceeded(title: String, text: String, cancel: String) - case stickersModified(title: String, text: String, undo: Bool, info: StickerPackCollectionInfo, topItem: ItemCollectionItem?, account: Account) - case dice(dice: TelegramMediaDice, account: Account, text: String, action: String?) + case stickersModified(title: String, text: String, undo: Bool, info: StickerPackCollectionInfo, topItem: ItemCollectionItem?, context: AccountContext) + case dice(dice: TelegramMediaDice, context: AccountContext, text: String, action: String?) case chatAddedToFolder(chatTitle: String, folderTitle: String) case chatRemovedFromFolder(chatTitle: String, folderTitle: String) case messagesUnpinned(title: String, text: String, undo: Bool, isHidden: Bool) @@ -35,7 +35,7 @@ public enum UndoOverlayContent { case voiceChatRecording(text: String) case voiceChatFlag(text: String) case voiceChatCanSpeak(text: String) - case sticker(account: Account, file: TelegramMediaFile, text: String) + case sticker(context: AccountContext, file: TelegramMediaFile, text: String) case copy(text: String) case mediaSaved(text: String) case paymentSent(currencyValue: String, itemTitle: String) diff --git a/submodules/UndoUI/Sources/UndoOverlayControllerNode.swift b/submodules/UndoUI/Sources/UndoOverlayControllerNode.swift index cc0f619c84..acd0e56a21 100644 --- a/submodules/UndoUI/Sources/UndoOverlayControllerNode.swift +++ b/submodules/UndoUI/Sources/UndoOverlayControllerNode.swift @@ -17,6 +17,7 @@ import SlotMachineAnimationNode import AnimationUI import StickerResources import AvatarNode +import AccountContext final class UndoOverlayControllerNode: ViewControllerTracingNode { private let elevatedLayout: Bool @@ -330,7 +331,7 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode { self.textNode.maximumNumberOfLines = 2 displayUndo = false self.originalRemainingSeconds = 5 - case let .stickersModified(title, text, undo, info, topItem, account): + case let .stickersModified(title, text, undo, info, topItem, context): self.avatarNode = nil self.iconNode = nil self.iconCheckNode = nil @@ -377,14 +378,14 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode { let stillImageSize = representation.dimensions.cgSize.aspectFitted(imageBoundingSize) self.stickerImageSize = stillImageSize - updatedImageSignal = chatMessageStickerPackThumbnail(postbox: account.postbox, resource: representation.resource) + updatedImageSignal = chatMessageStickerPackThumbnail(postbox: context.account.postbox, resource: representation.resource) case let .animated(resource): self.stickerImageSize = imageBoundingSize - updatedImageSignal = chatMessageStickerPackThumbnail(postbox: account.postbox, resource: resource, animated: true) + updatedImageSignal = chatMessageStickerPackThumbnail(postbox: context.account.postbox, resource: resource, animated: true) } if let resourceReference = resourceReference { - updatedFetchSignal = fetchedMediaResource(mediaBox: account.postbox.mediaBox, reference: resourceReference) + updatedFetchSignal = fetchedMediaResource(mediaBox: context.account.postbox.mediaBox, reference: resourceReference) } } else { updatedImageSignal = .single({ _ in return nil }) @@ -415,10 +416,10 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode { case let .animated(resource): let animatedStickerNode = AnimatedStickerNode() self.animatedStickerNode = animatedStickerNode - animatedStickerNode.setup(source: AnimatedStickerResourceSource(account: account, resource: resource), width: 80, height: 80, mode: .cached) + animatedStickerNode.setup(source: AnimatedStickerResourceSource(account: context.account, resource: resource), width: 80, height: 80, mode: .cached) } } - case let .dice(dice, account, text, action): + case let .dice(dice, context, text, action): self.avatarNode = nil self.iconNode = nil self.iconCheckNode = nil @@ -458,14 +459,14 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode { let animatedStickerNode = AnimatedStickerNode() self.animatedStickerNode = animatedStickerNode - let _ = (loadedStickerPack(postbox: account.postbox, network: account.network, reference: .dice(dice.emoji), forceActualized: false) + let _ = (context.engine.stickers.loadedStickerPack(reference: .dice(dice.emoji), forceActualized: false) |> deliverOnMainQueue).start(next: { stickerPack in if let value = dice.value { switch stickerPack { case let .result(_, items, _): let item = items[Int(value)] if let item = item as? StickerPackItem { - animatedStickerNode.setup(source: AnimatedStickerResourceSource(account: account, resource: item.file.resource), width: 120, height: 120, playbackMode: .once, mode: .direct(cachePathPrefix: nil)) + animatedStickerNode.setup(source: AnimatedStickerResourceSource(account: context.account, resource: item.file.resource), width: 120, height: 120, playbackMode: .once, mode: .direct(cachePathPrefix: nil)) } default: break @@ -613,7 +614,7 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode { displayUndo = false self.originalRemainingSeconds = 3 - case let .sticker(account, file, text): + case let .sticker(context, file, text): self.avatarNode = nil self.iconNode = nil self.iconCheckNode = nil @@ -650,14 +651,14 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode { let stillImageSize = representation.dimensions.cgSize.aspectFitted(imageBoundingSize) self.stickerImageSize = stillImageSize - updatedImageSignal = chatMessageStickerPackThumbnail(postbox: account.postbox, resource: representation.resource) + updatedImageSignal = chatMessageStickerPackThumbnail(postbox: context.account.postbox, resource: representation.resource) case let .animated(resource): self.stickerImageSize = imageBoundingSize - updatedImageSignal = chatMessageStickerPackThumbnail(postbox: account.postbox, resource: resource, animated: true) + updatedImageSignal = chatMessageStickerPackThumbnail(postbox: context.account.postbox, resource: resource, animated: true) } if let resourceReference = resourceReference { - updatedFetchSignal = fetchedMediaResource(mediaBox: account.postbox.mediaBox, reference: resourceReference) + updatedFetchSignal = fetchedMediaResource(mediaBox: context.account.postbox.mediaBox, reference: resourceReference) } } else { updatedImageSignal = .single({ _ in return nil }) @@ -688,7 +689,7 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode { case let .animated(resource): let animatedStickerNode = AnimatedStickerNode() self.animatedStickerNode = animatedStickerNode - animatedStickerNode.setup(source: AnimatedStickerResourceSource(account: account, resource: resource), width: 80, height: 80, mode: .cached) + animatedStickerNode.setup(source: AnimatedStickerResourceSource(account: context.account, resource: resource), width: 80, height: 80, mode: .cached) } } case let .copy(text):