Timeline: use json directly to be a bit more speedy (those methods are called a lot)

This commit is contained in:
ganfra 2021-09-09 19:06:09 +02:00
parent 2144bb9d49
commit f96485c493
14 changed files with 23 additions and 18 deletions

View file

@ -239,7 +239,7 @@ data class Event(
fun Event.isTextMessage(): Boolean { fun Event.isTextMessage(): Boolean {
return getClearType() == EventType.MESSAGE return getClearType() == EventType.MESSAGE
&& when (getClearContent()?.toModel<MessageContent>()?.msgType) { && when (getClearContent()?.get(MessageContent.MSG_TYPE_JSON_KEY)) {
MessageType.MSGTYPE_TEXT, MessageType.MSGTYPE_TEXT,
MessageType.MSGTYPE_EMOTE, MessageType.MSGTYPE_EMOTE,
MessageType.MSGTYPE_NOTICE -> true MessageType.MSGTYPE_NOTICE -> true
@ -249,7 +249,7 @@ fun Event.isTextMessage(): Boolean {
fun Event.isImageMessage(): Boolean { fun Event.isImageMessage(): Boolean {
return getClearType() == EventType.MESSAGE return getClearType() == EventType.MESSAGE
&& when (getClearContent()?.toModel<MessageContent>()?.msgType) { && when (getClearContent()?.get(MessageContent.MSG_TYPE_JSON_KEY)) {
MessageType.MSGTYPE_IMAGE -> true MessageType.MSGTYPE_IMAGE -> true
else -> false else -> false
} }
@ -257,7 +257,7 @@ fun Event.isImageMessage(): Boolean {
fun Event.isVideoMessage(): Boolean { fun Event.isVideoMessage(): Boolean {
return getClearType() == EventType.MESSAGE return getClearType() == EventType.MESSAGE
&& when (getClearContent()?.toModel<MessageContent>()?.msgType) { && when (getClearContent()?.get(MessageContent.MSG_TYPE_JSON_KEY)) {
MessageType.MSGTYPE_VIDEO -> true MessageType.MSGTYPE_VIDEO -> true
else -> false else -> false
} }
@ -265,7 +265,7 @@ fun Event.isVideoMessage(): Boolean {
fun Event.isAudioMessage(): Boolean { fun Event.isAudioMessage(): Boolean {
return getClearType() == EventType.MESSAGE return getClearType() == EventType.MESSAGE
&& when (getClearContent()?.toModel<MessageContent>()?.msgType) { && when (getClearContent()?.get(MessageContent.MSG_TYPE_JSON_KEY)) {
MessageType.MSGTYPE_AUDIO -> true MessageType.MSGTYPE_AUDIO -> true
else -> false else -> false
} }
@ -273,7 +273,7 @@ fun Event.isAudioMessage(): Boolean {
fun Event.isFileMessage(): Boolean { fun Event.isFileMessage(): Boolean {
return getClearType() == EventType.MESSAGE return getClearType() == EventType.MESSAGE
&& when (getClearContent()?.toModel<MessageContent>()?.msgType) { && when (getClearContent()?.get(MessageContent.MSG_TYPE_JSON_KEY)) {
MessageType.MSGTYPE_FILE -> true MessageType.MSGTYPE_FILE -> true
else -> false else -> false
} }
@ -281,7 +281,7 @@ fun Event.isFileMessage(): Boolean {
fun Event.isAttachmentMessage(): Boolean { fun Event.isAttachmentMessage(): Boolean {
return getClearType() == EventType.MESSAGE return getClearType() == EventType.MESSAGE
&& when (getClearContent()?.toModel<MessageContent>()?.msgType) { && when (getClearContent()?.get(MessageContent.MSG_TYPE_JSON_KEY)) {
MessageType.MSGTYPE_IMAGE, MessageType.MSGTYPE_IMAGE,
MessageType.MSGTYPE_AUDIO, MessageType.MSGTYPE_AUDIO,
MessageType.MSGTYPE_VIDEO, MessageType.MSGTYPE_VIDEO,

View file

@ -28,7 +28,7 @@ data class MessageAudioContent(
/** /**
* Required. Must be 'm.audio'. * Required. Must be 'm.audio'.
*/ */
@Json(name = "msgtype") override val msgType: String, @Json(name = MessageContent.MSG_TYPE_JSON_KEY) override val msgType: String,
/** /**
* Required. A description of the audio e.g. 'Bee Gees - Stayin' Alive', or some kind of content description for accessibility e.g. 'audio attachment'. * Required. A description of the audio e.g. 'Bee Gees - Stayin' Alive', or some kind of content description for accessibility e.g. 'audio attachment'.

View file

@ -20,6 +20,11 @@ import org.matrix.android.sdk.api.session.events.model.Content
import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent
interface MessageContent { interface MessageContent {
companion object {
const val MSG_TYPE_JSON_KEY = "msgtype"
}
val msgType: String val msgType: String
val body: String val body: String
val relatesTo: RelationDefaultContent? val relatesTo: RelationDefaultContent?

View file

@ -23,7 +23,7 @@ import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultCon
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class MessageDefaultContent( data class MessageDefaultContent(
@Json(name = "msgtype") override val msgType: String, @Json(name = MessageContent.MSG_TYPE_JSON_KEY) override val msgType: String,
@Json(name = "body") override val body: String, @Json(name = "body") override val body: String,
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null, @Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
@Json(name = "m.new_content") override val newContent: Content? = null @Json(name = "m.new_content") override val newContent: Content? = null

View file

@ -26,7 +26,7 @@ data class MessageEmoteContent(
/** /**
* Required. Must be 'm.emote'. * Required. Must be 'm.emote'.
*/ */
@Json(name = "msgtype") override val msgType: String, @Json(name = MessageContent.MSG_TYPE_JSON_KEY) override val msgType: String,
/** /**
* Required. The emote action to perform. * Required. The emote action to perform.

View file

@ -28,7 +28,7 @@ data class MessageFileContent(
/** /**
* Required. Must be 'm.file'. * Required. Must be 'm.file'.
*/ */
@Json(name = "msgtype") override val msgType: String, @Json(name = MessageContent.MSG_TYPE_JSON_KEY) override val msgType: String,
/** /**
* Required. A human-readable description of the file. This is recommended to be the filename of the original upload. * Required. A human-readable description of the file. This is recommended to be the filename of the original upload.

View file

@ -27,7 +27,7 @@ data class MessageImageContent(
/** /**
* Required. Must be 'm.image'. * Required. Must be 'm.image'.
*/ */
@Json(name = "msgtype") override val msgType: String, @Json(name = MessageContent.MSG_TYPE_JSON_KEY) override val msgType: String,
/** /**
* Required. A textual representation of the image. This could be the alt text of the image, the filename of the image, * Required. A textual representation of the image. This could be the alt text of the image, the filename of the image,

View file

@ -26,7 +26,7 @@ data class MessageLocationContent(
/** /**
* Required. Must be 'm.location'. * Required. Must be 'm.location'.
*/ */
@Json(name = "msgtype") override val msgType: String, @Json(name = MessageContent.MSG_TYPE_JSON_KEY) override val msgType: String,
/** /**
* Required. A description of the location e.g. 'Big Ben, London, UK', or some kind * Required. A description of the location e.g. 'Big Ben, London, UK', or some kind

View file

@ -26,7 +26,7 @@ data class MessageNoticeContent(
/** /**
* Required. Must be 'm.notice'. * Required. Must be 'm.notice'.
*/ */
@Json(name = "msgtype") override val msgType: String, @Json(name = MessageContent.MSG_TYPE_JSON_KEY) override val msgType: String,
/** /**
* Required. The notice text to send. * Required. The notice text to send.

View file

@ -30,7 +30,7 @@ const val OPTION_TYPE_BUTTONS = "org.matrix.buttons"
*/ */
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class MessageOptionsContent( data class MessageOptionsContent(
@Json(name = "msgtype") override val msgType: String = MessageType.MSGTYPE_OPTIONS, @Json(name = MessageContent.MSG_TYPE_JSON_KEY) override val msgType: String = MessageType.MSGTYPE_OPTIONS,
@Json(name = "type") val optionType: String? = null, @Json(name = "type") val optionType: String? = null,
@Json(name = "body") override val body: String, @Json(name = "body") override val body: String,
@Json(name = "label") val label: String?, @Json(name = "label") val label: String?,

View file

@ -26,7 +26,7 @@ import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultCon
*/ */
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class MessagePollResponseContent( data class MessagePollResponseContent(
@Json(name = "msgtype") override val msgType: String = MessageType.MSGTYPE_RESPONSE, @Json(name = MessageContent.MSG_TYPE_JSON_KEY) override val msgType: String = MessageType.MSGTYPE_RESPONSE,
@Json(name = "body") override val body: String, @Json(name = "body") override val body: String,
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null, @Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
@Json(name = "m.new_content") override val newContent: Content? = null @Json(name = "m.new_content") override val newContent: Content? = null

View file

@ -26,7 +26,7 @@ data class MessageTextContent(
/** /**
* Required. Must be 'm.text'. * Required. Must be 'm.text'.
*/ */
@Json(name = "msgtype") override val msgType: String, @Json(name = MessageContent.MSG_TYPE_JSON_KEY) override val msgType: String,
/** /**
* Required. The body of the message. * Required. The body of the message.

View file

@ -24,7 +24,7 @@ import org.matrix.android.sdk.internal.crypto.verification.VerificationInfoReque
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class MessageVerificationRequestContent( data class MessageVerificationRequestContent(
@Json(name = "msgtype") override val msgType: String = MessageType.MSGTYPE_VERIFICATION_REQUEST, @Json(name = MessageContent.MSG_TYPE_JSON_KEY)override val msgType: String = MessageType.MSGTYPE_VERIFICATION_REQUEST,
@Json(name = "body") override val body: String, @Json(name = "body") override val body: String,
@Json(name = "from_device") override val fromDevice: String?, @Json(name = "from_device") override val fromDevice: String?,
@Json(name = "methods") override val methods: List<String>, @Json(name = "methods") override val methods: List<String>,

View file

@ -27,7 +27,7 @@ data class MessageVideoContent(
/** /**
* Required. Must be 'm.video'. * Required. Must be 'm.video'.
*/ */
@Json(name = "msgtype") override val msgType: String, @Json(name = MessageContent.MSG_TYPE_JSON_KEY)override val msgType: String,
/** /**
* Required. A description of the video e.g. 'Gangnam style', or some kind of content description for accessibility e.g. 'video attachment'. * Required. A description of the video e.g. 'Gangnam style', or some kind of content description for accessibility e.g. 'video attachment'.