From dbb812ad846848777f50573cc4f666fbe5f62c7a Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 21 Jan 2019 18:16:15 +0100 Subject: [PATCH] Message type : add data classes for all the types --- .../detail/timeline/MessageItemFactory.kt | 45 ++++++++++++------- .../{MessageItem.kt => MessageTextItem.kt} | 2 +- .../session/room/model/message/AudioInfo.kt | 11 +++++ .../session/room/model/message/FileInfo.kt | 12 +++++ .../session/room/model/message/ImageInfo.kt | 16 +++++++ .../room/model/message/LocationInfo.kt | 10 +++++ .../room/model/message/MessageAudioContent.kt | 12 +++++ .../room/model/message/MessageContent.kt | 6 +++ .../model/message/MessageDefaultContent.kt | 10 +++++ .../room/model/message/MessageEmoteContent.kt | 12 +++++ .../room/model/message/MessageFileContent.kt | 13 ++++++ .../room/model/message/MessageImageContent.kt | 12 +++++ .../model/message/MessageLocationContent.kt | 12 +++++ .../model/message/MessageNoticeContent.kt | 12 +++++ .../MessageTextContent.kt} | 12 +++-- .../room/model/{ => message}/MessageType.kt | 2 +- .../room/model/message/MessageVideoContent.kt | 12 +++++ .../room/model/message/ThumbnailInfo.kt | 12 +++++ .../session/room/model/message/VideoInfo.kt | 15 +++++++ .../api/session/room/send/EventFactory.kt | 6 +-- .../android/internal/di/MoshiProvider.kt | 21 +++++++++ 21 files changed, 238 insertions(+), 27 deletions(-) rename app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/{MessageItem.kt => MessageTextItem.kt} (98%) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/AudioInfo.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/FileInfo.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ImageInfo.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/LocationInfo.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageContent.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageDefaultContent.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageEmoteContent.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageLocationContent.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageNoticeContent.kt rename matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/{MessageContent.kt => message/MessageTextContent.kt} (50%) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/{ => message}/MessageType.kt (90%) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ThumbnailInfo.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/VideoInfo.kt diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt index 58a7bb17e2..e77b150c01 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt @@ -7,7 +7,8 @@ import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.TimelineEvent import im.vector.matrix.android.api.session.events.model.toModel -import im.vector.matrix.android.api.session.room.model.MessageContent +import im.vector.matrix.android.api.session.room.model.message.MessageContent +import im.vector.matrix.android.api.session.room.model.message.MessageTextContent import im.vector.riotredesign.core.extensions.localDateTime class MessageItemFactory(private val timelineDateFormatter: TimelineDateFormatter) { @@ -17,28 +18,43 @@ class MessageItemFactory(private val timelineDateFormatter: TimelineDateFormatte fun create(event: TimelineEvent, nextEvent: TimelineEvent?, callback: TimelineEventController.Callback? - ): MessageItem? { + ): MessageTextItem? { - val messageContent: MessageContent? = event.root.content.toModel() val roomMember = event.roomMember - if (messageContent == null) { - return null - } val nextRoomMember = nextEvent?.roomMember val date = event.root.localDateTime() val nextDate = nextEvent?.root?.localDateTime() val addDaySeparator = date.toLocalDate() != nextDate?.toLocalDate() val isNextMessageReceivedMoreThanOneHourAgo = nextDate?.isBefore(date.minusMinutes(60)) - ?: false + ?: false if (addDaySeparator - || nextRoomMember != roomMember - || nextEvent?.root?.type != EventType.MESSAGE - || isNextMessageReceivedMoreThanOneHourAgo) { + || nextRoomMember != roomMember + || nextEvent?.root?.type != EventType.MESSAGE + || isNextMessageReceivedMoreThanOneHourAgo) { messagesDisplayedWithInformation.add(event.root.eventId) } + val messageContent: MessageContent = event.root.content.toModel() ?: return null + val showInformation = messagesDisplayedWithInformation.contains(event.root.eventId) + val time = timelineDateFormatter.formatMessageHour(date) + val avatarUrl = roomMember?.avatarUrl + val memberName = roomMember?.displayName ?: event.root.sender + + return when (messageContent) { + is MessageTextContent -> buildTextMessageItem(messageContent, memberName, avatarUrl, time, showInformation, callback) + else -> null + } + } + + private fun buildTextMessageItem(messageContent: MessageTextContent, + memberName: String?, + avatarUrl: String?, + time: String, + showInformation: Boolean, + callback: TimelineEventController.Callback?): MessageTextItem? { + val message = messageContent.body?.let { val spannable = SpannableStringBuilder(it) MatrixLinkify.addLinks(spannable, object : MatrixPermalinkSpan.Callback { @@ -49,13 +65,12 @@ class MessageItemFactory(private val timelineDateFormatter: TimelineDateFormatte Linkify.addLinks(spannable, Linkify.ALL) spannable } - val showInformation = messagesDisplayedWithInformation.contains(event.root.eventId) - return MessageItem( + return MessageTextItem( message = message, - avatarUrl = roomMember?.avatarUrl, + avatarUrl = avatarUrl, showInformation = showInformation, - time = timelineDateFormatter.formatMessageHour(date), - memberName = roomMember?.displayName ?: event.root.sender + time = time, + memberName = memberName ) } diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItem.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageTextItem.kt similarity index 98% rename from app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItem.kt rename to app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageTextItem.kt index 4aae5dd2ed..e75a96afd9 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItem.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageTextItem.kt @@ -8,7 +8,7 @@ import im.vector.riotredesign.R import im.vector.riotredesign.core.epoxy.KotlinModel import im.vector.riotredesign.features.home.AvatarRenderer -class MessageItem( +class MessageTextItem( val message: CharSequence? = null, val time: CharSequence? = null, val avatarUrl: String?, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/AudioInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/AudioInfo.kt new file mode 100644 index 0000000000..32670078af --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/AudioInfo.kt @@ -0,0 +1,11 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class AudioInfo( + @Json(name = "mimetype") val mimeType: String, + @Json(name = "size") val size: Long, + @Json(name = "duration") val duration: Int +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/FileInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/FileInfo.kt new file mode 100644 index 0000000000..75c263d9ca --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/FileInfo.kt @@ -0,0 +1,12 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class FileInfo( + @Json(name = "mimetype") val mimeType: String, + @Json(name = "size") val size: Long, + @Json(name = "thumbnail_info") val thumbnailInfo: ThumbnailInfo? = null, + @Json(name = "thumbnail_url") val thumbnailUrl: String? = null +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ImageInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ImageInfo.kt new file mode 100644 index 0000000000..f636c82c36 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ImageInfo.kt @@ -0,0 +1,16 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ImageInfo( + @Json(name = "mimetype") val mimeType: String, + @Json(name = "w") val w: Int, + @Json(name = "h") val h: Int, + @Json(name = "size") val size: Long, + @Json(name = "rotation") val rotation: Int? = null, + @Json(name = "orientation") val orientation: Int? = null, + @Json(name = "thumbnail_info") val thumbnailInfo: ThumbnailInfo? = null, + @Json(name = "thumbnail_url") val thumbnailUrl: String? = null +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/LocationInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/LocationInfo.kt new file mode 100644 index 0000000000..ee1c98877c --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/LocationInfo.kt @@ -0,0 +1,10 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class LocationInfo( + @Json(name = "thumbnail_url") val thumbnailUrl: String, + @Json(name = "thumbnail_info") val thumbnailInfo: ThumbnailInfo +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt new file mode 100644 index 0000000000..33e17d5cb3 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageAudioContent.kt @@ -0,0 +1,12 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class MessageAudioContent( + @Json(name = "msgtype") override val type: String, + @Json(name = "body") override val body: String, + @Json(name = "info") val info: AudioInfo, + @Json(name = "url") val url: String? = null +) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageContent.kt new file mode 100644 index 0000000000..93c89bc287 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageContent.kt @@ -0,0 +1,6 @@ +package im.vector.matrix.android.api.session.room.model.message + +interface MessageContent { + val type: String + val body: String +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageDefaultContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageDefaultContent.kt new file mode 100644 index 0000000000..7f6dc34c35 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageDefaultContent.kt @@ -0,0 +1,10 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class MessageDefaultContent( + @Json(name = "msgtype") override val type: String, + @Json(name = "body") override val body: String +) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageEmoteContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageEmoteContent.kt new file mode 100644 index 0000000000..297a01624a --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageEmoteContent.kt @@ -0,0 +1,12 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class MessageEmoteContent( + @Json(name = "msgtype") override val type: String, + @Json(name = "body") override val body: String, + @Json(name = "format") val format: String? = null, + @Json(name = "formatted_body") val formattedBody: String? = null +) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt new file mode 100644 index 0000000000..9e542569e1 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageFileContent.kt @@ -0,0 +1,13 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class MessageFileContent( + @Json(name = "msgtype") override val type: String, + @Json(name = "body") override val body: String, + @Json(name = "filename") val filename: String, + @Json(name = "info") val info: FileInfo, + @Json(name = "url") val url: String? = null +) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt new file mode 100644 index 0000000000..34e4bc4cdb --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageImageContent.kt @@ -0,0 +1,12 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class MessageImageContent( + @Json(name = "msgtype") override val type: String, + @Json(name = "body") override val body: String, + @Json(name = "info") val info: ImageInfo, + @Json(name = "url") val url: String? = null +) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageLocationContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageLocationContent.kt new file mode 100644 index 0000000000..d45fd21b8e --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageLocationContent.kt @@ -0,0 +1,12 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class MessageLocationContent( + @Json(name = "msgtype") override val type: String, + @Json(name = "body") override val body: String, + @Json(name = "geo_uri") val geoUri: String, + @Json(name = "info") val info: LocationInfo +) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageNoticeContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageNoticeContent.kt new file mode 100644 index 0000000000..eda19bcc67 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageNoticeContent.kt @@ -0,0 +1,12 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class MessageNoticeContent( + @Json(name = "msgtype") override val type: String, + @Json(name = "body") override val body: String, + @Json(name = "format") val format: String? = null, + @Json(name = "formatted_body") val formattedBody: String? = null +) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/MessageContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageTextContent.kt similarity index 50% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/MessageContent.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageTextContent.kt index 49a3ad6a6a..e109250af7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/MessageContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageTextContent.kt @@ -1,14 +1,12 @@ -package im.vector.matrix.android.api.session.room.model +package im.vector.matrix.android.api.session.room.model.message import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) -data class MessageContent( - - @Json(name = "msgtype") val type: String? = null, - @Json(name = "body") val body: String? = null, +data class MessageTextContent( + @Json(name = "msgtype") override val type: String, + @Json(name = "body") override val body: String, @Json(name = "format") val format: String? = null, @Json(name = "formatted_body") val formattedBody: String? = null - -) \ No newline at end of file +) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/MessageType.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageType.kt similarity index 90% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/MessageType.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageType.kt index 6ffebca66d..ab3e7f7544 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/MessageType.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageType.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.session.room.model +package im.vector.matrix.android.api.session.room.model.message object MessageType { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt new file mode 100644 index 0000000000..c817c13b13 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVideoContent.kt @@ -0,0 +1,12 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class MessageVideoContent( + @Json(name = "msgtype") override val type: String, + @Json(name = "body") override val body: String, + @Json(name = "info") val info: VideoInfo, + @Json(name = "url") val url: String? = null +) : MessageContent \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ThumbnailInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ThumbnailInfo.kt new file mode 100644 index 0000000000..50084b5d78 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/ThumbnailInfo.kt @@ -0,0 +1,12 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ThumbnailInfo( + @Json(name = "w") val width: Int, + @Json(name = "h") val height: Int, + @Json(name = "size") val size: Long, + @Json(name = "mimetype") val mimeType: String +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/VideoInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/VideoInfo.kt new file mode 100644 index 0000000000..6ca32e9969 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/VideoInfo.kt @@ -0,0 +1,15 @@ +package im.vector.matrix.android.api.session.room.model.message + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class VideoInfo( + @Json(name = "mimetype") val mimeType: String, + @Json(name = "w") val w: Int, + @Json(name = "h") val h: Int, + @Json(name = "size") val size: Long, + @Json(name = "duration") val duration: Int, + @Json(name = "thumbnail_info") val thumbnailInfo: ThumbnailInfo? = null, + @Json(name = "thumbnail_url") val thumbnailUrl: String? = null +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/send/EventFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/send/EventFactory.kt index 2dafe5036b..1bdaf5d60e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/send/EventFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/send/EventFactory.kt @@ -4,8 +4,8 @@ import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.session.events.model.Content import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType -import im.vector.matrix.android.api.session.room.model.MessageContent -import im.vector.matrix.android.api.session.room.model.MessageType +import im.vector.matrix.android.api.session.room.model.message.MessageTextContent +import im.vector.matrix.android.api.session.room.model.message.MessageType import im.vector.matrix.android.internal.di.MoshiProvider internal class EventFactory(private val credentials: Credentials) { @@ -13,7 +13,7 @@ internal class EventFactory(private val credentials: Credentials) { private val moshi = MoshiProvider.providesMoshi() fun createTextEvent(roomId: String, text: String): Event { - val content = MessageContent(type = MessageType.MSGTYPE_TEXT, body = text) + val content = MessageTextContent(type = MessageType.MSGTYPE_TEXT, body = text) return Event( roomId = roomId, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MoshiProvider.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MoshiProvider.kt index 1cabe215f0..984b90bddc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MoshiProvider.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MoshiProvider.kt @@ -1,6 +1,17 @@ package im.vector.matrix.android.internal.di import com.squareup.moshi.Moshi +import im.vector.matrix.android.api.session.room.model.message.MessageAudioContent +import im.vector.matrix.android.api.session.room.model.message.MessageContent +import im.vector.matrix.android.api.session.room.model.message.MessageDefaultContent +import im.vector.matrix.android.api.session.room.model.message.MessageEmoteContent +import im.vector.matrix.android.api.session.room.model.message.MessageFileContent +import im.vector.matrix.android.api.session.room.model.message.MessageImageContent +import im.vector.matrix.android.api.session.room.model.message.MessageLocationContent +import im.vector.matrix.android.api.session.room.model.message.MessageNoticeContent +import im.vector.matrix.android.api.session.room.model.message.MessageTextContent +import im.vector.matrix.android.api.session.room.model.message.MessageType +import im.vector.matrix.android.api.session.room.model.message.MessageVideoContent import im.vector.matrix.android.internal.network.parsing.RuntimeJsonAdapterFactory import im.vector.matrix.android.internal.network.parsing.UriMoshiAdapter import im.vector.matrix.android.internal.session.sync.model.UserAccountData @@ -14,6 +25,16 @@ object MoshiProvider { .add(RuntimeJsonAdapterFactory.of(UserAccountData::class.java, "type", UserAccountDataFallback::class.java) .registerSubtype(UserAccountDataDirectMessages::class.java, UserAccountData.TYPE_DIRECT_MESSAGES) ) + .add(RuntimeJsonAdapterFactory.of(MessageContent::class.java, "msgtype", MessageDefaultContent::class.java) + .registerSubtype(MessageTextContent::class.java, MessageType.MSGTYPE_TEXT) + .registerSubtype(MessageNoticeContent::class.java, MessageType.MSGTYPE_NOTICE) + .registerSubtype(MessageEmoteContent::class.java, MessageType.MSGTYPE_EMOTE) + .registerSubtype(MessageAudioContent::class.java, MessageType.MSGTYPE_AUDIO) + .registerSubtype(MessageImageContent::class.java, MessageType.MSGTYPE_IMAGE) + .registerSubtype(MessageVideoContent::class.java, MessageType.MSGTYPE_VIDEO) + .registerSubtype(MessageLocationContent::class.java, MessageType.MSGTYPE_LOCATION) + .registerSubtype(MessageFileContent::class.java, MessageType.MSGTYPE_FILE) + ) .build() fun providesMoshi(): Moshi {