You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2026-01-03 23:22:30 +03:00
add support for tracking room tags
This commit is contained in:
@@ -21,6 +21,8 @@ var ContentRepo = require("../content-repo");
|
||||
* @prop {string} name The human-readable display name for this room.
|
||||
* @prop {Array<MatrixEvent>} timeline The ordered list of message events for
|
||||
* this room.
|
||||
* @prop {object} tags Dict of room tags; the keys are the tag name and the values
|
||||
* are any metadata associated with the tag - e.g. { "fav" : { order: 1 } }
|
||||
* @prop {RoomState} oldState The state of the room at the time of the oldest
|
||||
* event in the timeline.
|
||||
* @prop {RoomState} currentState The state of the room at the time of the
|
||||
@@ -33,6 +35,10 @@ function Room(roomId, storageToken) {
|
||||
this.roomId = roomId;
|
||||
this.name = roomId;
|
||||
this.timeline = [];
|
||||
this.tags = {
|
||||
// $tagname: { $metadata: $value },
|
||||
// $tagname: { $metadata: $value },
|
||||
};
|
||||
this.oldState = new RoomState(roomId);
|
||||
this.currentState = new RoomState(roomId);
|
||||
this.summary = null;
|
||||
@@ -223,6 +229,9 @@ Room.prototype.addEvents = function(events, duplicateStrategy) {
|
||||
else if (events[i].getType() === "m.receipt") {
|
||||
this.addReceipt(events[i]);
|
||||
}
|
||||
else if (events[i].getType() === "m.tag") {
|
||||
this.addTags(events[i]);
|
||||
}
|
||||
else {
|
||||
if (duplicateStrategy) {
|
||||
// is there a duplicate?
|
||||
@@ -401,6 +410,27 @@ Room.prototype.addReceipt = function(event) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the room-tag event for the room. The previous one is overwritten.
|
||||
* @param {MatrixEvent} event the m.tag event
|
||||
*/
|
||||
Room.prototype.addTags = function(event) {
|
||||
// event content looks like:
|
||||
// content: {
|
||||
// tags: {
|
||||
// $tagname: { $metadata: $value },
|
||||
// $tagname: { $metadata: $value },
|
||||
// }
|
||||
// }
|
||||
|
||||
// XXX: we could do a deep-comparison to see if the tags have really
|
||||
// changed - but do we want to bother?
|
||||
this.emit("Room.tags", this);
|
||||
|
||||
// XXX: do we need to deep copy here?
|
||||
this._tags = event.content.tags;
|
||||
};
|
||||
|
||||
function setEventMetadata(event, stateContext, toStartOfTimeline) {
|
||||
// set sender and target properties
|
||||
event.sender = stateContext.getSentinelMember(
|
||||
@@ -527,3 +557,14 @@ module.exports = Room;
|
||||
* var newName = room.name;
|
||||
* });
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fires whenever a room's tags are updated.
|
||||
* @event module:client~MatrixClient#"Room.tags"
|
||||
* @param {Room} room The room whose Room.tags was updated.
|
||||
* @example
|
||||
* matrixClient.on("Room.tags", function(room){
|
||||
* var newTags = room.tags;
|
||||
* if (newTags["favourite"]) showStar(room);
|
||||
* });
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user