mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +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() {
|
async load() {
|
||||||
this._room.on("change", this._onRoomChange);
|
this._room.on("change", this._onRoomChange);
|
||||||
try {
|
try {
|
||||||
this._timeline = this._room.openTimeline();
|
this._timeline = this.track(this._room.openTimeline());
|
||||||
await this._timeline.load();
|
await this._timeline.load();
|
||||||
this._timelineVM = new TimelineViewModel(this.childOptions({
|
this._timelineVM = new TimelineViewModel(this.childOptions({
|
||||||
room: this._room,
|
room: this._room,
|
||||||
@ -63,17 +63,15 @@ export class RoomViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
// this races with enable, on the await openTimeline()
|
super.dispose();
|
||||||
if (this._timeline) {
|
|
||||||
// will stop the timeline from delivering updates on entries
|
|
||||||
this._timeline.close();
|
|
||||||
}
|
|
||||||
if (this._clearUnreadTimout) {
|
if (this._clearUnreadTimout) {
|
||||||
this._clearUnreadTimout.abort();
|
this._clearUnreadTimout.abort();
|
||||||
this._clearUnreadTimout = null;
|
this._clearUnreadTimout = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// called from view to close room
|
||||||
|
// parent vm will dispose this vm
|
||||||
close() {
|
close() {
|
||||||
this._closeCallback();
|
this._closeCallback();
|
||||||
}
|
}
|
||||||
|
@ -292,11 +292,9 @@ class BatchDecryptionResult {
|
|||||||
constructor(results, errors) {
|
constructor(results, errors) {
|
||||||
this.results = results;
|
this.results = results;
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
console.log("BatchDecryptionResult", this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applyToEntries(entries) {
|
applyToEntries(entries) {
|
||||||
console.log("BatchDecryptionResult.applyToEntries", this);
|
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
const result = this.results.get(entry.id);
|
const result = this.results.get(entry.id);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -39,8 +39,8 @@ export class Decryption {
|
|||||||
constructor({pickleKey, olm}) {
|
constructor({pickleKey, olm}) {
|
||||||
this._pickleKey = pickleKey;
|
this._pickleKey = pickleKey;
|
||||||
this._olm = olm;
|
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("worker-1039452087.js", 4));
|
||||||
|
//this._decryptor = new DecryptionWorker(new WorkerPool("./src/worker.js", 4));
|
||||||
this._initPromise = this._decryptor.init();
|
this._initPromise = this._decryptor.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,9 @@ export class DecryptionPreparation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async decrypt() {
|
async decrypt() {
|
||||||
|
// console.log("start sleeping");
|
||||||
|
// await new Promise(resolve => setTimeout(resolve, 5000));
|
||||||
|
// console.log("done sleeping");
|
||||||
try {
|
try {
|
||||||
const errors = this._initialErrors;
|
const errors = this._initialErrors;
|
||||||
const results = new Map();
|
const results = new Map();
|
||||||
|
@ -94,7 +94,6 @@ export class WorkerPool {
|
|||||||
}
|
}
|
||||||
this._requests.delete(message.replyToId);
|
this._requests.delete(message.replyToId);
|
||||||
}
|
}
|
||||||
console.log("got worker reply", message, this._requests.size);
|
|
||||||
this._sendPending();
|
this._sendPending();
|
||||||
} else if (e.type === "error") {
|
} else if (e.type === "error") {
|
||||||
console.error("worker error", e);
|
console.error("worker error", e);
|
||||||
@ -119,13 +118,11 @@ export class WorkerPool {
|
|||||||
|
|
||||||
_sendPending() {
|
_sendPending() {
|
||||||
this._pendingFlag = false;
|
this._pendingFlag = false;
|
||||||
console.log("seeing if there is anything to send", this._requests.size);
|
|
||||||
let success;
|
let success;
|
||||||
do {
|
do {
|
||||||
success = false;
|
success = false;
|
||||||
const request = this._getPendingRequest();
|
const request = this._getPendingRequest();
|
||||||
if (request) {
|
if (request) {
|
||||||
console.log("sending pending request", request);
|
|
||||||
const worker = this._getFreeWorker();
|
const worker = this._getFreeWorker();
|
||||||
if (worker) {
|
if (worker) {
|
||||||
this._sendWith(request, worker);
|
this._sendWith(request, worker);
|
||||||
@ -138,7 +135,6 @@ export class WorkerPool {
|
|||||||
_sendWith(request, worker) {
|
_sendWith(request, worker) {
|
||||||
request._worker = worker;
|
request._worker = worker;
|
||||||
worker.busy = true;
|
worker.busy = true;
|
||||||
console.log("sending message to worker", request._message);
|
|
||||||
worker.worker.postMessage(request._message);
|
worker.worker.postMessage(request._message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +158,7 @@ export class WorkerPool {
|
|||||||
// assumes all workers are free atm
|
// assumes all workers are free atm
|
||||||
sendAll(message) {
|
sendAll(message) {
|
||||||
const promises = this._workers.map(worker => {
|
const promises = this._workers.map(worker => {
|
||||||
const request = this._enqueueRequest(message);
|
const request = this._enqueueRequest(Object.assign({}, message));
|
||||||
this._sendWith(request, worker);
|
this._sendWith(request, worker);
|
||||||
return request.response();
|
return request.response();
|
||||||
});
|
});
|
||||||
@ -208,6 +204,6 @@ export class DecryptionWorker {
|
|||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
await this._workerPool.sendAll({type: "load_olm", path: "olm_legacy-3232457086.js"});
|
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 {Direction} from "./Direction.js";
|
||||||
import {TimelineReader} from "./persistence/TimelineReader.js";
|
import {TimelineReader} from "./persistence/TimelineReader.js";
|
||||||
import {PendingEventEntry} from "./entries/PendingEventEntry.js";
|
import {PendingEventEntry} from "./entries/PendingEventEntry.js";
|
||||||
import {EventEntry} from "./entries/EventEntry.js";
|
|
||||||
|
|
||||||
export class Timeline {
|
export class Timeline {
|
||||||
constructor({roomId, storage, closeCallback, fragmentIdComparer, pendingEvents, user}) {
|
constructor({roomId, storage, closeCallback, fragmentIdComparer, pendingEvents, user}) {
|
||||||
@ -99,10 +98,9 @@ export class Timeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
close() {
|
dispose() {
|
||||||
if (this._closeCallback) {
|
if (this._closeCallback) {
|
||||||
this._readerRequest?.dispose();
|
this._disposables.dispose();
|
||||||
this._readerRequest = null;
|
|
||||||
this._closeCallback();
|
this._closeCallback();
|
||||||
this._closeCallback = null;
|
this._closeCallback = null;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,9 @@ export class Disposables {
|
|||||||
}
|
}
|
||||||
|
|
||||||
track(disposable) {
|
track(disposable) {
|
||||||
|
if (this.isDisposed) {
|
||||||
|
throw new Error("Already disposed, check isDisposed after await if needed");
|
||||||
|
}
|
||||||
this._disposables.push(disposable);
|
this._disposables.push(disposable);
|
||||||
return disposable;
|
return disposable;
|
||||||
}
|
}
|
||||||
@ -41,8 +44,12 @@ export class Disposables {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isDisposed() {
|
||||||
|
return this._disposables === null;
|
||||||
|
}
|
||||||
|
|
||||||
disposeTracked(value) {
|
disposeTracked(value) {
|
||||||
if (value === undefined || value === null) {
|
if (value === undefined || value === null || this.isDisposed) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const idx = this._disposables.indexOf(value);
|
const idx = this._disposables.indexOf(value);
|
||||||
|
Loading…
Reference in New Issue
Block a user