forked from mystiq/hydrogen-web
log opening timeline
also load the timeline when opening it in the room, so logging starts in the room (and we don't need to pass the logger to Timeline) and also API-wise it makes more sense to not return uninitialized objects
This commit is contained in:
parent
29df61eb8a
commit
1093895133
3 changed files with 29 additions and 32 deletions
|
@ -41,12 +41,12 @@ export class RoomViewModel extends ViewModel {
|
||||||
async load() {
|
async load() {
|
||||||
this._room.on("change", this._onRoomChange);
|
this._room.on("change", this._onRoomChange);
|
||||||
try {
|
try {
|
||||||
|
const timeline = await this._room.openTimeline();
|
||||||
const timelineVM = this.track(new TimelineViewModel(this.childOptions({
|
const timelineVM = this.track(new TimelineViewModel(this.childOptions({
|
||||||
room: this._room,
|
room: this._room,
|
||||||
timeline: this._room.openTimeline(),
|
timeline,
|
||||||
ownUserId: this._ownUserId,
|
ownUserId: this._ownUserId,
|
||||||
})));
|
})));
|
||||||
await timelineVM.load();
|
|
||||||
this._timelineVM = timelineVM;
|
this._timelineVM = timelineVM;
|
||||||
this.emitChange("timelineViewModel");
|
this.emitChange("timelineViewModel");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -40,16 +40,9 @@ export class TimelineViewModel extends ViewModel {
|
||||||
super(options);
|
super(options);
|
||||||
const {room, timeline, ownUserId} = options;
|
const {room, timeline, ownUserId} = options;
|
||||||
this._timeline = this.track(timeline);
|
this._timeline = this.track(timeline);
|
||||||
// once we support sending messages we could do
|
|
||||||
// timeline.entries.concat(timeline.pendingEvents)
|
|
||||||
// for an ObservableList that also contains local echos
|
|
||||||
this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, ownUserId})));
|
this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, ownUserId})));
|
||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
|
||||||
await this._timeline.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {bool} startReached if the start of the timeline was reached
|
* @return {bool} startReached if the start of the timeline was reached
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -575,30 +575,34 @@ export class Room extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
openTimeline() {
|
openTimeline(log = null) {
|
||||||
if (this._timeline) {
|
return this._platform.logger.wrapOrRun(log, "open timeline", async log => {
|
||||||
throw new Error("not dealing with load race here for now");
|
log.set("id", this.id);
|
||||||
}
|
if (this._timeline) {
|
||||||
console.log(`opening the timeline for ${this._roomId}`);
|
throw new Error("not dealing with load race here for now");
|
||||||
this._timeline = new Timeline({
|
}
|
||||||
roomId: this.id,
|
console.log(`opening the timeline for ${this._roomId}`);
|
||||||
storage: this._storage,
|
this._timeline = new Timeline({
|
||||||
fragmentIdComparer: this._fragmentIdComparer,
|
roomId: this.id,
|
||||||
pendingEvents: this._sendQueue.pendingEvents,
|
storage: this._storage,
|
||||||
closeCallback: () => {
|
fragmentIdComparer: this._fragmentIdComparer,
|
||||||
console.log(`closing the timeline for ${this._roomId}`);
|
pendingEvents: this._sendQueue.pendingEvents,
|
||||||
this._timeline = null;
|
closeCallback: () => {
|
||||||
if (this._roomEncryption) {
|
this._timeline = null;
|
||||||
this._roomEncryption.notifyTimelineClosed();
|
if (this._roomEncryption) {
|
||||||
}
|
this._roomEncryption.notifyTimelineClosed();
|
||||||
},
|
}
|
||||||
user: this._user,
|
},
|
||||||
clock: this._platform.clock
|
user: this._user,
|
||||||
|
clock: this._platform.clock,
|
||||||
|
logger: this._platform.logger,
|
||||||
|
});
|
||||||
|
if (this._roomEncryption) {
|
||||||
|
this._timeline.enableEncryption(this._decryptEntries.bind(this, DecryptionSource.Timeline));
|
||||||
|
}
|
||||||
|
await this._timeline.load();
|
||||||
|
return this._timeline;
|
||||||
});
|
});
|
||||||
if (this._roomEncryption) {
|
|
||||||
this._timeline.enableEncryption(this._decryptEntries.bind(this, DecryptionSource.Timeline));
|
|
||||||
}
|
|
||||||
return this._timeline;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get mediaRepository() {
|
get mediaRepository() {
|
||||||
|
|
Loading…
Reference in a new issue