mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Add extended media polling
This commit is contained in:
@@ -78,16 +78,33 @@ final class ChatMessageThrottledProcessingManager {
|
||||
final class ChatMessageVisibleThrottledProcessingManager {
|
||||
private let queue = Queue()
|
||||
|
||||
private let delay: Double
|
||||
private let interval: Double
|
||||
|
||||
private var currentIds = Set<MessageId>()
|
||||
|
||||
var process: ((Set<MessageId>) -> Void)?
|
||||
|
||||
private var timer: SwiftSignalKit.Timer?
|
||||
private let timer: SwiftSignalKit.Timer
|
||||
|
||||
init(delay: Double = 1.0) {
|
||||
self.delay = delay
|
||||
init(interval: Double = 5.0) {
|
||||
self.interval = interval
|
||||
|
||||
var completionImpl: (() -> Void)?
|
||||
let timer = SwiftSignalKit.Timer(timeout: self.interval, repeat: true, completion: {
|
||||
completionImpl?()
|
||||
}, queue: self.queue)
|
||||
self.timer = timer
|
||||
timer.start()
|
||||
|
||||
completionImpl = { [weak self] in
|
||||
if let strongSelf = self, !strongSelf.currentIds.isEmpty {
|
||||
strongSelf.process?(strongSelf.currentIds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.timer.invalidate()
|
||||
}
|
||||
|
||||
func setProcess(process: @escaping (Set<MessageId>) -> Void) {
|
||||
@@ -100,21 +117,8 @@ final class ChatMessageVisibleThrottledProcessingManager {
|
||||
self.queue.async {
|
||||
if self.currentIds != ids {
|
||||
self.currentIds = ids
|
||||
if self.timer == nil {
|
||||
var completionImpl: (() -> Void)?
|
||||
let timer = SwiftSignalKit.Timer(timeout: self.delay, repeat: false, completion: {
|
||||
completionImpl?()
|
||||
}, queue: self.queue)
|
||||
completionImpl = { [weak self, weak timer] in
|
||||
if let strongSelf = self {
|
||||
if let timer = timer, strongSelf.timer === timer {
|
||||
strongSelf.timer = nil
|
||||
}
|
||||
strongSelf.process?(strongSelf.currentIds)
|
||||
}
|
||||
}
|
||||
self.timer = timer
|
||||
timer.start()
|
||||
if !self.currentIds.isEmpty {
|
||||
self.process?(self.currentIds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user