Code review
This commit is contained in:
parent
f008abde4f
commit
daadf72ffe
|
@ -41,6 +41,7 @@ typealias TaggedEvents = Map<String, TaggedEvent>
|
||||||
*/
|
*/
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class TaggedEventsContent(
|
data class TaggedEventsContent(
|
||||||
|
@Json(name = "tags")
|
||||||
var tags: TaggedEvents = emptyMap()
|
var tags: TaggedEvents = emptyMap()
|
||||||
) {
|
) {
|
||||||
val favouriteEvents
|
val favouriteEvents
|
||||||
|
@ -50,36 +51,28 @@ data class TaggedEventsContent(
|
||||||
get() = tags[TAG_HIDDEN].orEmpty()
|
get() = tags[TAG_HIDDEN].orEmpty()
|
||||||
|
|
||||||
fun tagEvent(eventId: String, info: TaggedEventInfo, tag: String) {
|
fun tagEvent(eventId: String, info: TaggedEventInfo, tag: String) {
|
||||||
val tagMap = HashMap<String, TaggedEventInfo>(tags[tag] ?: emptyMap())
|
val taggedEvents = tags[tag].orEmpty().plus(eventId to info)
|
||||||
tagMap[eventId] = info
|
tags = tags.plus(tag to taggedEvents)
|
||||||
|
|
||||||
val updatedTags = HashMap<String, Map<String, TaggedEventInfo>>(tags)
|
|
||||||
updatedTags[tag] = tagMap
|
|
||||||
tags = updatedTags
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun untagEvent(eventId: String, tag: String) {
|
fun untagEvent(eventId: String, tag: String) {
|
||||||
val tagMap = HashMap<String, TaggedEventInfo>(tags[tag] ?: emptyMap())
|
val taggedEvents = tags[tag]?.minus(eventId).orEmpty()
|
||||||
tagMap.remove(eventId)
|
tags = tags.plus(tag to taggedEvents)
|
||||||
|
|
||||||
val updatedTags = HashMap<String, Map<String, TaggedEventInfo>>(tags)
|
|
||||||
updatedTags[tag] = tagMap
|
|
||||||
tags = updatedTags
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAGS_KEY = "tags"
|
|
||||||
const val TAG_FAVOURITE = "m.favourite"
|
const val TAG_FAVOURITE = "m.favourite"
|
||||||
const val TAG_HIDDEN = "m.hidden"
|
const val TAG_HIDDEN = "m.hidden"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class TaggedEventInfo(
|
data class TaggedEventInfo(
|
||||||
var keywords: List<String>? = null,
|
@Json(name = "keywords")
|
||||||
|
val keywords: List<String>? = null,
|
||||||
|
|
||||||
@Json(name = "origin_server_ts")
|
@Json(name = "origin_server_ts")
|
||||||
val originServerTs: Long? = null,
|
val originServerTs: Long? = null,
|
||||||
|
|
||||||
@Json(name = "tagged_at")
|
@Json(name = "tagged_at")
|
||||||
var taggedAt: Long? = null
|
val taggedAt: Long? = null
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue