Add iOS platform service boundaries

This commit is contained in:
Mikhail Kilin
2026-05-20 15:48:33 +03:00
parent 593b19ba8e
commit 8bea159569
4 changed files with 242 additions and 1 deletions

View File

@@ -264,8 +264,15 @@ public final class ProfileViewModel: ObservableObject {
public final class MediaViewModel: ObservableObject {
@Published public private(set) var activePhotoPath: String?
@Published public private(set) var activeVoicePath: String?
@Published public private(set) var isVoicePlaying = false
public init() {}
private let cache: MediaCache?
private let voicePlayer: VoicePlayback?
public init(cache: MediaCache? = nil, voicePlayer: VoicePlayback? = nil) {
self.cache = cache
self.voicePlayer = voicePlayer
}
public func showPhoto(path: String) {
activePhotoPath = path
@@ -274,4 +281,27 @@ public final class MediaViewModel: ObservableObject {
public func showVoice(path: String) {
activeVoicePath = path
}
public func cachedPhotoPath(fileId: Int32) -> URL? {
cache?.photoPath(fileId: fileId)
}
public func cachedVoicePath(fileId: Int32) -> URL? {
cache?.voicePath(fileId: fileId)
}
public func playVoice(url: URL) async {
do {
try await voicePlayer?.load(url: url)
await voicePlayer?.play()
isVoicePlaying = true
} catch {
isVoicePlaying = false
}
}
public func pauseVoice() async {
await voicePlayer?.pause()
isVoicePlaying = false
}
}