mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Refactoring
This commit is contained in:
parent
3d10a0c38c
commit
c146d15559
@ -577,6 +577,31 @@ private struct NotificationContent: CustomStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
private func getCurrentRenderedTotalUnreadCount(accountManager: AccountManager<TelegramAccountManagerTypes>, 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
|
||||
|
@ -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()
|
||||
})
|
||||
|
@ -389,11 +389,12 @@ final class LocalizationListControllerNode: ViewControllerTracingNode {
|
||||
}
|
||||
|
||||
let removeItem: (String) -> Void = { id in
|
||||
let _ = (context.account.postbox.transaction { transaction -> Signal<LocalizationInfo?, NoError> 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<LocalizationInfo?, NoError> 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
|
||||
|
@ -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<ItemCollectionId>()
|
||||
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))
|
||||
})
|
||||
|
@ -42,6 +42,13 @@ public extension TelegramEngineUnauthorized {
|
||||
public func uploadedPeerVideo(resource: MediaResource) -> Signal<UploadedPeerPhotoData, NoError> {
|
||||
return _internal_uploadedPeerVideo(postbox: self.account.postbox, network: self.account.network, messageMediaPreuploadManager: nil, resource: resource)
|
||||
}
|
||||
|
||||
public func setState(state: UnauthorizedAccountState) -> Signal<Never, NoError> {
|
||||
return self.account.postbox.transaction { transaction -> Void in
|
||||
transaction.setState(state)
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,5 +25,14 @@ public extension TelegramEngine {
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
public func clear(collectionIds: [Int8]) -> Signal<Never, NoError> {
|
||||
return self.account.postbox.transaction { transaction -> Void in
|
||||
for id in collectionIds {
|
||||
transaction.clearItemCacheCollection(collectionId: id)
|
||||
}
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 })
|
||||
|
@ -32,6 +32,13 @@ public extension TelegramEngine {
|
||||
public func downloadAndApplyLocalization(accountManager: AccountManager<TelegramAccountManagerTypes>, languageCode: String) -> Signal<Void, DownloadAndApplyLocalizationError> {
|
||||
return _internal_downloadAndApplyLocalization(accountManager: accountManager, postbox: self.account.postbox, network: self.account.network, languageCode: languageCode)
|
||||
}
|
||||
|
||||
public func removeSavedLocalization(languageCode: String) -> Signal<Never, NoError> {
|
||||
return self.account.postbox.transaction { transaction -> Void in
|
||||
_internal_removeSavedLocalization(transaction: transaction, languageCode: languageCode)
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,5 +415,19 @@ public extension TelegramEngine {
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
public func debugAddHoles() -> Signal<Never, NoError> {
|
||||
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<Never, NoError> {
|
||||
return self.account.postbox.transaction { transaction -> Void in
|
||||
transaction.reindexUnreadCounters()
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,5 +131,29 @@ public extension TelegramEngine {
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
public func reorderStickerPacks(namespace: ItemCollectionId.Namespace, itemIds: [ItemCollectionId]) -> Signal<Never, NoError> {
|
||||
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<ItemCollectionId>()
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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<ItemCollectionId>()
|
||||
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))
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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<TelegramAccountManagerTypes>, 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<TelegramAccountManagerTypes>, engine: TelegramEngine) -> Signal<(Int32, RenderedTotalUnreadCountType), NoError> {
|
||||
return combineLatest(
|
||||
accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.inAppNotificationSettings]),
|
||||
|
@ -28,10 +28,13 @@ public final class CachedWallpaper: Codable {
|
||||
}
|
||||
|
||||
public func cachedWallpaper(account: Account, slug: String, settings: WallpaperSettings?, update: Bool = false) -> Signal<CachedWallpaper?, NoError> {
|
||||
return account.postbox.transaction { transaction -> Signal<CachedWallpaper?, NoError> 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<CachedWallpaper?, NoError> 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<CachedWallpaper?, NoError> 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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user