Compare commits
1 Commits
v23.08.1
...
fix-editin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bf23c491a |
@@ -937,12 +937,24 @@ QVariant MessageEventModel::getLastLocalUserMessageEventId()
|
||||
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
|
||||
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 {
|
||||
// For any message that isn't an edit return the id of the current message
|
||||
eventId = (*it)->id();
|
||||
}
|
||||
targetMessage.insert("event_id", eventId);
|
||||
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
|
||||
QModelIndex idx = index(eventIDToIndex(eventId), 0);
|
||||
targetMessage.insert("message", idx.data(Qt::UserRole + 2));
|
||||
|
||||
@@ -739,13 +739,25 @@ void NeoChatRoom::postHtmlMessage(const QString &text, const QString &html, Mess
|
||||
}
|
||||
|
||||
if (isEdit) {
|
||||
QJsonObject content{{"body", text}, {"msgtype", msgTypeToString(type)}, {"format", "org.matrix.custom.html"}, {"formatted_body", html}};
|
||||
if (isReply) {
|
||||
content["m.relates_to"] =
|
||||
QJsonObject {
|
||||
{"m.in_reply_to",
|
||||
QJsonObject {
|
||||
{"event_id", replyEventId}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
QJsonObject json{
|
||||
{"type", "m.room.message"},
|
||||
{"msgtype", msgTypeToString(type)},
|
||||
{"body", "* " + text},
|
||||
{"format", "org.matrix.custom.html"},
|
||||
{"formatted_body", html},
|
||||
{"m.new_content", QJsonObject{{"body", text}, {"msgtype", msgTypeToString(type)}, {"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);
|
||||
|
||||
@@ -129,6 +129,9 @@ QQC2.ToolBar {
|
||||
} else if (event.key === Qt.Key_Up && inputField.text.length === 0) {
|
||||
let editEvent = messageEventModel.getLastLocalUserMessageEventId()
|
||||
if (editEvent) {
|
||||
if(editEvent["m.relates_to"]) {
|
||||
currentRoom.chatBoxReplyId = editEvent["m.relates_to"]["m.in_reply_to"]["event_id"];
|
||||
}
|
||||
currentRoom.chatBoxEditId = editEvent["event_id"]
|
||||
}
|
||||
} else if (event.key === Qt.Key_Up && completionMenu.visible) {
|
||||
|
||||
@@ -15,6 +15,7 @@ Loader {
|
||||
required property var author
|
||||
required property string message
|
||||
required property string eventId
|
||||
property string replyEventId
|
||||
property var eventType
|
||||
property string formattedBody: ""
|
||||
required property string source
|
||||
@@ -29,7 +30,7 @@ Loader {
|
||||
icon.name: "document-edit"
|
||||
onTriggered: {
|
||||
currentRoom.chatBoxEditId = eventId;
|
||||
currentRoom.chatBoxReplyId = "";
|
||||
currentRoom.chatBoxReplyId = replyEventId;
|
||||
}
|
||||
visible: author.id === Controller.activeConnection.localUserId && (loadRoot.eventType === MessageEventModel.Emote || loadRoot.eventType === MessageEventModel.Message)
|
||||
},
|
||||
|
||||
@@ -537,7 +537,7 @@ Kirigami.ScrollablePage {
|
||||
icon.name: "document-edit"
|
||||
onClicked: {
|
||||
currentRoom.chatBoxEditId = hoverActions.event.eventId;
|
||||
currentRoom.chatBoxReplyId = "";
|
||||
currentRoom.chatBoxReplyId = hoverActions.event.replyId;
|
||||
chatBox.focusInputField();
|
||||
}
|
||||
}
|
||||
@@ -682,6 +682,7 @@ Kirigami.ScrollablePage {
|
||||
author: event.author,
|
||||
message: event.display,
|
||||
eventId: event.eventId,
|
||||
replyEventId: event.replyId,
|
||||
formattedBody: event.formattedBody,
|
||||
source: event.source,
|
||||
eventType: event.eventType,
|
||||
|
||||
Reference in New Issue
Block a user