forked from reya/coop-mobile
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user