-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Support tagged events in Room Account Data (MSC2437) |
85 changes: 85 additions & 0 deletions
85
...in/java/org/matrix/android/sdk/internal/session/room/tagged_events/TaggedEventsContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.session.room.tagged_events | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
/** | ||
* Keys are event IDs, values are event information. | ||
*/ | ||
typealias TagEvent = Map<String, TaggedEventInfo> | ||
|
||
/** | ||
* Keys are tag names (eg. m.favourite), values are the related events. | ||
*/ | ||
typealias TagEvents = Map<String, TagEvent> | ||
|
||
/** | ||
* Class used to parse the content of a m.tagged_events type event. | ||
* This kind of event defines the tagged events in a room. | ||
* | ||
* The content of this event is a tags key whose value is an object mapping the name of each tag | ||
* to another object. The JSON object associated with each tag is an object where the keys are the | ||
* event IDs and values give information about the events. | ||
* | ||
* Ref: https://github.com/matrix-org/matrix-doc/pull/2437 | ||
*/ | ||
@JsonClass(generateAdapter = true) | ||
data class TaggedEventsContent( | ||
var tags: TagEvents = emptyMap() | ||
) { | ||
val favouriteEvents | ||
get() = tags[TAG_FAVOURITE].orEmpty() | ||
|
||
val hiddenEvents | ||
get() = tags[TAG_HIDDEN].orEmpty() | ||
|
||
fun tagEvent(eventId: String, info: TaggedEventInfo, tag: String) { | ||
val tagMap = HashMap<String, TaggedEventInfo>(tags[tag] ?: emptyMap()) | ||
tagMap[eventId] = info | ||
|
||
val updatedTags = HashMap<String, Map<String, TaggedEventInfo>>(tags) | ||
updatedTags[tag] = tagMap | ||
tags = updatedTags | ||
} | ||
|
||
fun untagEvent(eventId: String, tag: String) { | ||
val tagMap = HashMap<String, TaggedEventInfo>(tags[tag] ?: emptyMap()) | ||
tagMap.remove(eventId) | ||
|
||
val updatedTags = HashMap<String, Map<String, TaggedEventInfo>>(tags) | ||
updatedTags[tag] = tagMap | ||
tags = updatedTags | ||
} | ||
|
||
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<String>? = null, | ||
|
||
@Json(name = "origin_server_ts") | ||
val originServerTs: Long? = null, | ||
|
||
@Json(name = "tagged_at") | ||
var taggedAt: Long? = null | ||
) |