1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-19 16:42:09 +03:00
Files
matrix-js-sdk/lib/models/room.js
Kegan Dougal 9fa7fa0487 Shuffle around how events are stored.
Rather than having MatrixInMemoryStore do it all, we make the right object do
the right thing, and keep the store for storing said objects.
2015-06-08 15:43:18 +01:00

53 lines
1.6 KiB
JavaScript

"use strict";
/**
* @module models/room
*/
var RoomState = require("./room-state");
/**
* Construct a new Room.
* @constructor
* @param {string} roomId Required. The ID of this room.
* @prop {string} roomId The ID of this room.
* @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 {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
* newest event in the timeline.
* @prop {RoomSummary} summary The room summary.
*/
function Room(roomId) {
this.roomId = roomId;
this.name = roomId;
this.timeline = [];
this.oldState = new RoomState(roomId);
this.currentState = new RoomState(roomId);
this.summary = null;
}
Room.prototype = {
/**
* Add some events to this room's timeline.
* @param {MatrixEvent[]} events A list of events to add.
* @param {boolean} toStartOfTimeline True to add these events to the start
* (oldest) instead of the end (newest) of the timeline. If true, the oldest
* event will be the <b>last</b> element of 'events'.
*/
addEventsToTimeline: function(events, toStartOfTimeline) {
for (var i = 0; i < events.length; i++) {
if (toStartOfTimeline) {
this.timeline.unshift(events[i]);
}
else {
this.timeline.push(events[i]);
}
}
}
};
/**
* The Room class.
*/
module.exports = Room;