You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Clean up Event.clearEvent handling
This commit is contained in:
@@ -152,7 +152,7 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
private _replacingEvent: MatrixEvent = null;
|
private _replacingEvent: MatrixEvent = null;
|
||||||
private _localRedactionEvent: MatrixEvent = null;
|
private _localRedactionEvent: MatrixEvent = null;
|
||||||
private _isCancelled = false;
|
private _isCancelled = false;
|
||||||
private clearEvent: Partial<IClearEvent> = {};
|
private clearEvent?: IClearEvent;
|
||||||
|
|
||||||
/* curve25519 key which we believe belongs to the sender of the event. See
|
/* curve25519 key which we believe belongs to the sender of the event. See
|
||||||
* getSenderKey()
|
* getSenderKey()
|
||||||
@@ -285,7 +285,7 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
* @return {string} The event type, e.g. <code>m.room.message</code>
|
* @return {string} The event type, e.g. <code>m.room.message</code>
|
||||||
*/
|
*/
|
||||||
public getType(): EventType | string {
|
public getType(): EventType | string {
|
||||||
return this.clearEvent.type || this.event.type;
|
return this.clearEvent?.type || this.event.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -334,7 +334,7 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
if (this._localRedactionEvent) {
|
if (this._localRedactionEvent) {
|
||||||
return {} as T;
|
return {} as T;
|
||||||
}
|
}
|
||||||
return (this.clearEvent.content || this.event.content || {}) as T;
|
return (this.clearEvent?.content || this.event.content || {}) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -486,7 +486,7 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public shouldAttemptDecryption() {
|
public shouldAttemptDecryption() {
|
||||||
return this.isEncrypted() && !this.isBeingDecrypted() && this.getClearContent() === null;
|
return this.isEncrypted() && !this.isBeingDecrypted() && !this.clearEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -518,10 +518,7 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
throw new Error("Attempt to decrypt event which isn't encrypted");
|
throw new Error("Attempt to decrypt event which isn't encrypted");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (this.clearEvent?.content?.msgtype !== "m.bad.encrypted") {
|
||||||
this.clearEvent && this.clearEvent.content &&
|
|
||||||
this.clearEvent.content.msgtype !== "m.bad.encrypted"
|
|
||||||
) {
|
|
||||||
// we may want to just ignore this? let's start with rejecting it.
|
// we may want to just ignore this? let's start with rejecting it.
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Attempt to decrypt event which has already been decrypted",
|
"Attempt to decrypt event which has already been decrypted",
|
||||||
@@ -729,8 +726,7 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
* @returns {Object} The cleartext (decrypted) content for the event
|
* @returns {Object} The cleartext (decrypted) content for the event
|
||||||
*/
|
*/
|
||||||
public getClearContent(): IContent | null {
|
public getClearContent(): IContent | null {
|
||||||
const ev = this.clearEvent;
|
return this.clearEvent?.content || null;
|
||||||
return ev && ev.content ? ev.content : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -921,8 +917,8 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
public getRedactionEvent(): object | null {
|
public getRedactionEvent(): object | null {
|
||||||
if (!this.isRedacted()) return null;
|
if (!this.isRedacted()) return null;
|
||||||
|
|
||||||
if (this.clearEvent.unsigned) {
|
if (this.clearEvent?.unsigned) {
|
||||||
return this.clearEvent.unsigned.redacted_because;
|
return this.clearEvent?.unsigned.redacted_because;
|
||||||
} else if (this.event.unsigned.redacted_because) {
|
} else if (this.event.unsigned.redacted_because) {
|
||||||
return this.event.unsigned.redacted_because;
|
return this.event.unsigned.redacted_because;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user