feat: add basic support for file upload via blossom (#32)

Reviewed-on: https://git.reya.su/reya/coop-mobile/pulls/32
This commit is contained in:
2026-06-30 08:11:19 +00:00
parent 3bfe2308ba
commit cd5a393a01
9 changed files with 160 additions and 84 deletions
@@ -149,7 +149,11 @@ class ChatViewModel(
}
}
fun sendMessage(roomId: Long, message: String, replies: List<EventId> = emptyList()) {
fun sendMessage(
roomId: Long,
message: String,
replies: List<EventId> = emptyList()
) {
if (message.isEmpty()) {
appViewModel.showError("Message cannot be empty")
return
@@ -173,6 +177,24 @@ class ChatViewModel(
}
}
suspend fun sendFileMessage(
roomId: Long,
file: ByteArray?,
contentType: String? = "image/jpeg",
replies: List<EventId> = emptyList()
) {
if (file == null) return
try {
val uri = appViewModel.blossomUpload(file, contentType)
?: throw IllegalArgumentException("Failed to upload file")
sendMessage(roomId, uri, replies)
} catch (e: Exception) {
throw IllegalArgumentException("Error: ${e.message}")
}
}
fun isMessageSent(id: EventId): Boolean {
val giftWrapId = nostr.messages.rumorMap[id]
return if (giftWrapId != null) {