Expose draft updates to iOS bridge
This commit is contained in:
@@ -18,6 +18,7 @@ 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 setDraft(chatId: Int64, text: String) async throws
|
||||
func downloadPhoto(fileId: Int32) async throws -> DownloadedFile
|
||||
func downloadVoice(fileId: Int32) async throws -> DownloadedFile
|
||||
}
|
||||
@@ -204,6 +205,14 @@ public actor FakeSessionBridge: SessionBridge {
|
||||
return message.text
|
||||
}
|
||||
|
||||
public func setDraft(chatId: Int64, text: String) async throws {
|
||||
let draft = Draft(chatId: chatId, text: text)
|
||||
if let index = chats.firstIndex(where: { $0.id == chatId }) {
|
||||
chats[index].draft = text.isEmpty ? nil : draft
|
||||
}
|
||||
events.append(.draftChanged(draft))
|
||||
}
|
||||
|
||||
public func downloadPhoto(fileId: Int32) async throws -> DownloadedFile {
|
||||
DownloadedFile(fileId: fileId, path: "/tmp/fake-photo-\(fileId).jpg")
|
||||
}
|
||||
|
||||
@@ -105,6 +105,10 @@ public actor UniFfiSessionBridge: SessionBridge {
|
||||
try handle.copyPayload(chatId: chatId, messageId: messageId)
|
||||
}
|
||||
|
||||
public func setDraft(chatId: Int64, text: String) async throws {
|
||||
try handle.setDraft(chatId: chatId, text: text)
|
||||
}
|
||||
|
||||
public func downloadPhoto(fileId: Int32) async throws -> DownloadedFile {
|
||||
try Self.mapDownloadedFile(handle.downloadPhoto(fileId: fileId))
|
||||
}
|
||||
|
||||
@@ -228,6 +228,15 @@ public final class ChatViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
public func saveDraft() async {
|
||||
do {
|
||||
try await bridge.setDraft(chatId: chat.id, text: composeText)
|
||||
errorMessage = nil
|
||||
} catch {
|
||||
errorMessage = error.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
private func replaceMessage(_ message: Message) {
|
||||
if let index = messages.firstIndex(where: { $0.id == message.id }) {
|
||||
messages[index] = message
|
||||
|
||||
Reference in New Issue
Block a user