-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support tagged events in Room Account Data (MSC2437) #4753
Conversation
02c301c
to
5eabc83
Compare
5eabc83
to
62fdcf5
Compare
62fdcf5
to
3bd2b77
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, removed the variable for now
...c/main/java/org/matrix/android/sdk/internal/session/room/taggedevents/TaggedEventsContent.kt
Show resolved
Hide resolved
} | ||
|
||
data class TaggedEventInfo( | ||
var keywords: List<String>? = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add @Json(name = "keywords")
for code clarity.
Also it could be a val
and not a var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thx
val originServerTs: Long? = null, | ||
|
||
@Json(name = "tagged_at") | ||
var taggedAt: Long? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be a val
and not a var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
val updatedTags = HashMap<String, Map<String, TaggedEventInfo>>(tags) | ||
updatedTags[tag] = tagMap | ||
tags = updatedTags | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a better optimization :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 }
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update
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.