Don't erase existing reply-to relationships when editing messages

Signed-off-by: Joshua Goins <josh@redstrate.com>
This commit is contained in:
Joshua Goins
2023-01-04 23:36:30 -05:00
parent f03cd3f4c6
commit e055992943
5 changed files with 31 additions and 11 deletions

View File

@@ -937,12 +937,24 @@ QVariant MessageEventModel::getLastLocalUserMessageEventId()
if (content.contains("m.new_content")) { if (content.contains("m.new_content")) {
// The message has been edited so we have to return the id of the original message instead of the replacement // The message has been edited so we have to return the id of the original message instead of the replacement
eventId = content["m.relates_to"].toObject()["event_id"].toString(); eventId = content["m.relates_to"].toObject()["event_id"].toString();
e = eventCast<const RoomMessageEvent>(m_currentRoom->findInTimeline(eventId)->event());
if (!e) {
return {};
}
content = e->contentJson();
} else { } else {
// For any message that isn't an edit return the id of the current message // For any message that isn't an edit return the id of the current message
eventId = (*it)->id(); eventId = (*it)->id();
} }
targetMessage.insert("event_id", eventId); targetMessage.insert("event_id", eventId);
targetMessage.insert("formattedBody", content["formatted_body"].toString()); targetMessage.insert("formattedBody", content["formatted_body"].toString());
// keep reply relationship
if (content.contains("m.relates_to")) {
targetMessage.insert("m.relates_to", content["m.relates_to"].toObject());
}
// Need to get the message from the original eventId or body will have * on the front // Need to get the message from the original eventId or body will have * on the front
QModelIndex idx = index(eventIDToIndex(eventId), 0); QModelIndex idx = index(eventIDToIndex(eventId), 0);
targetMessage.insert("message", idx.data(Qt::UserRole + 2)); targetMessage.insert("message", idx.data(Qt::UserRole + 2));

View File

@@ -739,14 +739,18 @@ void NeoChatRoom::postHtmlMessage(const QString &text, const QString &html, Mess
} }
if (isEdit) { if (isEdit) {
QJsonObject json{ QJsonObject content{{"body", text}, {"msgtype", msgTypeToString(type)}, {"format", "org.matrix.custom.html"}, {"formatted_body", html}};
{"type", "m.room.message"}, if (isReply) {
{"msgtype", msgTypeToString(type)}, content["m.relates_to"] = QJsonObject{{"m.in_reply_to", QJsonObject{{"event_id", replyEventId}}}};
{"body", "* " + text}, }
{"format", "org.matrix.custom.html"},
{"formatted_body", html}, QJsonObject json{{"type", "m.room.message"},
{"m.new_content", QJsonObject{{"body", text}, {"msgtype", msgTypeToString(type)}, {"format", "org.matrix.custom.html"}, {"formatted_body", html}}}, {"msgtype", msgTypeToString(type)},
{"m.relates_to", QJsonObject{{"rel_type", "m.replace"}, {"event_id", relateToEventId}}}}; {"body", "* " + text},
{"format", "org.matrix.custom.html"},
{"formatted_body", html},
{"m.new_content", content},
{"m.relates_to", QJsonObject{{"rel_type", "m.replace"}, {"event_id", relateToEventId}}}};
postJson("m.room.message", json); postJson("m.room.message", json);
return; return;
@@ -1427,7 +1431,6 @@ void NeoChatRoom::setPushNotificationState(PushNotificationState::State state)
m_currentPushNotificationState = state; m_currentPushNotificationState = state;
Q_EMIT pushNotificationStateChanged(m_currentPushNotificationState); Q_EMIT pushNotificationStateChanged(m_currentPushNotificationState);
} }
void NeoChatRoom::updatePushNotificationState(QString type) void NeoChatRoom::updatePushNotificationState(QString type)

View File

@@ -129,6 +129,9 @@ QQC2.ToolBar {
} else if (event.key === Qt.Key_Up && inputField.text.length === 0) { } else if (event.key === Qt.Key_Up && inputField.text.length === 0) {
let editEvent = messageEventModel.getLastLocalUserMessageEventId() let editEvent = messageEventModel.getLastLocalUserMessageEventId()
if (editEvent) { if (editEvent) {
if(editEvent["m.relates_to"]) {
currentRoom.chatBoxReplyId = editEvent["m.relates_to"]["m.in_reply_to"]["event_id"];
}
currentRoom.chatBoxEditId = editEvent["event_id"] currentRoom.chatBoxEditId = editEvent["event_id"]
} }
} else if (event.key === Qt.Key_Up && completionMenu.visible) { } else if (event.key === Qt.Key_Up && completionMenu.visible) {

View File

@@ -15,6 +15,7 @@ Loader {
required property var author required property var author
required property string message required property string message
required property string eventId required property string eventId
property string replyEventId
property var eventType property var eventType
property string formattedBody: "" property string formattedBody: ""
required property string source required property string source
@@ -29,7 +30,7 @@ Loader {
icon.name: "document-edit" icon.name: "document-edit"
onTriggered: { onTriggered: {
currentRoom.chatBoxEditId = eventId; currentRoom.chatBoxEditId = eventId;
currentRoom.chatBoxReplyId = ""; currentRoom.chatBoxReplyId = replyEventId;
} }
visible: author.id === Controller.activeConnection.localUserId && (loadRoot.eventType === MessageEventModel.Emote || loadRoot.eventType === MessageEventModel.Message) visible: author.id === Controller.activeConnection.localUserId && (loadRoot.eventType === MessageEventModel.Emote || loadRoot.eventType === MessageEventModel.Message)
}, },

View File

@@ -537,7 +537,7 @@ Kirigami.ScrollablePage {
icon.name: "document-edit" icon.name: "document-edit"
onClicked: { onClicked: {
currentRoom.chatBoxEditId = hoverActions.event.eventId; currentRoom.chatBoxEditId = hoverActions.event.eventId;
currentRoom.chatBoxReplyId = ""; currentRoom.chatBoxReplyId = hoverActions.event.replyId;
chatBox.focusInputField(); chatBox.focusInputField();
} }
} }
@@ -682,6 +682,7 @@ Kirigami.ScrollablePage {
author: event.author, author: event.author,
message: event.display, message: event.display,
eventId: event.eventId, eventId: event.eventId,
replyEventId: event.replyId,
formattedBody: event.formattedBody, formattedBody: event.formattedBody,
source: event.source, source: event.source,
eventType: event.eventType, eventType: event.eventType,