diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 59bcd52f..a2ea5f66 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -38,7 +38,7 @@ export class RoomViewModel extends ViewModel { async load() { this._room.on("change", this._onRoomChange); try { - this._timeline = this._room.openTimeline(); + this._timeline = this.track(this._room.openTimeline()); await this._timeline.load(); this._timelineVM = new TimelineViewModel(this.childOptions({ room: this._room, @@ -63,17 +63,15 @@ export class RoomViewModel extends ViewModel { } dispose() { - // this races with enable, on the await openTimeline() - if (this._timeline) { - // will stop the timeline from delivering updates on entries - this._timeline.close(); - } + super.dispose(); if (this._clearUnreadTimout) { this._clearUnreadTimout.abort(); this._clearUnreadTimout = null; } } + // called from view to close room + // parent vm will dispose this vm close() { this._closeCallback(); } diff --git a/src/matrix/e2ee/RoomEncryption.js b/src/matrix/e2ee/RoomEncryption.js index 544081b3..44229b97 100644 --- a/src/matrix/e2ee/RoomEncryption.js +++ b/src/matrix/e2ee/RoomEncryption.js @@ -292,11 +292,9 @@ class BatchDecryptionResult { constructor(results, errors) { this.results = results; this.errors = errors; - console.log("BatchDecryptionResult", this); } applyToEntries(entries) { - console.log("BatchDecryptionResult.applyToEntries", this); for (const entry of entries) { const result = this.results.get(entry.id); if (result) { diff --git a/src/matrix/e2ee/megolm/Decryption.js b/src/matrix/e2ee/megolm/Decryption.js index 6121192d..9726e6d8 100644 --- a/src/matrix/e2ee/megolm/Decryption.js +++ b/src/matrix/e2ee/megolm/Decryption.js @@ -39,8 +39,8 @@ export class Decryption { constructor({pickleKey, olm}) { this._pickleKey = pickleKey; this._olm = olm; - // this._decryptor = new DecryptionWorker(new Worker("./src/worker.js")); this._decryptor = new DecryptionWorker(new WorkerPool("worker-1039452087.js", 4)); + //this._decryptor = new DecryptionWorker(new WorkerPool("./src/worker.js", 4)); this._initPromise = this._decryptor.init(); } diff --git a/src/matrix/e2ee/megolm/decryption/DecryptionPreparation.js b/src/matrix/e2ee/megolm/decryption/DecryptionPreparation.js index 02ee32df..e24d70af 100644 --- a/src/matrix/e2ee/megolm/decryption/DecryptionPreparation.js +++ b/src/matrix/e2ee/megolm/decryption/DecryptionPreparation.js @@ -28,6 +28,9 @@ export class DecryptionPreparation { } async decrypt() { + // console.log("start sleeping"); + // await new Promise(resolve => setTimeout(resolve, 5000)); + // console.log("done sleeping"); try { const errors = this._initialErrors; const results = new Map(); diff --git a/src/matrix/e2ee/megolm/decryption/DecryptionWorker.js b/src/matrix/e2ee/megolm/decryption/DecryptionWorker.js index 9cc64d74..38a474ed 100644 --- a/src/matrix/e2ee/megolm/decryption/DecryptionWorker.js +++ b/src/matrix/e2ee/megolm/decryption/DecryptionWorker.js @@ -94,7 +94,6 @@ export class WorkerPool { } this._requests.delete(message.replyToId); } - console.log("got worker reply", message, this._requests.size); this._sendPending(); } else if (e.type === "error") { console.error("worker error", e); @@ -119,13 +118,11 @@ export class WorkerPool { _sendPending() { this._pendingFlag = false; - console.log("seeing if there is anything to send", this._requests.size); let success; do { success = false; const request = this._getPendingRequest(); if (request) { - console.log("sending pending request", request); const worker = this._getFreeWorker(); if (worker) { this._sendWith(request, worker); @@ -138,7 +135,6 @@ export class WorkerPool { _sendWith(request, worker) { request._worker = worker; worker.busy = true; - console.log("sending message to worker", request._message); worker.worker.postMessage(request._message); } @@ -162,7 +158,7 @@ export class WorkerPool { // assumes all workers are free atm sendAll(message) { const promises = this._workers.map(worker => { - const request = this._enqueueRequest(message); + const request = this._enqueueRequest(Object.assign({}, message)); this._sendWith(request, worker); return request.response(); }); @@ -208,6 +204,6 @@ export class DecryptionWorker { async init() { await this._workerPool.sendAll({type: "load_olm", path: "olm_legacy-3232457086.js"}); - // return this._send({type: "load_olm", path: "../lib/olm/olm_legacy.js"}); + //await this._workerPool.sendAll({type: "load_olm", path: "../lib/olm/olm_legacy.js"}); } } diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 233990a3..98f114a5 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -532,4 +532,4 @@ class DecryptionRequest { this.preparation.dispose(); } } -} \ No newline at end of file +} diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index 38dc1c6a..74362a13 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -19,7 +19,6 @@ import {Disposables} from "../../../utils/Disposables.js"; import {Direction} from "./Direction.js"; import {TimelineReader} from "./persistence/TimelineReader.js"; import {PendingEventEntry} from "./entries/PendingEventEntry.js"; -import {EventEntry} from "./entries/EventEntry.js"; export class Timeline { constructor({roomId, storage, closeCallback, fragmentIdComparer, pendingEvents, user}) { @@ -99,10 +98,9 @@ export class Timeline { } /** @public */ - close() { + dispose() { if (this._closeCallback) { - this._readerRequest?.dispose(); - this._readerRequest = null; + this._disposables.dispose(); this._closeCallback(); this._closeCallback = null; } diff --git a/src/utils/Disposables.js b/src/utils/Disposables.js index e020ef83..efc49897 100644 --- a/src/utils/Disposables.js +++ b/src/utils/Disposables.js @@ -28,6 +28,9 @@ export class Disposables { } track(disposable) { + if (this.isDisposed) { + throw new Error("Already disposed, check isDisposed after await if needed"); + } this._disposables.push(disposable); return disposable; } @@ -41,8 +44,12 @@ export class Disposables { } } + get isDisposed() { + return this._disposables === null; + } + disposeTracked(value) { - if (value === undefined || value === null) { + if (value === undefined || value === null || this.isDisposed) { return null; } const idx = this._disposables.indexOf(value);