mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-05-21 18:20:41 +00:00
f84e94f507
Drive raw `MediaResource` out of the `TelegramEngine` public facade for photo-upload APIs, and complete a first batch of consumer-side migrations. Behavior-preserving. The `_internal_*` Postbox-facing functions are untouched — only the facade signatures change, bridging inside via `_asResource()` / `EngineMediaResource(_:)`. TelegramEngine facades migrated (signatures now take EngineMediaResource): - TelegramEngine.Peers.uploadedPeerPhoto / uploadedPeerVideo - TelegramEngine.Peers.updatePeerPhoto (closure param too) - TelegramEngine.AccountData.updateAccountPhoto / updateFallbackPhoto - TelegramEngine.Contacts.updateContactPhoto - TelegramEngine.Auth.uploadedPeerVideo Consumer-side changes: - MapResourceToAvatarSizes utility: signature is now (engine: TelegramEngine, resource: EngineMediaResource, ...). Uses engine.resources.data(id:) internally. The submodule drops `import Postbox` and the Bazel dep. - AuthorizationUI: avatar-video signal retyped from Signal<TelegramMediaResource?> to Signal<EngineMediaResource?>. - 27 `mapResourceToAvatarSizes(postbox:...)` call sites across 5 TelegramUI/TelegramCallsUI files migrated to the new form. Deferred: - SaveToCameraRoll (planned Task 8) abandoned — module has three public functions taking `postbox: Postbox` (umbrella-type leak, banned by rule 2) and requires a full module-migration wave, not a type swap. Reason recorded in the wave-2 plan doc. - Other TelegramEngine facades still leaking MediaResource (TelegramEngineStickers.uploadSticker; UploadSecureIdFile.* — additionally leaks Postbox) flagged for a future wave. Docs: - CLAUDE.md: new rule 7 (TelegramCore never imports UIKit/Display, shared with Telegram-Mac), and a new "MediaResource → EngineMediaResource consumer migration" section describing the wrap/unwrap helpers and the modify-in-place facade-bridging pattern. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
29 lines
1.0 KiB
Swift
29 lines
1.0 KiB
Swift
import Foundation
|
|
import UIKit
|
|
import SwiftSignalKit
|
|
import TelegramCore
|
|
import Display
|
|
|
|
public func mapResourceToAvatarSizes(engine: TelegramEngine, resource: EngineMediaResource, representations: [TelegramMediaImageRepresentation]) -> Signal<[Int: Data], NoError> {
|
|
return engine.resources.data(id: resource.id)
|
|
|> take(1)
|
|
|> map { data -> [Int: Data] in
|
|
guard data.isComplete, let image = UIImage(contentsOfFile: data.path) else {
|
|
return [:]
|
|
}
|
|
var result: [Int: Data] = [:]
|
|
for i in 0 ..< representations.count {
|
|
let size: CGSize
|
|
if representations[i].dimensions.width == 80 {
|
|
size = CGSize(width: 160.0, height: 160.0)
|
|
} else {
|
|
size = representations[i].dimensions.cgSize
|
|
}
|
|
if let scaledImage = generateScaledImage(image: image, size: size, scale: 1.0), let scaledData = scaledImage.jpegData(compressionQuality: 0.8) {
|
|
result[i] = scaledData
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
}
|