Wire iOS media downloads through session bridge
This commit is contained in:
@@ -18,6 +18,8 @@ public protocol SessionBridge: Sendable {
|
||||
func react(chatId: Int64, messageId: Int64, reaction: String) async throws -> [Reaction]
|
||||
func pinnedMessages(chatId: Int64) async throws -> [Message]
|
||||
func copyPayload(chatId: Int64, messageId: Int64) async throws -> String
|
||||
func downloadPhoto(fileId: Int32) async throws -> DownloadedFile
|
||||
func downloadVoice(fileId: Int32) async throws -> DownloadedFile
|
||||
}
|
||||
|
||||
public actor FakeSessionBridge: SessionBridge {
|
||||
@@ -201,6 +203,14 @@ public actor FakeSessionBridge: SessionBridge {
|
||||
}
|
||||
return message.text
|
||||
}
|
||||
|
||||
public func downloadPhoto(fileId: Int32) async throws -> DownloadedFile {
|
||||
DownloadedFile(fileId: fileId, path: "/tmp/fake-photo-\(fileId).jpg")
|
||||
}
|
||||
|
||||
public func downloadVoice(fileId: Int32) async throws -> DownloadedFile {
|
||||
DownloadedFile(fileId: fileId, path: "/tmp/fake-voice-\(fileId).ogg")
|
||||
}
|
||||
}
|
||||
|
||||
public enum FakeBridgeError: LocalizedError {
|
||||
|
||||
@@ -153,6 +153,16 @@ public struct Profile: Equatable, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct DownloadedFile: Equatable, Sendable {
|
||||
public var fileId: Int32
|
||||
public var path: String
|
||||
|
||||
public init(fileId: Int32, path: String) {
|
||||
self.fileId = fileId
|
||||
self.path = path
|
||||
}
|
||||
}
|
||||
|
||||
public enum SessionEvent: Equatable, Sendable {
|
||||
case authChanged(AuthState)
|
||||
case chatListChanged([ChatSummary])
|
||||
|
||||
@@ -105,6 +105,14 @@ public actor UniFfiSessionBridge: SessionBridge {
|
||||
try handle.copyPayload(chatId: chatId, messageId: messageId)
|
||||
}
|
||||
|
||||
public func downloadPhoto(fileId: Int32) async throws -> DownloadedFile {
|
||||
try Self.mapDownloadedFile(handle.downloadPhoto(fileId: fileId))
|
||||
}
|
||||
|
||||
public func downloadVoice(fileId: Int32) async throws -> DownloadedFile {
|
||||
try Self.mapDownloadedFile(handle.downloadVoice(fileId: fileId))
|
||||
}
|
||||
|
||||
private static func mapAuthState(_ state: IosAuthState) -> AuthState {
|
||||
switch state {
|
||||
case .waitTdlibParameters:
|
||||
@@ -192,6 +200,10 @@ public actor UniFfiSessionBridge: SessionBridge {
|
||||
)
|
||||
}
|
||||
|
||||
private static func mapDownloadedFile(_ file: IosDownloadedFile) -> DownloadedFile {
|
||||
DownloadedFile(fileId: file.fileId, path: file.path)
|
||||
}
|
||||
|
||||
private static func mapEvent(_ event: IosEvent) -> SessionEvent {
|
||||
switch event {
|
||||
case let .authChanged(state):
|
||||
|
||||
Reference in New Issue
Block a user