Merge pull request #3574 from element-hq/feature/bma/improveMediaModel
Clarify model for Event with attachment
This commit is contained in:
commit
7ece687740
58 changed files with 444 additions and 259 deletions
|
|
@ -30,10 +30,14 @@ data class MessageContent(
|
|||
data object RedactedContent : EventContent
|
||||
|
||||
data class StickerContent(
|
||||
val body: String,
|
||||
val filename: String,
|
||||
val body: String?,
|
||||
val info: ImageInfo,
|
||||
val source: MediaSource,
|
||||
) : EventContent
|
||||
) : EventContent {
|
||||
val bestDescription: String
|
||||
get() = body ?: filename
|
||||
}
|
||||
|
||||
data class PollContent(
|
||||
val question: String,
|
||||
|
|
|
|||
|
|
@ -18,24 +18,37 @@ import io.element.android.libraries.matrix.api.media.VideoInfo
|
|||
@Immutable
|
||||
sealed interface MessageType
|
||||
|
||||
@Immutable
|
||||
sealed interface MessageTypeWithAttachment : MessageType {
|
||||
val filename: String
|
||||
val caption: String?
|
||||
val formattedCaption: FormattedBody?
|
||||
|
||||
val bestDescription: String
|
||||
get() = caption ?: filename
|
||||
}
|
||||
|
||||
data class EmoteMessageType(
|
||||
val body: String,
|
||||
val formatted: FormattedBody?
|
||||
) : MessageType
|
||||
|
||||
data class ImageMessageType(
|
||||
val body: String,
|
||||
val formatted: FormattedBody?,
|
||||
val filename: String?,
|
||||
override val filename: String,
|
||||
override val caption: String?,
|
||||
override val formattedCaption: FormattedBody?,
|
||||
val source: MediaSource,
|
||||
val info: ImageInfo?
|
||||
) : MessageType
|
||||
) : MessageTypeWithAttachment
|
||||
|
||||
// FIXME This is never used in production code.
|
||||
data class StickerMessageType(
|
||||
val body: String,
|
||||
override val filename: String,
|
||||
override val caption: String?,
|
||||
override val formattedCaption: FormattedBody?,
|
||||
val source: MediaSource,
|
||||
val info: ImageInfo?
|
||||
) : MessageType
|
||||
) : MessageTypeWithAttachment
|
||||
|
||||
data class LocationMessageType(
|
||||
val body: String,
|
||||
|
|
@ -44,31 +57,37 @@ data class LocationMessageType(
|
|||
) : MessageType
|
||||
|
||||
data class AudioMessageType(
|
||||
val body: String,
|
||||
override val filename: String,
|
||||
override val caption: String?,
|
||||
override val formattedCaption: FormattedBody?,
|
||||
val source: MediaSource,
|
||||
val info: AudioInfo?,
|
||||
) : MessageType
|
||||
) : MessageTypeWithAttachment
|
||||
|
||||
data class VoiceMessageType(
|
||||
val body: String,
|
||||
override val filename: String,
|
||||
override val caption: String?,
|
||||
override val formattedCaption: FormattedBody?,
|
||||
val source: MediaSource,
|
||||
val info: AudioInfo?,
|
||||
val details: AudioDetails?,
|
||||
) : MessageType
|
||||
) : MessageTypeWithAttachment
|
||||
|
||||
data class VideoMessageType(
|
||||
val body: String,
|
||||
val formatted: FormattedBody?,
|
||||
val filename: String?,
|
||||
override val filename: String,
|
||||
override val caption: String?,
|
||||
override val formattedCaption: FormattedBody?,
|
||||
val source: MediaSource,
|
||||
val info: VideoInfo?
|
||||
) : MessageType
|
||||
) : MessageTypeWithAttachment
|
||||
|
||||
data class FileMessageType(
|
||||
val body: String,
|
||||
override val filename: String,
|
||||
override val caption: String?,
|
||||
override val formattedCaption: FormattedBody?,
|
||||
val source: MediaSource,
|
||||
val info: FileInfo?
|
||||
) : MessageType
|
||||
) : MessageTypeWithAttachment
|
||||
|
||||
data class NoticeMessageType(
|
||||
val body: String,
|
||||
|
|
|
|||
|
|
@ -50,14 +50,18 @@ class EventMessageMapper {
|
|||
when (type.content.voice) {
|
||||
null -> {
|
||||
AudioMessageType(
|
||||
body = type.content.body,
|
||||
filename = type.content.filename,
|
||||
caption = type.content.caption,
|
||||
formattedCaption = type.content.formattedCaption?.map(),
|
||||
source = type.content.source.map(),
|
||||
info = type.content.info?.map(),
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
VoiceMessageType(
|
||||
body = type.content.body,
|
||||
filename = type.content.filename,
|
||||
caption = type.content.caption,
|
||||
formattedCaption = type.content.formattedCaption?.map(),
|
||||
source = type.content.source.map(),
|
||||
info = type.content.info?.map(),
|
||||
details = type.content.audio?.map(),
|
||||
|
|
@ -66,10 +70,22 @@ class EventMessageMapper {
|
|||
}
|
||||
}
|
||||
is RustMessageType.File -> {
|
||||
FileMessageType(type.content.body, type.content.source.map(), type.content.info?.map())
|
||||
FileMessageType(
|
||||
filename = type.content.filename,
|
||||
caption = type.content.caption,
|
||||
formattedCaption = type.content.formattedCaption?.map(),
|
||||
source = type.content.source.map(),
|
||||
info = type.content.info?.map(),
|
||||
)
|
||||
}
|
||||
is RustMessageType.Image -> {
|
||||
ImageMessageType(type.content.body, type.content.formatted?.map(), type.content.filename, type.content.source.map(), type.content.info?.map())
|
||||
ImageMessageType(
|
||||
filename = type.content.filename,
|
||||
caption = type.content.caption,
|
||||
formattedCaption = type.content.formattedCaption?.map(),
|
||||
source = type.content.source.map(),
|
||||
info = type.content.info?.map(),
|
||||
)
|
||||
}
|
||||
is RustMessageType.Notice -> {
|
||||
NoticeMessageType(type.content.body, type.content.formatted?.map())
|
||||
|
|
@ -81,7 +97,13 @@ class EventMessageMapper {
|
|||
EmoteMessageType(type.content.body, type.content.formatted?.map())
|
||||
}
|
||||
is RustMessageType.Video -> {
|
||||
VideoMessageType(type.content.body, type.content.formatted?.map(), type.content.filename, type.content.source.map(), type.content.info?.map())
|
||||
VideoMessageType(
|
||||
filename = type.content.filename,
|
||||
caption = type.content.caption,
|
||||
formattedCaption = type.content.formattedCaption?.map(),
|
||||
source = type.content.source.map(),
|
||||
info = type.content.info?.map(),
|
||||
)
|
||||
}
|
||||
is RustMessageType.Location -> {
|
||||
LocationMessageType(type.content.body, type.content.geoUri, type.content.description)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,8 @@ class TimelineEventContentMapper(
|
|||
}
|
||||
is TimelineItemContent.Sticker -> {
|
||||
StickerContent(
|
||||
body = it.body,
|
||||
filename = it.body,
|
||||
body = null,
|
||||
info = it.info.map(),
|
||||
source = it.source.map(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ package io.element.android.libraries.matrix.test.timeline
|
|||
import io.element.android.libraries.matrix.api.core.EventId
|
||||
import io.element.android.libraries.matrix.api.core.TransactionId
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import io.element.android.libraries.matrix.api.media.ImageInfo
|
||||
import io.element.android.libraries.matrix.api.media.MediaSource
|
||||
import io.element.android.libraries.matrix.api.poll.PollAnswer
|
||||
import io.element.android.libraries.matrix.api.poll.PollKind
|
||||
import io.element.android.libraries.matrix.api.timeline.item.TimelineItemDebugInfo
|
||||
|
|
@ -25,6 +27,7 @@ import io.element.android.libraries.matrix.api.timeline.item.event.PollContent
|
|||
import io.element.android.libraries.matrix.api.timeline.item.event.ProfileChangeContent
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.ProfileTimelineDetails
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.Receipt
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.StickerContent
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.TextMessageType
|
||||
import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
||||
import io.element.android.libraries.matrix.test.A_USER_ID
|
||||
|
|
@ -110,6 +113,18 @@ fun aMessageContent(
|
|||
type = messageType
|
||||
)
|
||||
|
||||
fun aStickerContent(
|
||||
filename: String = "filename",
|
||||
info: ImageInfo,
|
||||
mediaSource: MediaSource,
|
||||
body: String? = null,
|
||||
) = StickerContent(
|
||||
filename = filename,
|
||||
body = body,
|
||||
info = info,
|
||||
source = mediaSource,
|
||||
)
|
||||
|
||||
fun aTimelineItemDebugInfo(
|
||||
model: String = "Rust(Model())",
|
||||
originalJson: String? = null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue