adding mimetype and reusing filename image content properties
This commit is contained in:
parent
934f80df1f
commit
f668a1b8ea
|
@ -443,6 +443,7 @@ internal class AndroidImageContentReader(private val contentResolver: ContentRes
|
|||
height = options.outHeight,
|
||||
width = options.outWidth,
|
||||
size = output.size.toLong(),
|
||||
mimeType = options.outMimeType,
|
||||
fileName = androidUri.lastPathSegment ?: "file",
|
||||
content = output
|
||||
)
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package app.dapk.st.matrix.message.internal
|
||||
|
||||
interface ImageContentReader {
|
||||
fun read(uri: String): ImageContent
|
||||
|
||||
data class ImageContent(
|
||||
val height: Int,
|
||||
val width: Int,
|
||||
val size: Long,
|
||||
val fileName: String,
|
||||
val mimeType: String,
|
||||
val content: ByteArray
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as ImageContent
|
||||
|
||||
if (height != other.height) return false
|
||||
if (width != other.width) return false
|
||||
if (size != other.size) return false
|
||||
if (!content.contentEquals(other.content)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = height
|
||||
result = 31 * result + width
|
||||
result = 31 * result + size.hashCode()
|
||||
result = 31 * result + content.contentHashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,21 +38,15 @@ internal class SendMessageUseCase(
|
|||
}
|
||||
|
||||
is MessageService.Message.ImageMessage -> {
|
||||
println("Sending message")
|
||||
val imageContent = imageContentReader.read(message.content.uri)
|
||||
|
||||
println("content: ${imageContent.size}")
|
||||
|
||||
val uri = httpClient.execute(uploadRequest(imageContent.content, imageContent.fileName, "image/png")).contentUri
|
||||
println("Got uri $uri")
|
||||
|
||||
val uri = httpClient.execute(uploadRequest(imageContent.content, imageContent.fileName, imageContent.mimeType)).contentUri
|
||||
val request = sendRequest(
|
||||
roomId = message.roomId,
|
||||
eventType = EventType.ROOM_MESSAGE,
|
||||
txId = message.localId,
|
||||
content = MessageService.Message.Content.ImageContent(
|
||||
url = uri,
|
||||
filename = "foobar.png",
|
||||
filename = imageContent.fileName,
|
||||
MessageService.Message.Content.ImageContent.Info(
|
||||
height = imageContent.height,
|
||||
width = imageContent.width,
|
||||
|
@ -66,38 +60,3 @@ internal class SendMessageUseCase(
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
interface ImageContentReader {
|
||||
fun read(uri: String): ImageContent
|
||||
|
||||
data class ImageContent(
|
||||
val height: Int,
|
||||
val width: Int,
|
||||
val size: Long,
|
||||
val fileName: String,
|
||||
val content: ByteArray
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as ImageContent
|
||||
|
||||
if (height != other.height) return false
|
||||
if (width != other.width) return false
|
||||
if (size != other.size) return false
|
||||
if (!content.contentEquals(other.content)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = height
|
||||
result = 31 * result + width
|
||||
result = 31 * result + size.hashCode()
|
||||
result = 31 * result + content.contentHashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,10 +19,7 @@ internal object ApiTimelineMessageContentDeserializer : KSerializer<ApiTimelineE
|
|||
return when (element.jsonObject["msgtype"]?.jsonPrimitive?.content) {
|
||||
"m.text" -> ApiTimelineEvent.TimelineMessage.Content.Text.serializer().deserialize(decoder)
|
||||
"m.image" -> ApiTimelineEvent.TimelineMessage.Content.Image.serializer().deserialize(decoder)
|
||||
else -> {
|
||||
println(element)
|
||||
ApiTimelineEvent.TimelineMessage.Content.Ignored
|
||||
}
|
||||
else -> ApiTimelineEvent.TimelineMessage.Content.Ignored
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ internal class RoomEventFactory(
|
|||
|
||||
private fun ApiTimelineEvent.TimelineMessage.readImageMeta(userCredentials: UserCredentials): RoomEvent.Image.ImageMeta {
|
||||
val content = this.content as ApiTimelineEvent.TimelineMessage.Content.Image
|
||||
println(content)
|
||||
return RoomEvent.Image.ImageMeta(
|
||||
content.info?.width,
|
||||
content.info?.height,
|
||||
|
|
|
@ -338,6 +338,7 @@ class JavaImageContentReader : ImageContentReader {
|
|||
height = image.height,
|
||||
width = image.width,
|
||||
size = size,
|
||||
mimeType = "image/${file.extension}",
|
||||
fileName = file.name,
|
||||
content = file.readBytes()
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue