feat: add a quick edit workflow using the up arrow key
neochat now supports a quick edit shortcut, which helps to edit the last message from the user in a room. Apply 1 suggestion(s) to 1 file(s) remove comment
This commit is contained in:
@@ -28,6 +28,7 @@ ToolBar {
|
||||
signal inputFieldForceActiveFocusTriggered()
|
||||
signal messageSent()
|
||||
signal pasteImageTriggered()
|
||||
signal editLastUserMessage()
|
||||
|
||||
property alias isCompleting: completionMenu.visible
|
||||
|
||||
@@ -141,6 +142,8 @@ ToolBar {
|
||||
switchRoomUp();
|
||||
} else if (event.key === Qt.Key_V && event.modifiers & Qt.ControlModifier) {
|
||||
chatBar.pasteImage();
|
||||
} else if (event.key === Qt.Key_Up && !(event.modifiers & Qt.ControlModifier)) {
|
||||
editLastUserMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ Item {
|
||||
|
||||
signal fancyEffectsReasonFound(string fancyEffect)
|
||||
signal messageSent()
|
||||
signal editLastUserMessage()
|
||||
|
||||
Kirigami.Theme.colorSet: Kirigami.Theme.View
|
||||
|
||||
@@ -153,6 +154,9 @@ Item {
|
||||
checkForFancyEffectsReason()
|
||||
root.messageSent();
|
||||
}
|
||||
onEditLastUserMessage: {
|
||||
root.editLastUserMessage();
|
||||
}
|
||||
}
|
||||
|
||||
function checkForFancyEffectsReason() {
|
||||
|
||||
@@ -651,6 +651,12 @@ Kirigami.ScrollablePage {
|
||||
goToLastMessage();
|
||||
}
|
||||
}
|
||||
onEditLastUserMessage: {
|
||||
const targetMessage = messageEventModel.getLastLocalUserMessageEventId();
|
||||
if (targetMessage) {
|
||||
ChatBoxHelper.edit(targetMessage["body"], targetMessage["body"], targetMessage["event_id"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
background: FancyEffectsContainer {
|
||||
|
||||
@@ -632,3 +632,38 @@ int MessageEventModel::eventIDToIndex(const QString &eventID) const
|
||||
}
|
||||
return it - m_currentRoom->messageEvents().rbegin() + timelineBaseIndex();
|
||||
}
|
||||
|
||||
QVariant MessageEventModel::getLastLocalUserMessageEventId()
|
||||
{
|
||||
QVariantMap targetMessage;
|
||||
const auto &timelineBottom = m_currentRoom->messageEvents().rbegin();
|
||||
|
||||
// set a cap limit of 35 messages, to prevent loading a lot of messages
|
||||
// in rooms where the user has not sent many messages
|
||||
const auto limit = timelineBottom + std::min(35, m_currentRoom->timelineSize());
|
||||
|
||||
for (auto it = timelineBottom; it != limit; ++it) {
|
||||
auto evt = it->event();
|
||||
auto e = eventCast<const RoomMessageEvent>(evt);
|
||||
|
||||
// check if the current message's sender's id is same as the user's id
|
||||
if ((*it)->senderId() == m_currentRoom->localUser()->id()) {
|
||||
auto content = (*it)->contentJson();
|
||||
|
||||
if (content.contains("m.relates_to")) {
|
||||
// the message has been edited once
|
||||
// so we have to return the id of the related' message instead
|
||||
targetMessage.insert("event_id",content["m.relates_to"].toObject()["event_id"].toString());
|
||||
targetMessage.insert("body", content["formatted_body"].toString());
|
||||
return targetMessage;
|
||||
}
|
||||
|
||||
if (e->msgtype() == MessageEventType::Text) {
|
||||
targetMessage.insert("event_id", (*it)->id());
|
||||
targetMessage.insert("body", content["body"].toString());
|
||||
return targetMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
return targetMessage;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public:
|
||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
Q_INVOKABLE [[nodiscard]] int eventIDToIndex(const QString &eventID) const;
|
||||
Q_INVOKABLE [[nodiscard]] QVariant getLastLocalUserMessageEventId();
|
||||
|
||||
private Q_SLOTS:
|
||||
int refreshEvent(const QString &eventId);
|
||||
|
||||
Reference in New Issue
Block a user