forked from mystiq/hydrogen-web
load all pending operations when starting the session, pass to room
This commit is contained in:
parent
ab1fe711ad
commit
96119b4e58
2 changed files with 20 additions and 5 deletions
|
@ -28,6 +28,7 @@ import {MEGOLM_ALGORITHM} from "./e2ee/common.js";
|
||||||
import {RoomEncryption} from "./e2ee/RoomEncryption.js";
|
import {RoomEncryption} from "./e2ee/RoomEncryption.js";
|
||||||
import {DeviceTracker} from "./e2ee/DeviceTracker.js";
|
import {DeviceTracker} from "./e2ee/DeviceTracker.js";
|
||||||
import {LockMap} from "../utils/LockMap.js";
|
import {LockMap} from "../utils/LockMap.js";
|
||||||
|
import {groupBy} from "../utils/groupBy.js";
|
||||||
|
|
||||||
const PICKLE_KEY = "DEFAULT_KEY";
|
const PICKLE_KEY = "DEFAULT_KEY";
|
||||||
|
|
||||||
|
@ -212,9 +213,20 @@ export class Session {
|
||||||
await txn.complete();
|
await txn.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const opsTxn = await this._storage.readWriteTxn([
|
||||||
|
this._storage.storeNames.operations
|
||||||
|
]);
|
||||||
|
const operations = await opsTxn.operations.getAll();
|
||||||
|
const operationsByScope = groupBy(operations, o => o.scope);
|
||||||
|
|
||||||
this._sendScheduler.start();
|
this._sendScheduler.start();
|
||||||
for (const [, room] of this._rooms) {
|
for (const [, room] of this._rooms) {
|
||||||
room.start();
|
let roomOperationsByType;
|
||||||
|
const roomOperations = operationsByScope.get(room.id);
|
||||||
|
if (roomOperations) {
|
||||||
|
roomOperationsByType = groupBy(roomOperations, r => r.type);
|
||||||
|
}
|
||||||
|
room.start(roomOperationsByType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -259,14 +259,17 @@ export class Room extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @package */
|
/** @package */
|
||||||
async start() {
|
async start(pendingOperations) {
|
||||||
if (this._roomEncryption) {
|
if (this._roomEncryption) {
|
||||||
try {
|
try {
|
||||||
// if we got interrupted last time sending keys to newly joined members
|
const roomKeyShares = pendingOperations?.get("share_room_key");
|
||||||
await this._roomEncryption.shareRoomKeyToPendingMembers(this._hsApi);
|
if (roomKeyShares) {
|
||||||
|
// if we got interrupted last time sending keys to newly joined members
|
||||||
|
await this._roomEncryption.flushPendingRoomKeyShares(this._hsApi, roomKeyShares);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// we should not throw here
|
// we should not throw here
|
||||||
console.error(`could not send out pending room keys for room ${this.id}`, err.stack);
|
console.error(`could not send out (all) pending room keys for room ${this.id}`, err.stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._sendQueue.resumeSending();
|
this._sendQueue.resumeSending();
|
||||||
|
|
Loading…
Reference in a new issue