diff --git a/Telegram/NotificationService/Sources/NotificationService.swift b/Telegram/NotificationService/Sources/NotificationService.swift index a40754bca4..a63054d8e5 100644 --- a/Telegram/NotificationService/Sources/NotificationService.swift +++ b/Telegram/NotificationService/Sources/NotificationService.swift @@ -577,6 +577,31 @@ private struct NotificationContent: CustomStringConvertible { } } +private func getCurrentRenderedTotalUnreadCount(accountManager: AccountManager, postbox: Postbox) -> Signal<(Int32, RenderedTotalUnreadCountType), NoError> { + let counters = postbox.transaction { transaction -> ChatListTotalUnreadState in + return transaction.getTotalUnreadState(groupId: .root) + } + return combineLatest( + accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.inAppNotificationSettings]) + |> take(1), + counters + ) + |> map { sharedData, totalReadCounters -> (Int32, RenderedTotalUnreadCountType) in + let inAppSettings: InAppNotificationSettings + if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.inAppNotificationSettings]?.get(InAppNotificationSettings.self) { + inAppSettings = value + } else { + inAppSettings = .defaultSettings + } + let type: RenderedTotalUnreadCountType + switch inAppSettings.totalUnreadCountDisplayStyle { + case .filtered: + type = .filtered + } + return (totalReadCounters.count(for: inAppSettings.totalUnreadCountDisplayStyle.category, in: inAppSettings.totalUnreadCountDisplayCategory.statsType, with: inAppSettings.totalUnreadCountIncludeTags), type) + } +} + @available(iOSApplicationExtension 10.0, iOS 10.0, *) private final class NotificationServiceHandler { private let queue: Queue diff --git a/submodules/DebugSettingsUI/Sources/DebugController.swift b/submodules/DebugSettingsUI/Sources/DebugController.swift index 51fa64d722..0de1fc679f 100644 --- a/submodules/DebugSettingsUI/Sources/DebugController.swift +++ b/submodules/DebugSettingsUI/Sources/DebugController.swift @@ -762,11 +762,10 @@ private enum DebugControllerEntry: ItemListNodeEntry { transaction.clearNotices() }).start() if let context = arguments.context { - let _ = (context.account.postbox.transaction { transaction -> Void in - transaction.clearItemCacheCollection(collectionId: Namespaces.CachedItemCollection.cachedPollResults) - - transaction.clearItemCacheCollection(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks) - }).start() + let _ = context.engine.itemCache.clear(collectionIds: [ + Namespaces.CachedItemCollection.cachedPollResults, + Namespaces.CachedItemCollection.cachedStickerPacks + ]).start() let _ = context.engine.peers.unmarkChatListFeaturedFiltersAsSeen() } @@ -846,12 +845,10 @@ private enum DebugControllerEntry: ItemListNodeEntry { let presentationData = arguments.sharedContext.currentPresentationData.with { $0 } let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) arguments.presentController(controller, nil) - let _ = (context.account.postbox.transaction { transaction -> Void in - transaction.addHolesEverywhere(peerNamespaces: [Namespaces.Peer.CloudUser, Namespaces.Peer.CloudGroup, Namespaces.Peer.CloudChannel], holeNamespace: Namespaces.Message.Cloud) - } - |> deliverOnMainQueue).start(completed: { - controller.dismiss() - }) + let _ = (context.engine.messages.debugAddHoles() + |> deliverOnMainQueue).start(completed: { + controller.dismiss() + }) }) case .reindexUnread: return ItemListActionItem(presentationData: presentationData, title: "Reindex Unread Counters", kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: { @@ -861,9 +858,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { let presentationData = arguments.sharedContext.currentPresentationData.with { $0 } let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) arguments.presentController(controller, nil) - let _ = (context.account.postbox.transaction { transaction -> Void in - transaction.reindexUnreadCounters() - } + let _ = (context.engine.messages.debugReindexUnreadCounters() |> deliverOnMainQueue).start(completed: { controller.dismiss() }) diff --git a/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift b/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift index d2372a841b..74598d3c98 100644 --- a/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift +++ b/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift @@ -389,11 +389,12 @@ final class LocalizationListControllerNode: ViewControllerTracingNode { } let removeItem: (String) -> Void = { id in - let _ = (context.account.postbox.transaction { transaction -> Signal in - removeSavedLocalization(transaction: transaction, languageCode: id) - let state = transaction.getPreferencesEntry(key: PreferencesKeys.localizationListState)?.get(LocalizationListState.self) + let _ = context.engine.localization.removeSavedLocalization(languageCode: id).start() + + let _ = (context.engine.data.get(TelegramEngine.EngineData.Item.Configuration.LocalizationList()) + |> mapToSignal { state -> Signal in return context.sharedContext.accountManager.transaction { transaction -> LocalizationInfo? in - if let settings = transaction.getSharedData(SharedDataKeys.localizationSettings)?.get(LocalizationSettings.self), let state = state { + if let settings = transaction.getSharedData(SharedDataKeys.localizationSettings)?.get(LocalizationSettings.self) { if settings.primaryComponent.languageCode == id { for item in state.availableOfficialLocalizations { if item.languageCode == "en" { @@ -405,7 +406,6 @@ final class LocalizationListControllerNode: ViewControllerTracingNode { return nil } } - |> switchToLatest |> deliverOnMainQueue).start(next: { [weak self] info in if revealedCodeValue == id { revealedCodeValue = nil diff --git a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift index a31f272c52..d9db23d840 100644 --- a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift @@ -1148,26 +1148,7 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta break } } - let _ = (context.account.postbox.transaction { transaction -> Void in - let infos = transaction.getItemCollectionsInfos(namespace: namespaceForMode(mode)) - - var packDict: [ItemCollectionId: Int] = [:] - for i in 0 ..< infos.count { - packDict[infos[i].0] = i - } - var tempSortedPacks: [(ItemCollectionId, ItemCollectionInfo)] = [] - var processedPacks = Set() - for id in currentIds { - if let index = packDict[id] { - tempSortedPacks.append(infos[index]) - processedPacks.insert(id) - } - } - let restPacks = infos.filter { !processedPacks.contains($0.0) } - let sortedPacks = restPacks + tempSortedPacks - addSynchronizeInstalledStickerPacksOperation(transaction: transaction, namespace: namespaceForMode(mode), content: .sync, noDelay: false) - transaction.replaceItemCollectionInfos(namespace: namespaceForMode(mode), itemCollectionInfos: sortedPacks) - } + let _ = (context.engine.stickers.reorderStickerPacks(namespace: namespaceForMode(mode), itemIds: currentIds) |> deliverOnMainQueue).start(completed: { temporaryPackOrder.set(.single(nil)) }) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift b/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift index 307023ceaf..357f3594b6 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift @@ -42,6 +42,13 @@ public extension TelegramEngineUnauthorized { public func uploadedPeerVideo(resource: MediaResource) -> Signal { return _internal_uploadedPeerVideo(postbox: self.account.postbox, network: self.account.network, messageMediaPreuploadManager: nil, resource: resource) } + + public func setState(state: UnauthorizedAccountState) -> Signal { + return self.account.postbox.transaction { transaction -> Void in + transaction.setState(state) + } + |> ignoreValues + } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Data/Configuration.swift b/submodules/TelegramCore/Sources/TelegramEngine/Data/Configuration.swift index 8f4b4cb205..a37d93e54f 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Data/Configuration.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Data/Configuration.swift @@ -333,5 +333,26 @@ public extension TelegramEngine.EngineData.Item { return EngineContentSettings(appConfiguration: appConfiguration) } } + + public struct LocalizationList: TelegramEngineDataItem, PostboxViewDataItem { + public typealias Result = LocalizationListState + + public init() { + } + + var key: PostboxViewKey { + return .preferences(keys: Set([PreferencesKeys.localizationListState])) + } + + func extract(view: PostboxView) -> Result { + guard let view = view as? PreferencesView else { + preconditionFailure() + } + guard let localizationListState = view.values[PreferencesKeys.localizationListState]?.get(LocalizationListState.self) else { + return LocalizationListState.defaultSettings + } + return localizationListState + } + } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/ItemCache/TelegramEngineItemCache.swift b/submodules/TelegramCore/Sources/TelegramEngine/ItemCache/TelegramEngineItemCache.swift index 8ca176672c..2ea4f81130 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/ItemCache/TelegramEngineItemCache.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/ItemCache/TelegramEngineItemCache.swift @@ -25,5 +25,14 @@ public extension TelegramEngine { } |> ignoreValues } + + public func clear(collectionIds: [Int8]) -> Signal { + return self.account.postbox.transaction { transaction -> Void in + for id in collectionIds { + transaction.clearItemCacheCollection(collectionId: id) + } + } + |> ignoreValues + } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationListState.swift b/submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationListState.swift index 49c29a186b..99dbcdd728 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationListState.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Localization/LocalizationListState.swift @@ -3,8 +3,7 @@ import Postbox import SwiftSignalKit import TelegramApi - -public func removeSavedLocalization(transaction: Transaction, languageCode: String) { +func _internal_removeSavedLocalization(transaction: Transaction, languageCode: String) { updateLocalizationListStateInteractively(transaction: transaction, { state in var state = state state.availableSavedLocalizations = state.availableSavedLocalizations.filter({ $0.languageCode != languageCode }) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift b/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift index f07e4a38d2..9095a39199 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Localization/TelegramEngineLocalization.swift @@ -32,6 +32,13 @@ public extension TelegramEngine { public func downloadAndApplyLocalization(accountManager: AccountManager, languageCode: String) -> Signal { return _internal_downloadAndApplyLocalization(accountManager: accountManager, postbox: self.account.postbox, network: self.account.network, languageCode: languageCode) } + + public func removeSavedLocalization(languageCode: String) -> Signal { + return self.account.postbox.transaction { transaction -> Void in + _internal_removeSavedLocalization(transaction: transaction, languageCode: languageCode) + } + |> ignoreValues + } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift index 7a6ec19451..fa3764d532 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -415,5 +415,19 @@ public extension TelegramEngine { } |> ignoreValues } + + public func debugAddHoles() -> Signal { + return self.account.postbox.transaction { transaction -> Void in + transaction.addHolesEverywhere(peerNamespaces: [Namespaces.Peer.CloudUser, Namespaces.Peer.CloudGroup, Namespaces.Peer.CloudChannel], holeNamespace: Namespaces.Message.Cloud) + } + |> ignoreValues + } + + public func debugReindexUnreadCounters() -> Signal { + return self.account.postbox.transaction { transaction -> Void in + transaction.reindexUnreadCounters() + } + |> ignoreValues + } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/TelegramEngineStickers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/TelegramEngineStickers.swift index f82e3afc7a..c064783ab5 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/TelegramEngineStickers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/TelegramEngineStickers.swift @@ -131,5 +131,29 @@ public extension TelegramEngine { } |> ignoreValues } + + public func reorderStickerPacks(namespace: ItemCollectionId.Namespace, itemIds: [ItemCollectionId]) -> Signal { + return self.account.postbox.transaction { transaction -> Void in + let infos = transaction.getItemCollectionsInfos(namespace: namespace) + + var packDict: [ItemCollectionId: Int] = [:] + for i in 0 ..< infos.count { + packDict[infos[i].0] = i + } + var tempSortedPacks: [(ItemCollectionId, ItemCollectionInfo)] = [] + var processedPacks = Set() + for id in itemIds { + if let index = packDict[id] { + tempSortedPacks.append(infos[index]) + processedPacks.insert(id) + } + } + let restPacks = infos.filter { !processedPacks.contains($0.0) } + let sortedPacks = restPacks + tempSortedPacks + addSynchronizeInstalledStickerPacksOperation(transaction: transaction, namespace: namespace, content: .sync, noDelay: false) + transaction.replaceItemCollectionInfos(namespace: namespace, itemCollectionInfos: sortedPacks) + } + |> ignoreValues + } } } diff --git a/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift b/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift index aed01b872d..7562288787 100644 --- a/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift +++ b/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift @@ -122,9 +122,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail let countryCode = defaultCountryCode() - let _ = (strongSelf.account.postbox.transaction { transaction -> Void in - transaction.setState(UnauthorizedAccountState(isTestingEnvironment: isTestingEnvironment, masterDatacenterId: masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))) - }).start() + let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: isTestingEnvironment, masterDatacenterId: masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start() } } } @@ -154,9 +152,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail transaction.removeAuth() }).start() } else { - let _ = strongSelf.account.postbox.transaction({ transaction -> Void in - transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .empty)) - }).start() + let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .empty)).start() } }) controller.accountUpdated = { [weak self] updatedAccount in @@ -282,9 +278,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail } let countryCode = defaultCountryCode() - let _ = (strongSelf.account.postbox.transaction { transaction -> Void in - transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))) - }).start() + let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start() }) controller.loginWithCode = { [weak self, weak controller] code in if let strongSelf = self { @@ -331,9 +325,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail return } let account = strongSelf.account - let _ = (strongSelf.account.postbox.transaction { transaction -> Void in - transaction.setState(UnauthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, contents: .empty)) - }).start() + let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, contents: .empty)).start() })]), on: .root, blockInteraction: false, completion: {}) }) ], actionLayout: .vertical, dismissOnOutsideTap: true) @@ -378,9 +370,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail case .codeExpired: text = strongSelf.presentationData.strings.Login_CodeExpired let account = strongSelf.account - let _ = (strongSelf.account.postbox.transaction { transaction -> Void in - transaction.setState(UnauthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, contents: .empty)) - }).start() + let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, contents: .empty)).start() } if resetCode { @@ -437,9 +427,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail controller.reset = { [weak self] in if let strongSelf = self { let account = strongSelf.account - let _ = (strongSelf.account.postbox.transaction { transaction -> Void in - transaction.setState(UnauthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, contents: .empty)) - }).start() + let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, contents: .empty)).start() } } controller.updateData(number: formatPhoneNumber(number), codeType: type, nextType: nextType, timeout: timeout, termsOfService: termsOfService) @@ -464,9 +452,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail } let countryCode = defaultCountryCode() - let _ = (strongSelf.account.postbox.transaction { transaction -> Void in - transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))) - }).start() + let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start() }) controller.loginWithPassword = { [weak self, weak controller] password in if let strongSelf = self { @@ -601,9 +587,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail } let countryCode = defaultCountryCode() - let _ = (strongSelf.account.postbox.transaction { transaction -> Void in - transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))) - }).start() + let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start() }) controller.reset = { [weak self, weak controller] in if let strongSelf = self, let strongController = controller { @@ -637,9 +621,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail controller.logout = { [weak self] in if let strongSelf = self { let account = strongSelf.account - let _ = (strongSelf.account.postbox.transaction { transaction -> Void in - transaction.setState(UnauthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, contents: .empty)) - }).start() + let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, contents: .empty)).start() } } } @@ -665,9 +647,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail } let countryCode = defaultCountryCode() - let _ = (strongSelf.account.postbox.transaction { transaction -> Void in - transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))) - }).start() + let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).start() }, displayCancel: displayCancel) controller.signUpWithName = { [weak self, weak controller] firstName, lastName, avatarData, avatarAsset, avatarAdjustments in if let strongSelf = self { diff --git a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift index e1c1ca95e6..6851645a6b 100644 --- a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift +++ b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift @@ -730,27 +730,7 @@ final class ChatMediaInputNode: ChatInputNode { break } } - let _ = (context.account.postbox.transaction { transaction -> Void in - let namespace = Namespaces.ItemCollection.CloudStickerPacks - let infos = transaction.getItemCollectionsInfos(namespace: namespace) - - var packDict: [ItemCollectionId: Int] = [:] - for i in 0 ..< infos.count { - packDict[infos[i].0] = i - } - var tempSortedPacks: [(ItemCollectionId, ItemCollectionInfo)] = [] - var processedPacks = Set() - for id in currentIds { - if let index = packDict[id] { - tempSortedPacks.append(infos[index]) - processedPacks.insert(id) - } - } - let restPacks = infos.filter { !processedPacks.contains($0.0) } - let sortedPacks = restPacks + tempSortedPacks - addSynchronizeInstalledStickerPacksOperation(transaction: transaction, namespace: namespace, content: .sync, noDelay: false) - transaction.replaceItemCollectionInfos(namespace: namespace, itemCollectionInfos: sortedPacks) - } + let _ = (context.engine.stickers.reorderStickerPacks(namespace: Namespaces.ItemCollection.CloudStickerPacks, itemIds: currentIds) |> deliverOnMainQueue).start(completed: { [weak self] in temporaryPackOrder.set(.single(nil)) diff --git a/submodules/TelegramUI/Sources/SharedNotificationManager.swift b/submodules/TelegramUI/Sources/SharedNotificationManager.swift index 6643e32e3f..bfe53b0ebd 100644 --- a/submodules/TelegramUI/Sources/SharedNotificationManager.swift +++ b/submodules/TelegramUI/Sources/SharedNotificationManager.swift @@ -393,10 +393,6 @@ public final class SharedNotificationManager { if let readMessageId = readMessageId { self.clearNotificationsManager?.append(readMessageId) - - let _ = account.postbox.transaction(ignoreDisabled: true, { transaction -> Void in - transaction.applyIncomingReadMaxId(readMessageId) - }).start() } for messageId in messagesDeleted { @@ -404,9 +400,6 @@ public final class SharedNotificationManager { } if !messagesDeleted.isEmpty { - let _ = account.postbox.transaction(ignoreDisabled: true, { transaction -> Void in - TelegramEngine(account: account).messages.deleteMessages(transaction: transaction, ids: messagesDeleted) - }).start() } if readMessageId != nil || !messagesDeleted.isEmpty { diff --git a/submodules/TelegramUIPreferences/Sources/RenderedTotalUnreadCount.swift b/submodules/TelegramUIPreferences/Sources/RenderedTotalUnreadCount.swift index c36a1b7935..613b51444e 100644 --- a/submodules/TelegramUIPreferences/Sources/RenderedTotalUnreadCount.swift +++ b/submodules/TelegramUIPreferences/Sources/RenderedTotalUnreadCount.swift @@ -22,31 +22,6 @@ public func renderedTotalUnreadCount(inAppSettings: InAppNotificationSettings, t return (totalUnreadState.count(for: inAppSettings.totalUnreadCountDisplayStyle.category, in: inAppSettings.totalUnreadCountDisplayCategory.statsType, with: inAppSettings.totalUnreadCountIncludeTags), type) } -public func getCurrentRenderedTotalUnreadCount(accountManager: AccountManager, postbox: Postbox) -> Signal<(Int32, RenderedTotalUnreadCountType), NoError> { - let counters = postbox.transaction { transaction -> ChatListTotalUnreadState in - return transaction.getTotalUnreadState(groupId: .root) - } - return combineLatest( - accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.inAppNotificationSettings]) - |> take(1), - counters - ) - |> map { sharedData, totalReadCounters -> (Int32, RenderedTotalUnreadCountType) in - let inAppSettings: InAppNotificationSettings - if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.inAppNotificationSettings]?.get(InAppNotificationSettings.self) { - inAppSettings = value - } else { - inAppSettings = .defaultSettings - } - let type: RenderedTotalUnreadCountType - switch inAppSettings.totalUnreadCountDisplayStyle { - case .filtered: - type = .filtered - } - return (totalReadCounters.count(for: inAppSettings.totalUnreadCountDisplayStyle.category, in: inAppSettings.totalUnreadCountDisplayCategory.statsType, with: inAppSettings.totalUnreadCountIncludeTags), type) - } -} - public func renderedTotalUnreadCount(accountManager: AccountManager, engine: TelegramEngine) -> Signal<(Int32, RenderedTotalUnreadCountType), NoError> { return combineLatest( accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.inAppNotificationSettings]), diff --git a/submodules/WallpaperResources/Sources/WallpaperCache.swift b/submodules/WallpaperResources/Sources/WallpaperCache.swift index 3c293626f9..12d999635e 100644 --- a/submodules/WallpaperResources/Sources/WallpaperCache.swift +++ b/submodules/WallpaperResources/Sources/WallpaperCache.swift @@ -28,10 +28,13 @@ public final class CachedWallpaper: Codable { } public func cachedWallpaper(account: Account, slug: String, settings: WallpaperSettings?, update: Bool = false) -> Signal { - return account.postbox.transaction { transaction -> Signal in - let key = ValueBoxKey(length: 8) - key.setInt64(0, value: Int64(bitPattern: slug.persistentHashValue)) - if !update, let entry = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: ApplicationSpecificItemCacheCollectionId.cachedWallpapers, key: key))?.get(CachedWallpaper.self) { + let engine = TelegramEngine(account: account) + + let slugKey = ValueBoxKey(length: 8) + slugKey.setInt64(0, value: Int64(bitPattern: slug.persistentHashValue)) + return engine.data.get(TelegramEngine.EngineData.Item.ItemCache.Item(collectionId: ApplicationSpecificItemCacheCollectionId.cachedWallpapers, id: slugKey)) + |> mapToSignal { entry -> Signal in + if !update, let entry = entry?.get(CachedWallpaper.self) { if let settings = settings { return .single(CachedWallpaper(wallpaper: entry.wallpaper.withUpdatedSettings(settings))) } else { @@ -44,33 +47,34 @@ public func cachedWallpaper(account: Account, slug: String, settings: WallpaperS return .single(nil) } |> mapToSignal { wallpaper -> Signal in - return account.postbox.transaction { transaction -> CachedWallpaper? in - let key = ValueBoxKey(length: 8) - key.setInt64(0, value: Int64(bitPattern: slug.persistentHashValue)) - let id = ItemCacheEntryId(collectionId: ApplicationSpecificItemCacheCollectionId.cachedWallpapers, key: key) - if var wallpaper = wallpaper { - switch wallpaper { - case let .file(file): - wallpaper = .file(TelegramWallpaper.File(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: file.isPattern, isDark: file.isDark, slug: file.slug, file: file.file.withUpdatedResource(WallpaperDataResource(slug: slug)), settings: file.settings)) - default: - break - } - if let entry = CodableEntry(CachedWallpaper(wallpaper: wallpaper)) { - transaction.putItemCacheEntry(id: id, entry: entry) - } - if let settings = settings { - return CachedWallpaper(wallpaper: wallpaper.withUpdatedSettings(settings)) - } else { - return CachedWallpaper(wallpaper: wallpaper) - } - } else { - transaction.removeItemCacheEntry(id: id) - return nil + let slugKey = ValueBoxKey(length: 8) + slugKey.setInt64(0, value: Int64(bitPattern: slug.persistentHashValue)) + + if var wallpaper = wallpaper { + switch wallpaper { + case let .file(file): + wallpaper = .file(TelegramWallpaper.File(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: file.isPattern, isDark: file.isDark, slug: file.slug, file: file.file.withUpdatedResource(WallpaperDataResource(slug: slug)), settings: file.settings)) + default: + break } + + let result: CachedWallpaper + if let settings = settings { + result = CachedWallpaper(wallpaper: wallpaper.withUpdatedSettings(settings)) + } else { + result = CachedWallpaper(wallpaper: wallpaper) + } + return engine.itemCache.put(collectionId: ApplicationSpecificItemCacheCollectionId.cachedWallpapers, id: slugKey, item: CachedWallpaper(wallpaper: wallpaper)) + |> map { _ -> CachedWallpaper? in } + |> then(.single(result)) + } else { + return engine.itemCache.remove(collectionId: ApplicationSpecificItemCacheCollectionId.cachedWallpapers, id: slugKey) + |> map { _ -> CachedWallpaper? in } + |> then(.single(nil)) } } } - } |> switchToLatest + } } public func updateCachedWallpaper(engine: TelegramEngine, wallpaper: TelegramWallpaper) {