From bd9c247ee8ee2925e4fd9af0516c54395977812e Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 29 Sep 2022 17:03:08 +0100 Subject: [PATCH] fixing bridge images not showing up - caused by a missing mimetype field in the message request --- .../st/matrix/message/internal/ApiMessage.kt | 1 + .../message/internal/SendMessageUseCase.kt | 24 +++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/ApiMessage.kt b/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/ApiMessage.kt index 9af2353..84bc9f7 100644 --- a/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/ApiMessage.kt +++ b/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/ApiMessage.kt @@ -45,6 +45,7 @@ sealed class ApiMessage { data class Info( @SerialName("h") val height: Int, @SerialName("w") val width: Int, + @SerialName("mimetype") val mimeType: String, @SerialName("size") val size: Long, ) diff --git a/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/SendMessageUseCase.kt b/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/SendMessageUseCase.kt index 8398148..a75e088 100644 --- a/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/SendMessageUseCase.kt +++ b/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/SendMessageUseCase.kt @@ -1,6 +1,9 @@ package app.dapk.st.matrix.message.internal -import app.dapk.st.matrix.common.* +import app.dapk.st.matrix.common.EventId +import app.dapk.st.matrix.common.EventType +import app.dapk.st.matrix.common.JsonString +import app.dapk.st.matrix.common.RoomId import app.dapk.st.matrix.http.MatrixHttpClient import app.dapk.st.matrix.http.MatrixHttpClient.HttpRequest import app.dapk.st.matrix.message.ApiSendResponse @@ -57,7 +60,7 @@ internal class SendMessageUseCase( } } - private suspend fun ApiMessageMapper.imageMessageRequest(message: Message.ImageMessage): HttpRequest { + private suspend fun imageMessageRequest(message: Message.ImageMessage): HttpRequest { val imageMeta = imageContentReader.meta(message.content.uri) return when (message.sendEncrypted) { @@ -91,11 +94,11 @@ internal class SendMessageUseCase( info = ApiMessage.ImageMessage.ImageContent.Info( height = imageMeta.height, width = imageMeta.width, - size = imageMeta.size + size = imageMeta.size, + mimeType = imageMeta.mimeType, ) ) - val json = JsonString( MatrixHttpClient.jsonWithDefaults.encodeToString( ApiMessage.ImageMessage.serializer(), @@ -134,7 +137,8 @@ internal class SendMessageUseCase( ApiMessage.ImageMessage.ImageContent.Info( height = imageMeta.height, width = imageMeta.width, - size = imageMeta.size + size = imageMeta.size, + mimeType = imageMeta.mimeType, ) ), ) @@ -163,14 +167,4 @@ class ApiMessageMapper { ) ) - fun Message.ImageMessage.toContents(uri: MxUrl, image: ImageContentReader.ImageContent) = ApiMessage.ImageMessage.ImageContent( - url = uri, - filename = image.fileName, - ApiMessage.ImageMessage.ImageContent.Info( - height = image.height, - width = image.width, - size = image.size - ) - ) - }