1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-04 05:02:41 +03:00

Merge pull request #916 from matrix-org/jryans/stringify-events

Add stringify helper to summarise events when debugging
This commit is contained in:
J. Ryan Stinnett
2019-05-16 09:44:39 +01:00
committed by GitHub

View File

@@ -794,6 +794,35 @@ utils.extend(module.exports.MatrixEvent.prototype, {
replacingEventId() { replacingEventId() {
return this._replacingEvent && this._replacingEvent.getId(); return this._replacingEvent && this._replacingEvent.getId();
}, },
/**
* Summarise the event as JSON for debugging. If encrypted, include both the
* decrypted and encrypted view of the event. This is named `toJSON` for use
* with `JSON.stringify` which checks objects for functions named `toJSON`
* and will call them to customise the output if they are defined.
*
* @return {Object}
*/
toJSON() {
const event = {
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(),
};
if (!this.isEncrypted()) {
return event;
}
return {
decrypted: event,
encrypted: this.event,
};
},
}); });