mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Consolidates 137 wave commits + 31 supporting commits (CLAUDE.md bump, typealias additions, AnyObject→EngineMedia restoration) into one squashed commit. Migrates dozens of consumer-side public APIs, struct fields, protocol methods, and enum payloads from Postbox protocols/structs to TelegramEngine engine wrappers and typealiases. Drops `import Postbox` from many files. Adds new TelegramCore typealiases and one TelegramEngineUnauthorized facade. Notable changes by category: **TelegramCore typealias additions** (rule 2 — narrow utility typealiases): - EngineChatListIndex, EngineTempBoxFile, EngineItemCollectionItemIndex, EngineItemCollectionViewEntryIndex, EngineValueBoxEncryptionParameters, EngineMessageAndThreadId, EnginePeerStoryStats, EngineMessageHistoryAnchorIndex, EngineChatListTotalUnreadStateCategory, EngineChatListTotalUnreadStateStats, EnginePeerSummaryCounterTags, EngineChatListTotalUnreadState, EngineItemCacheEntryId, EngineHashFunctions, EngineCachedMediaResourceRepresentationResult, EngineMediaResourceDataFetchResult, EngineMediaResourceDataFetchError, EngineMediaResourceStatus, EngineCachedPeerData **TelegramCore engine extensions/forwarders**: - EngineMessage.engineMedia, EngineMessage.enginePeers, EngineMessage.adAttribute, EngineMessage.effectivelyIncoming - engineFileSize forwarder - TelegramEngine.Resources.clearCachedMediaResources(mediaResourceIds: Set<EngineMediaResource.Id>) - TelegramEngine.Resources.fetchStatus(id:resourceSize:) - TelegramEngineUnauthorized.UnauthorizedResources facade with storeResourceData **Public API/struct migrations to engine types**: - ChatAvailableMessageActions.banAuthor/banAuthors → EnginePeer?/[EnginePeer] - WebSessionsContextState.peers → [EnginePeer.Id: EnginePeer] - CacheUsageStats.peers → [EnginePeer.Id: EnginePeer] - PeerCommand.peer → EnginePeer - PeerInfoControllerMode.calls(messages:) → [EngineMessage] - CallControllerNodeProtocol.updatePeer → EnginePeer params - ChatHistoryListNode.messageInCurrentHistoryView (and 4 variants) → EngineMessage? - ChatHistorySearchContainerNode.messageForGallery → EngineMessage? - PeerInfoPaneNode.findLoadedMessage / ensureMessageIsVisible / transitionNodeForGallery → engine-typed - GalleryHiddenMediaTarget.getTransitionInfo / GalleryHiddenMediaManager.findTarget → engine-typed - ChatPanelInterfaceInteraction.presentReactionDeletionOptions / presentBan*MessageOptions → EnginePeer - DrawingMessageRenderer.messages → [EngineMessage] - ChatVideoGalleryItemScrubberView.setFetchStatusSignal → EngineMediaResource.FetchStatus - ChannelDiscussionGroupActionSheetItem.peer, VoiceChatPeerEntry.peer, VoiceChatFullscreenParticipantItem.peer, MediaStreamComponent.chatPeer, MediaStreamVideoComponent.callPeer, ChatMessageContactBubbleContentNode.contactPeer, ChatMessageForwardInfoNode.peer, ChatMessageCommentFooterContentNode.replyPeers, ChatReportPeerTitlePanelNode.peer, ChatMessageActionUrlAuthController.bot, PeerMediaCollectionInterfaceState.peer, ChatMessageCallBubbleContentNode.peopleAvatars, ChatLoadingNode.renderedPeer (→ EngineRenderedPeer) — all to engine types **Wave-71-shadow stored-field migrations** (Postbox Peer/Message → Engine wrapper): - LegacyCallControllerNode.peer - CallStatusBarNode.currentPeer **Dead-code / dead-field removals**: - CallController.peer, CallControllerNodeV2.account, ContactMultiselectionController PeerNameIndex fields, preparedChatListNodeViewTransition account: Account param, FetchResource.swift entirely (unused function) **Module-level Postbox import drops**: 30+ files including TelegramRootController, EditStories, GiftViewScreen, AnimatedStickerUtils, FetchPhotoLibraryImageResource, PeerInfoGiftsPaneNode, PeerInfoPaneContainerNode, PresentAddMembers, PeerInfoProfileItems, ChatControllerAdminBanUsers, PresentationData typealiases, DefaultDayPresentationTheme, ChatListViewTransition, GalleryHiddenMediaManager, RecentSessionsController, GifContext, AuthorizationSequenceController, PeerInfoHeaderEditingContentNode, PeerInfoHeaderNode, PeerAllowedReactionListController, CallControllerNodeV2, and 6 PeerInfo pane files. **AnyObject restoration**: rule 8 added (never substitute Postbox protocols with Any/AnyObject) — undid previous AnyObject substitutions in waves 141/143 back to EngineMedia. Doc maintenance: CLAUDE.md updated to reflect new typealiases and forwarders. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
126 lines
4 KiB
Swift
126 lines
4 KiB
Swift
import Foundation
|
|
import UIKit
|
|
import SwiftSignalKit
|
|
import TelegramCore
|
|
|
|
final class ChatMessageThrottledProcessingManager {
|
|
private let queue = Queue.mainQueue()
|
|
|
|
private let delay: Double
|
|
private let submitInterval: Double?
|
|
|
|
var process: ((Set<EngineMessageAndThreadId>) -> Void)?
|
|
|
|
private var timer: SwiftSignalKit.Timer?
|
|
private var processedList: [EngineMessageAndThreadId] = []
|
|
private var processed: [EngineMessageAndThreadId: Double] = [:]
|
|
private var buffer = Set<EngineMessageAndThreadId>()
|
|
|
|
init(delay: Double = 1.0, submitInterval: Double? = nil) {
|
|
self.delay = delay
|
|
self.submitInterval = submitInterval
|
|
}
|
|
|
|
func setProcess(process: @escaping (Set<EngineMessageAndThreadId>) -> Void) {
|
|
self.queue.async {
|
|
self.process = process
|
|
}
|
|
}
|
|
|
|
func add(_ messageIds: [EngineMessageAndThreadId]) {
|
|
self.queue.async {
|
|
let timestamp = CFAbsoluteTimeGetCurrent()
|
|
|
|
for id in messageIds {
|
|
if let processedTimestamp = self.processed[id] {
|
|
if let submitInterval = self.submitInterval, (submitInterval.isZero || (timestamp - processedTimestamp) >= submitInterval) {
|
|
self.processed[id] = timestamp
|
|
self.processedList.append(id)
|
|
self.buffer.insert(id)
|
|
}
|
|
} else {
|
|
self.processed[id] = timestamp
|
|
self.processedList.append(id)
|
|
self.buffer.insert(id)
|
|
}
|
|
}
|
|
|
|
if self.processedList.count > 1000 {
|
|
for i in 0 ..< 200 {
|
|
self.processed.removeValue(forKey: self.processedList[i])
|
|
}
|
|
self.processedList.removeSubrange(0 ..< 200)
|
|
}
|
|
|
|
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
|
|
}
|
|
let buffer = strongSelf.buffer
|
|
strongSelf.buffer.removeAll()
|
|
strongSelf.process?(buffer)
|
|
}
|
|
}
|
|
self.timer = timer
|
|
timer.start()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
final class ChatMessageVisibleThrottledProcessingManager {
|
|
private let queue = Queue.mainQueue()
|
|
|
|
private let interval: Double
|
|
|
|
private var currentIds = Set<EngineMessageAndThreadId>()
|
|
|
|
var process: ((Set<EngineMessageAndThreadId>) -> Void)?
|
|
|
|
private let timer: SwiftSignalKit.Timer
|
|
|
|
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<EngineMessageAndThreadId>) -> Void) {
|
|
self.queue.async {
|
|
self.process = process
|
|
}
|
|
}
|
|
|
|
func update(_ ids: Set<EngineMessageAndThreadId>) {
|
|
self.queue.async {
|
|
if self.currentIds != ids {
|
|
self.currentIds = ids
|
|
if !self.currentIds.isEmpty {
|
|
self.process?(self.currentIds)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|