mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
abort decrypt requests when changing room
This commit is contained in:
parent
0bf1723d99
commit
de1cc0d739
@ -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();
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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"});
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user