2019-03-09 00:28:54 +05:30
|
|
|
import EventEmitter from "../../../EventEmitter.js";
|
2019-02-28 03:20:08 +05:30
|
|
|
|
|
|
|
export default class RoomViewModel extends EventEmitter {
|
|
|
|
constructor(room) {
|
|
|
|
super();
|
|
|
|
this._room = room;
|
|
|
|
this._timeline = null;
|
|
|
|
this._onRoomChange = this._onRoomChange.bind(this);
|
2019-03-09 05:13:43 +05:30
|
|
|
this._timelineError = null;
|
2019-02-28 03:20:08 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
async enable() {
|
|
|
|
this._room.on("change", this._onRoomChange);
|
2019-03-09 05:13:43 +05:30
|
|
|
try {
|
|
|
|
this._timeline = await this._room.openTimeline();
|
|
|
|
this.emit("change", "timelineEntries");
|
|
|
|
} catch (err) {
|
|
|
|
this._timelineError = err;
|
|
|
|
this.emit("change", "error");
|
|
|
|
}
|
2019-02-28 03:20:08 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
disable() {
|
|
|
|
if (this._timeline) {
|
|
|
|
this._timeline.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// room doesn't tell us yet which fields changed,
|
|
|
|
// so emit all fields originating from summary
|
|
|
|
_onRoomChange() {
|
|
|
|
this.emit("change", "name");
|
|
|
|
}
|
|
|
|
|
|
|
|
get name() {
|
|
|
|
return this._room.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
get timelineEntries() {
|
|
|
|
return this._timeline && this._timeline.entries;
|
|
|
|
}
|
2019-03-09 05:13:43 +05:30
|
|
|
|
|
|
|
get error() {
|
|
|
|
if (this._timelineError) {
|
|
|
|
return `Something went wrong loading the timeline: ${this._timelineError.message}`;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2019-02-28 03:20:08 +05:30
|
|
|
}
|