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
Merge pull request #984 from matrix-org/bwindels/replace-server-date
Get edit date transparently from server aggregations or local echo
This commit is contained in:
@@ -898,13 +898,25 @@ utils.extend(module.exports.MatrixEvent.prototype, {
|
|||||||
return this.status;
|
return this.status;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getServerAggregatedRelation(relType) {
|
||||||
|
const relations = this.getUnsigned()["m.relations"];
|
||||||
|
if (relations) {
|
||||||
|
return relations[relType];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the event ID of the event replacing the content of this event, if any.
|
* Returns the event ID of the event replacing the content of this event, if any.
|
||||||
*
|
*
|
||||||
* @return {string?}
|
* @return {string?}
|
||||||
*/
|
*/
|
||||||
replacingEventId() {
|
replacingEventId() {
|
||||||
return this._replacingEvent && this._replacingEvent.getId();
|
const replaceRelation = this._getServerAggregatedRelation("m.replace");
|
||||||
|
if (replaceRelation) {
|
||||||
|
return replaceRelation.event_id;
|
||||||
|
} else if (this._replacingEvent) {
|
||||||
|
return this._replacingEvent.getId();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -918,6 +930,23 @@ utils.extend(module.exports.MatrixEvent.prototype, {
|
|||||||
return this._replacingEvent;
|
return this._replacingEvent;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the origin_server_ts of the event replacing the content of this event, if any.
|
||||||
|
*
|
||||||
|
* @return {Date?}
|
||||||
|
*/
|
||||||
|
replacingEventDate() {
|
||||||
|
const replaceRelation = this._getServerAggregatedRelation("m.replace");
|
||||||
|
if (replaceRelation) {
|
||||||
|
const ts = replaceRelation.origin_server_ts;
|
||||||
|
if (Number.isFinite(ts)) {
|
||||||
|
return new Date(ts);
|
||||||
|
}
|
||||||
|
} else if (this._replacingEvent) {
|
||||||
|
return this._replacingEvent.getDate();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the event that wants to redact this event, but hasn't been sent yet.
|
* Returns the event that wants to redact this event, but hasn't been sent yet.
|
||||||
* @return {MatrixEvent} the event
|
* @return {MatrixEvent} the event
|
||||||
|
|||||||
Reference in New Issue
Block a user