Merge pull request #167 from ouchadam/feature/missing-mimetype

Fixing bridges missing images
This commit is contained in:
Adam Brown 2022-09-29 17:07:41 +01:00 committed by GitHub
commit 60f4859ed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 15 deletions

View File

@ -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,
)

View File

@ -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<ApiSendResponse> {
private suspend fun imageMessageRequest(message: Message.ImageMessage): HttpRequest<ApiSendResponse> {
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
)
)
}