You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
Send extensible events structure and support on-demand parsing (#2091)
* Parse extensible events on demand * Decorate messages with MSC1767 when appropriate We do this automatically to force a pool of messages in the wild we can use for testing. * Include the SDK * Appease linter and tests * Change property name to appease linter * Update SDK
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2015 - 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
import { ExtensibleEvent, ExtensibleEvents, Optional } from "matrix-events-sdk";
|
||||
|
||||
import { logger } from '../logger';
|
||||
import { VerificationRequest } from "../crypto/verification/request/VerificationRequest";
|
||||
@@ -210,6 +211,12 @@ export class MatrixEvent extends EventEmitter {
|
||||
*/
|
||||
private visibility: MessageVisibility = MESSAGE_VISIBLE;
|
||||
|
||||
// Not all events will be extensible-event compatible, so cache a flag in
|
||||
// addition to a falsy cached event value. We check the flag later on in
|
||||
// a public getter to decide if the cache is valid.
|
||||
private _hasCachedExtEv = false;
|
||||
private _cachedExtEv: Optional<ExtensibleEvent> = undefined;
|
||||
|
||||
/* curve25519 key which we believe belongs to the sender of the event. See
|
||||
* getSenderKey()
|
||||
*/
|
||||
@@ -327,6 +334,25 @@ export class MatrixEvent extends EventEmitter {
|
||||
this.reEmitter = new ReEmitter(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unstable getter to try and get an extensible event. Note that this might
|
||||
* return a falsy value if the event could not be parsed as an extensible
|
||||
* event.
|
||||
*
|
||||
* @deprecated Use stable functions where possible.
|
||||
*/
|
||||
public get unstableExtensibleEvent(): Optional<ExtensibleEvent> {
|
||||
if (!this._hasCachedExtEv) {
|
||||
this._cachedExtEv = ExtensibleEvents.parse(this.getEffectiveEvent());
|
||||
}
|
||||
return this._cachedExtEv;
|
||||
}
|
||||
|
||||
private invalidateExtensibleEvent() {
|
||||
// just reset the flag - that'll trick the getter into parsing a new event
|
||||
this._hasCachedExtEv = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the event as though it would appear unencrypted. If the event is already not
|
||||
* encrypted, it is simply returned as-is.
|
||||
@@ -861,6 +887,7 @@ export class MatrixEvent extends EventEmitter {
|
||||
this.forwardingCurve25519KeyChain =
|
||||
decryptionResult.forwardingCurve25519KeyChain || [];
|
||||
this.untrusted = decryptionResult.untrusted || false;
|
||||
this.invalidateExtensibleEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1079,6 +1106,8 @@ export class MatrixEvent extends EventEmitter {
|
||||
delete content[key];
|
||||
}
|
||||
}
|
||||
|
||||
this.invalidateExtensibleEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1282,6 +1311,7 @@ export class MatrixEvent extends EventEmitter {
|
||||
if (this._replacingEvent !== newEvent) {
|
||||
this._replacingEvent = newEvent;
|
||||
this.emit("Event.replaced", this);
|
||||
this.invalidateExtensibleEvent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user