mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Migrates uploadSecureIdFile's public signature from (context:, postbox: Postbox, network: Network, resource: MediaResource) to (context:, engine: TelegramEngine, resource: EngineMediaResource). SecureIdVerificationDocumentsContext refactored to hold engine: TelegramEngine instead of raw postbox + network, drops import Postbox (tally +1). The one instantiation site in SecureIdDocumentFormControllerNode updates to pass engine: self.context.engine. Completes the last explicitly-named future-wave candidate from CLAUDE.md. Bundled: spec + plan + C1 atomic migration + CLAUDE.md outcome. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
73 lines
2.8 KiB
Swift
73 lines
2.8 KiB
Swift
import Foundation
|
|
import TelegramCore
|
|
import SwiftSignalKit
|
|
|
|
private final class DocumentContext {
|
|
private let disposable: Disposable
|
|
|
|
init(disposable: Disposable) {
|
|
self.disposable = disposable
|
|
}
|
|
|
|
deinit {
|
|
self.disposable.dispose()
|
|
}
|
|
}
|
|
|
|
final class SecureIdVerificationDocumentsContext {
|
|
private let context: SecureIdAccessContext
|
|
private let engine: TelegramEngine
|
|
private let update: (Int64, SecureIdVerificationLocalDocumentState) -> Void
|
|
private var contexts: [Int64: DocumentContext] = [:]
|
|
private(set) var uploadedFiles: [Data: Data] = [:]
|
|
|
|
init(engine: TelegramEngine, context: SecureIdAccessContext, update: @escaping (Int64, SecureIdVerificationLocalDocumentState) -> Void) {
|
|
self.engine = engine
|
|
self.context = context
|
|
self.update = update
|
|
}
|
|
|
|
func stateUpdated(_ documents: [SecureIdVerificationDocument]) {
|
|
var validIds = Set<Int64>()
|
|
|
|
for document in documents {
|
|
switch document {
|
|
case let .local(info):
|
|
validIds.insert(info.id)
|
|
if self.contexts[info.id] == nil {
|
|
let disposable = MetaDisposable()
|
|
self.contexts[info.id] = DocumentContext(disposable: disposable)
|
|
disposable.set((uploadSecureIdFile(context: self.context, engine: self.engine, resource: EngineMediaResource(info.resource))
|
|
|> deliverOnMainQueue).start(next: { [weak self] result in
|
|
if let strongSelf = self {
|
|
switch result {
|
|
case let .progress(value):
|
|
if strongSelf.contexts[info.id] != nil {
|
|
strongSelf.update(info.id, .uploading(value))
|
|
}
|
|
case let .result(file, data):
|
|
if strongSelf.contexts[info.id] != nil {
|
|
strongSelf.uploadedFiles[file.fileHash] = data
|
|
strongSelf.update(info.id, .uploaded(file))
|
|
}
|
|
}
|
|
}
|
|
}, error: { _ in
|
|
}))
|
|
}
|
|
case .remote:
|
|
break
|
|
}
|
|
}
|
|
|
|
var removeIds: [Int64] = []
|
|
for (id, _) in self.contexts {
|
|
if !validIds.contains(id) {
|
|
removeIds.append(id)
|
|
}
|
|
}
|
|
for id in removeIds {
|
|
self.contexts.removeValue(forKey: id)
|
|
}
|
|
}
|
|
}
|