From daadf72ffedbc99378f6235d33532c9f83e63076 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Tue, 4 Jan 2022 17:55:51 +0100 Subject: [PATCH] Code review --- .../room/taggedevents/TaggedEventsContent.kt | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/taggedevents/TaggedEventsContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/taggedevents/TaggedEventsContent.kt index 318e8f8ea2..58ca25f1e2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/taggedevents/TaggedEventsContent.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/taggedevents/TaggedEventsContent.kt @@ -41,6 +41,7 @@ typealias TaggedEvents = Map */ @JsonClass(generateAdapter = true) data class TaggedEventsContent( + @Json(name = "tags") var tags: TaggedEvents = emptyMap() ) { val favouriteEvents @@ -50,36 +51,28 @@ data class TaggedEventsContent( get() = tags[TAG_HIDDEN].orEmpty() fun tagEvent(eventId: String, info: TaggedEventInfo, tag: String) { - val tagMap = HashMap(tags[tag] ?: emptyMap()) - tagMap[eventId] = info - - val updatedTags = HashMap>(tags) - updatedTags[tag] = tagMap - tags = updatedTags + val taggedEvents = tags[tag].orEmpty().plus(eventId to info) + tags = tags.plus(tag to taggedEvents) } fun untagEvent(eventId: String, tag: String) { - val tagMap = HashMap(tags[tag] ?: emptyMap()) - tagMap.remove(eventId) - - val updatedTags = HashMap>(tags) - updatedTags[tag] = tagMap - tags = updatedTags + val taggedEvents = tags[tag]?.minus(eventId).orEmpty() + tags = tags.plus(tag to taggedEvents) } companion object { - const val TAGS_KEY = "tags" const val TAG_FAVOURITE = "m.favourite" const val TAG_HIDDEN = "m.hidden" } } data class TaggedEventInfo( - var keywords: List? = null, + @Json(name = "keywords") + val keywords: List? = null, @Json(name = "origin_server_ts") val originServerTs: Long? = null, @Json(name = "tagged_at") - var taggedAt: Long? = null + val taggedAt: Long? = null )