Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose MatrixEvent's internal clearEvent as a function #1784

Merged
merged 5 commits into from
Jul 14, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ export class MatrixEvent extends EventEmitter {
}

/**
* Gets the clear event as it would be received over the wire. If the event
* is not encrypted, this simply returns the event as-is.
* @returns {IEvent} The clear event, as known by the SDK.
* Gets the event as though it would appear unencrypted. If the event is already not
* encrypted, it is simply returned as-is.
* @returns {IEvent} The event in wire format.
*/
public getClearEvent(): IEvent {
public getEffectiveEvent(): IEvent {
// clearEvent doesn't have all the fields, so we'll copy what we can from this.event
return Object.assign({}, this.event, this.clearEvent) as IEvent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you allergic to the nicer syntax :P?

return {
    ...this.event,
    ...this.clearEvent,
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"nicer" - I feel it doesn't communicate the order properly given JS objects are unordered, so there's no implicit guarantee that the spread operation will be applied correctly. The spec says it will, but that's a detail someone has to remember when writing/reading the code.

}
Expand Down Expand Up @@ -1240,15 +1240,7 @@ export class MatrixEvent extends EventEmitter {
* @return {Object}
*/
public toJSON(): object {
const event: any = {
type: this.getType(),
sender: this.getSender(),
content: this.getContent(),
event_id: this.getId(),
origin_server_ts: this.getTs(),
unsigned: this.getUnsigned(),
room_id: this.getRoomId(),
};
const event = this.getEffectiveEvent();

// if this is a redaction then attach the redacts key
turt2live marked this conversation as resolved.
Show resolved Hide resolved
if (this.isRedaction()) {
Expand Down