You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-13 07:42:14 +03:00
support marking an as replacing another
and take if the timestamp of the original event if so also helper methods
This commit is contained in:
@@ -122,6 +122,7 @@ module.exports.MatrixEvent = function MatrixEvent(
|
|||||||
this.error = null;
|
this.error = null;
|
||||||
this.forwardLooking = true;
|
this.forwardLooking = true;
|
||||||
this._pushActions = null;
|
this._pushActions = null;
|
||||||
|
this._replacedEvent = null;
|
||||||
|
|
||||||
this._clearEvent = {};
|
this._clearEvent = {};
|
||||||
|
|
||||||
@@ -208,6 +209,9 @@ utils.extend(module.exports.MatrixEvent.prototype, {
|
|||||||
* @return {Number} The event timestamp, e.g. <code>1433502692297</code>
|
* @return {Number} The event timestamp, e.g. <code>1433502692297</code>
|
||||||
*/
|
*/
|
||||||
getTs: function() {
|
getTs: function() {
|
||||||
|
if (this._replacedEvent) {
|
||||||
|
return this._replacedEvent.getTs();
|
||||||
|
}
|
||||||
return this.event.origin_server_ts;
|
return this.event.origin_server_ts;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -216,6 +220,9 @@ utils.extend(module.exports.MatrixEvent.prototype, {
|
|||||||
* @return {Date} The event date, e.g. <code>new Date(1433502692297)</code>
|
* @return {Date} The event date, e.g. <code>new Date(1433502692297)</code>
|
||||||
*/
|
*/
|
||||||
getDate: function() {
|
getDate: function() {
|
||||||
|
if (this._replacedEvent) {
|
||||||
|
return this._replacedEvent.getDate();
|
||||||
|
}
|
||||||
return this.event.origin_server_ts ? new Date(this.event.origin_server_ts) : null;
|
return this.event.origin_server_ts ? new Date(this.event.origin_server_ts) : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -742,6 +749,30 @@ utils.extend(module.exports.MatrixEvent.prototype, {
|
|||||||
const relation = content && content["m.relates_to"];
|
const relation = content && content["m.relates_to"];
|
||||||
return relation && relation.rel_type && relation.event_id;
|
return relation && relation.rel_type && relation.event_id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isReplacement() {
|
||||||
|
const content = this.getContent();
|
||||||
|
const relation = content && content["m.relates_to"];
|
||||||
|
return relation && relation.rel_type === "m.replace" && relation.event_id;
|
||||||
|
},
|
||||||
|
|
||||||
|
setReplacedEvent(replacedEvent) {
|
||||||
|
this._replacedEvent = replacedEvent;
|
||||||
|
},
|
||||||
|
|
||||||
|
getReplacedEvent() {
|
||||||
|
return this._replacedEvent;
|
||||||
|
},
|
||||||
|
|
||||||
|
getOriginalId() {
|
||||||
|
const content = this.getContent();
|
||||||
|
const relation = content && content["m.relates_to"];
|
||||||
|
if (relation && relation.rel_type === "m.replace") {
|
||||||
|
return relation.event_id;
|
||||||
|
} else {
|
||||||
|
return this.getId();
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user