hydrogen-web/src/matrix/room/room.js

29 lines
846 B
JavaScript
Raw Normal View History

2019-02-11 01:55:29 +05:30
import RoomSummary from "./summary.js";
import RoomPersister from "./persister.js";
2019-02-21 04:18:16 +05:30
import EventEmitter from "../../EventEmitter.js";
2018-12-21 19:05:24 +05:30
2019-02-21 04:18:16 +05:30
export default class Room extends EventEmitter {
constructor(roomId, storage, emitCollectionChange) {
super();
2018-12-21 19:05:24 +05:30
this._roomId = roomId;
this._storage = storage;
2019-02-11 01:55:29 +05:30
this._summary = new RoomSummary(roomId);
this._persister = new RoomPersister(roomId);
2019-02-21 04:18:16 +05:30
this._emitCollectionChange = emitCollectionChange;
2018-12-21 19:05:24 +05:30
}
2019-02-11 01:55:29 +05:30
async applySync(roomResponse, membership, txn) {
2019-02-21 04:18:16 +05:30
const changed = this._summary.applySync(roomResponse, membership, txn);
2019-02-11 01:55:29 +05:30
this._persister.persistSync(roomResponse, txn);
2019-02-21 04:18:16 +05:30
if (changed) {
this.emit("change");
2019-02-24 23:55:06 +05:30
(this._emitCollectionChange)(this);
2019-02-21 04:18:16 +05:30
}
2018-12-21 19:05:24 +05:30
}
2019-02-11 01:55:29 +05:30
load(summary, txn) {
this._summary.load(summary);
return this._persister.load(txn);
2018-12-21 19:05:24 +05:30
}
2019-02-21 04:18:16 +05:30
}