From 03f72c3abd02dbe2fbd6586c880d4ca8f7070c17 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 9 Apr 2019 23:41:56 +0400 Subject: [PATCH] Added recent sticker clearing --- TelegramCore/ChatHistoryPreloadManager.swift | 2 +- ...nagedSynchronizeRecentlyUsedMediaOperations.swift | 8 ++++++++ .../SynchronizeRecentlyUsedMediaOperations.swift | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/TelegramCore/ChatHistoryPreloadManager.swift b/TelegramCore/ChatHistoryPreloadManager.swift index 4e1c9f0211..0cdd031947 100644 --- a/TelegramCore/ChatHistoryPreloadManager.swift +++ b/TelegramCore/ChatHistoryPreloadManager.swift @@ -204,7 +204,7 @@ final class ChatHistoryPreloadManager { if let strongSelf = self { var indices: [(ChatHistoryPreloadIndex, Bool, Bool)] = [] for entry in view.0.entries { - if case let .MessageEntry(index, _, readState, notificationSettings, _, _, _) = entry { + if case let .MessageEntry(index, _, readState, notificationSettings, _, _, _, _) = entry { var hasUnread = false if let readState = readState { hasUnread = readState.count != 0 diff --git a/TelegramCore/ManagedSynchronizeRecentlyUsedMediaOperations.swift b/TelegramCore/ManagedSynchronizeRecentlyUsedMediaOperations.swift index dbe38cb389..2b92f6b42c 100644 --- a/TelegramCore/ManagedSynchronizeRecentlyUsedMediaOperations.swift +++ b/TelegramCore/ManagedSynchronizeRecentlyUsedMediaOperations.swift @@ -181,6 +181,14 @@ private func synchronizeRecentlyUsedMedia(transaction: Transaction, postbox: Pos |> mapToSignal { _ -> Signal in return .complete() } + case .clear: + return network.request(Api.functions.messages.clearRecentStickers(flags: 0)) + |> `catch` { _ -> Signal in + return .single(.boolFalse) + } + |> mapToSignal { _ -> Signal in + return .complete() + } case .sync: return managedRecentStickers(postbox: postbox, network: network) } diff --git a/TelegramCore/SynchronizeRecentlyUsedMediaOperations.swift b/TelegramCore/SynchronizeRecentlyUsedMediaOperations.swift index 566833a75f..f7e35283e0 100644 --- a/TelegramCore/SynchronizeRecentlyUsedMediaOperations.swift +++ b/TelegramCore/SynchronizeRecentlyUsedMediaOperations.swift @@ -10,12 +10,14 @@ import SwiftSignalKit private enum SynchronizeRecentlyUsedMediaOperationContentType: Int32 { case add case remove + case clear case sync } enum SynchronizeRecentlyUsedMediaOperationContent: PostboxCoding { case add(id: Int64, accessHash: Int64, fileReference: FileMediaReference?) case remove(id: Int64, accessHash: Int64) + case clear case sync init(decoder: PostboxDecoder) { @@ -24,6 +26,8 @@ enum SynchronizeRecentlyUsedMediaOperationContent: PostboxCoding { self = .add(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeAnyObjectForKey("fr", decoder: { FileMediaReference(decoder: $0) }) as? FileMediaReference) case SynchronizeRecentlyUsedMediaOperationContentType.remove.rawValue: self = .remove(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) + case SynchronizeRecentlyUsedMediaOperationContentType.clear.rawValue: + self = .clear case SynchronizeRecentlyUsedMediaOperationContentType.sync.rawValue: self = .sync default: @@ -47,6 +51,8 @@ enum SynchronizeRecentlyUsedMediaOperationContent: PostboxCoding { encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.remove.rawValue, forKey: "r") encoder.encodeInt64(id, forKey: "i") encoder.encodeInt64(accessHash, forKey: "h") + case .clear: + encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.clear.rawValue, forKey: "r") case .sync: encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.sync.rawValue, forKey: "r") } @@ -103,3 +109,9 @@ func addRecentlyUsedSticker(transaction: Transaction, fileReference: FileMediaRe addSynchronizeRecentlyUsedMediaOperation(transaction: transaction, category: .stickers, operation: .add(id: resource.fileId, accessHash: resource.accessHash, fileReference: fileReference)) } } + +public func clearRecentlyUsedStickers(transaction: Transaction) { + transaction.replaceOrderedItemListItems(collectionId: Namespaces.OrderedItemList.CloudRecentStickers, items: []) + addSynchronizeRecentlyUsedMediaOperation(transaction: transaction, category: .stickers, operation: .clear) +} +