Support tagged events in Room Account Data (MSC2437)#4753
Conversation
02c301c to
5eabc83
Compare
5eabc83 to
62fdcf5
Compare
62fdcf5 to
3bd2b77
Compare
bmarty
left a comment
There was a problem hiding this comment.
Thanks, some small remarks and suggested change.
I guess the next step is to add some API to the SDK services to let the app play with tags?
Also m.hidden events should be hidden from the timeline, and it should be handled by default by the SDK (CC @ganfra).
| } | ||
|
|
||
| companion object { | ||
| const val TAGS_KEY = "tags" |
There was a problem hiding this comment.
TAGS_KEY is useless. Better to define a string in the data class TaggedEventsContent (see my other remark there)
There was a problem hiding this comment.
I agree, removed the variable for now
| } | ||
|
|
||
| data class TaggedEventInfo( | ||
| var keywords: List<String>? = null, |
There was a problem hiding this comment.
Please add @Json(name = "keywords") for code clarity.
Also it could be a val and not a var
| val originServerTs: Long? = null, | ||
|
|
||
| @Json(name = "tagged_at") | ||
| var taggedAt: Long? = null |
| val updatedTags = HashMap<String, Map<String, TaggedEventInfo>>(tags) | ||
| updatedTags[tag] = tagMap | ||
| tags = updatedTags | ||
| } |
There was a problem hiding this comment.
I propose to rewrite to
fun tagEvent(eventId: String, tag: String, info: TaggedEventInfo) {
val tagMap = tags[tag].orEmpty().toMutableMap()
.also { it[eventId] = info }
tags = tags.toMutableMap().also { it[tag] = tagMap }
}There was a problem hiding this comment.
I found a better optimization :)
There was a problem hiding this comment.
TIL the plus() and minus() operator extensions on Map. Note that it can be written using + and - but for code clarity I prefer what you have done. Thanks!
| val updatedTags = HashMap<String, Map<String, TaggedEventInfo>>(tags) | ||
| updatedTags[tag] = tagMap | ||
| tags = updatedTags | ||
| } |
There was a problem hiding this comment.
I propose to rewrite to:
fun untagEvent(eventId: String, tag: String) {
val tagMap = tags[tag]?.toMutableMap() ?: return
tagMap.remove(eventId)
tags = tags.toMutableMap().also { it[tag] = tagMap }
}|
Small change after merge: 401479f |
Introduce tagged_events model in the matrix SDK.
This event is stored in the Room Account Data. Clients can use it to identify some state_events (as favourites for example), see the related MSC to learn more about it.