mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 04:21:57 +03:00
fix: make edit prefill work correctly from EditHistory
handle encrypted and unencrypted events get the correct event_id (the base message) when called from EditHistoryMessage keep only the `body` and `msgtype` fields when prefilling
This commit is contained in:
parent
51ac5421c9
commit
29b95e6083
1 changed files with 26 additions and 7 deletions
|
@ -39,6 +39,7 @@ export default class ViewSource extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onBack() {
|
onBack() {
|
||||||
|
// TODO: refresh the "Event ID:" modal header
|
||||||
this.setState({ isEditing: false });
|
this.setState({ isEditing: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,15 +81,28 @@ export default class ViewSource extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns the id of the initial message, not the id of the previous edit
|
||||||
|
getBaseEventId() {
|
||||||
|
const mxEvent = this.props.mxEvent.replacingEvent() || this.props.mxEvent; // show the replacing event, not the original, if it is an edit
|
||||||
|
const isEncrypted = this.props.mxEvent.getType() !== this.props.mxEvent.getWireType();
|
||||||
|
const baseMxEvent = this.props.mxEvent;
|
||||||
|
|
||||||
|
if (isEncrypted) {
|
||||||
|
// `relates_to` field is inside the encrypted event
|
||||||
|
return mxEvent.event.content["m.relates_to"]?.event_id ?? baseMxEvent.getId();
|
||||||
|
} else {
|
||||||
|
return mxEvent.getContent()["m.relates_to"]?.event_id ?? baseMxEvent.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// returns the SendCustomEvent component prefilled with the correct details
|
// returns the SendCustomEvent component prefilled with the correct details
|
||||||
editSourceContent() {
|
editSourceContent() {
|
||||||
const mxEvent = this.props.mxEvent.replacingEvent() || this.props.mxEvent; // show the replacing event, not the original, if it is an edit
|
const mxEvent = this.props.mxEvent.replacingEvent() || this.props.mxEvent; // show the replacing event, not the original, if it is an edit
|
||||||
|
|
||||||
const isStateEvent = mxEvent.isState();
|
const isStateEvent = mxEvent.isState();
|
||||||
console.log("isStateEvent", isStateEvent);
|
|
||||||
const roomId = mxEvent.getRoomId();
|
const roomId = mxEvent.getRoomId();
|
||||||
const eventId = mxEvent.getId();
|
|
||||||
const originalContent = mxEvent.getContent();
|
const originalContent = mxEvent.getContent();
|
||||||
|
|
||||||
if (isStateEvent) {
|
if (isStateEvent) {
|
||||||
return (
|
return (
|
||||||
<MatrixClientContext.Consumer>
|
<MatrixClientContext.Consumer>
|
||||||
|
@ -107,14 +121,19 @@ export default class ViewSource extends React.Component {
|
||||||
</MatrixClientContext.Consumer>
|
</MatrixClientContext.Consumer>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// send an edit-message event
|
// prefill an edit-message event
|
||||||
// prefill the "m.new_content" field
|
// keep only the `body` and `msgtype` fields of originalContent
|
||||||
|
const bodyToStartFrom = originalContent["m.new_content"]?.body ?? originalContent.body; // prefill the last edit body, to start editing from there
|
||||||
const newContent = {
|
const newContent = {
|
||||||
...originalContent,
|
"body": ` * ${bodyToStartFrom}`,
|
||||||
"m.new_content": originalContent,
|
"msgtype": originalContent.msgtype,
|
||||||
|
"m.new_content": {
|
||||||
|
body: bodyToStartFrom,
|
||||||
|
msgtype: originalContent.msgtype,
|
||||||
|
},
|
||||||
"m.relates_to": {
|
"m.relates_to": {
|
||||||
rel_type: "m.replace",
|
rel_type: "m.replace",
|
||||||
event_id: eventId,
|
event_id: this.getBaseEventId(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue