mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-02-02 07:31:38 +01:00
Emit event from DeviceMessageHandler
This commit is contained in:
parent
75688cf6f3
commit
ed4eb9bde0
@ -17,9 +17,11 @@ limitations under the License.
|
||||
import {OLM_ALGORITHM} from "./e2ee/common.js";
|
||||
import {countBy, groupBy} from "../utils/groupBy";
|
||||
import {LRUCache} from "../utils/LRUCache";
|
||||
import {EventEmitter} from "../utils/EventEmitter";
|
||||
|
||||
export class DeviceMessageHandler {
|
||||
export class DeviceMessageHandler extends EventEmitter{
|
||||
constructor({storage, callHandler}) {
|
||||
super();
|
||||
this._storage = storage;
|
||||
this._olmDecryption = null;
|
||||
this._megolmDecryption = null;
|
||||
@ -39,6 +41,7 @@ export class DeviceMessageHandler {
|
||||
async prepareSync(toDeviceEvents, lock, txn, log) {
|
||||
log.set("messageTypes", countBy(toDeviceEvents, e => e.type));
|
||||
const encryptedEvents = toDeviceEvents.filter(e => e.type === "m.room.encrypted");
|
||||
this._emitUnencryptedEvents(toDeviceEvents);
|
||||
if (!this._olmDecryption) {
|
||||
log.log("can't decrypt, encryption not enabled", log.level.Warn);
|
||||
return;
|
||||
@ -74,6 +77,7 @@ export class DeviceMessageHandler {
|
||||
}
|
||||
|
||||
async afterSyncCompleted(decryptionResults, deviceTracker, hsApi, log) {
|
||||
this._emitEncryptedEvents(decryptionResults);
|
||||
if (this._callHandler) {
|
||||
// if we don't have a device, we need to fetch the device keys the message claims
|
||||
// and check the keys, and we should only do network requests during
|
||||
@ -101,6 +105,19 @@ export class DeviceMessageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_emitUnencryptedEvents(toDeviceEvents) {
|
||||
const unencryptedEvents = toDeviceEvents.filter(e => e.type !== "m.room.encrypted");
|
||||
for (const event of unencryptedEvents) {
|
||||
this.emit("message", { unencrypted: event });
|
||||
}
|
||||
}
|
||||
|
||||
_emitEncryptedEvents(decryptionResults) {
|
||||
for (const result of decryptionResults) {
|
||||
this.emit("message", { encrypted: result });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SyncPreparation {
|
||||
|
Loading…
x
Reference in New Issue
Block a user