mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Sparse message list improvements
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Foundation
|
||||
import SwiftSignalKit
|
||||
import Postbox
|
||||
import TelegramApi
|
||||
|
||||
public extension TelegramEngine {
|
||||
final class Messages {
|
||||
@@ -245,5 +246,52 @@ public extension TelegramEngine {
|
||||
public func sparseMessageList(peerId: EnginePeer.Id, tag: EngineMessage.Tags) -> SparseMessageList {
|
||||
return SparseMessageList(account: self.account, peerId: peerId, messageTag: tag)
|
||||
}
|
||||
|
||||
public func refreshMessageTagStats(peerId: EnginePeer.Id, tags: [EngineMessage.Tags]) -> Signal<Never, NoError> {
|
||||
let account = self.account
|
||||
return self.account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||
return transaction.getPeer(peerId).flatMap(apiInputPeer)
|
||||
}
|
||||
|> mapToSignal { inputPeer -> Signal<Never, NoError> in
|
||||
guard let inputPeer = inputPeer else {
|
||||
return .complete()
|
||||
}
|
||||
var signals: [Signal<(count: Int32?, topId: Int32?), NoError>] = []
|
||||
for tag in tags {
|
||||
guard let filter = messageFilterForTagMask(tag) else {
|
||||
signals.append(.single((nil, nil)))
|
||||
continue
|
||||
}
|
||||
signals.append(self.account.network.request(Api.functions.messages.search(flags: 0, peer: inputPeer, q: "", fromId: nil, topMsgId: nil, filter: filter, minDate: 0, maxDate: 0, offsetId: 0, addOffset: 0, limit: 1, maxId: 0, minId: 0, hash: 0))
|
||||
|> map { result -> (count: Int32?, topId: Int32?) in
|
||||
switch result {
|
||||
case let .messagesSlice(_, count, _, _, messages, _, _):
|
||||
return (count, messages.first?.id(namespace: Namespaces.Message.Cloud)?.id)
|
||||
case let .channelMessages(_, _, count, _, messages, _, _):
|
||||
return (count, messages.first?.id(namespace: Namespaces.Message.Cloud)?.id)
|
||||
case let .messages(messages, _, _):
|
||||
return (Int32(messages.count), messages.first?.id(namespace: Namespaces.Message.Cloud)?.id)
|
||||
case .messagesNotModified:
|
||||
return (nil, nil)
|
||||
}
|
||||
}
|
||||
|> `catch` { _ -> Signal<(count: Int32?, topId: Int32?), NoError> in
|
||||
return .single((nil, nil))
|
||||
})
|
||||
}
|
||||
return combineLatest(signals)
|
||||
|> mapToSignal { counts -> Signal<Never, NoError> in
|
||||
return account.postbox.transaction { transaction in
|
||||
for i in 0 ..< tags.count {
|
||||
let (count, maxId) = counts[i]
|
||||
if let count = count {
|
||||
transaction.replaceMessageTagSummary(peerId: peerId, tagMask: tags[i], namespace: Namespaces.Message.Cloud, count: count, maxId: maxId ?? 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user