Implement quick edit
This commit is contained in:
@@ -339,6 +339,7 @@ ToolBar {
|
|||||||
|
|
||||||
function postMessage() {
|
function postMessage() {
|
||||||
checkForFancyEffectsReason();
|
checkForFancyEffectsReason();
|
||||||
|
|
||||||
if (ChatBoxHelper.hasAttachment) {
|
if (ChatBoxHelper.hasAttachment) {
|
||||||
// send attachment but don't reset the text
|
// send attachment but don't reset the text
|
||||||
actionsHandler.postMessage("", ChatBoxHelper.attachmentPath,
|
actionsHandler.postMessage("", ChatBoxHelper.attachmentPath,
|
||||||
@@ -347,8 +348,16 @@ ToolBar {
|
|||||||
messageSent();
|
messageSent();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
actionsHandler.postMessage(inputField.text.trim(), ChatBoxHelper.attachmentPath,
|
|
||||||
ChatBoxHelper.replyEventId, ChatBoxHelper.editEventId, userAutocompleted);
|
const re = /^s\/([^\/]*)\/([^\/]*)/;
|
||||||
|
if (Config.allowQuickEdit && re.test(inputField.text)) {
|
||||||
|
// send edited messages
|
||||||
|
actionsHandler.postEdit(inputField.text);
|
||||||
|
} else {
|
||||||
|
// send normal message
|
||||||
|
actionsHandler.postMessage(inputField.text.trim(), ChatBoxHelper.attachmentPath,
|
||||||
|
ChatBoxHelper.replyEventId, ChatBoxHelper.editEventId, userAutocompleted);
|
||||||
|
}
|
||||||
currentRoom.markAllMessagesAsRead();
|
currentRoom.markAllMessagesAsRead();
|
||||||
inputField.clear();
|
inputField.clear();
|
||||||
inputField.text = Qt.binding(function() {
|
inputField.text = Qt.binding(function() {
|
||||||
|
|||||||
@@ -76,5 +76,13 @@ Kirigami.ScrollablePage {
|
|||||||
Config.save()
|
Config.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QQC2.CheckBox {
|
||||||
|
text: i18n("Use s/text/replacement syntax to edit your last message")
|
||||||
|
checked: Config.allowQuickEdit
|
||||||
|
onToggled: {
|
||||||
|
Config.allowQuickEdit = checked
|
||||||
|
Config.save()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#include "actionshandler.h"
|
#include "actionshandler.h"
|
||||||
|
#include "controller.h"
|
||||||
|
|
||||||
#include "csapi/joining.h"
|
#include <csapi/joining.h>
|
||||||
|
#include <events/roommessageevent.h>
|
||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -56,6 +58,36 @@ void ActionsHandler::setConnection(Connection *connection)
|
|||||||
Q_EMIT connectionChanged();
|
Q_EMIT connectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ActionsHandler::postEdit(const QString &text)
|
||||||
|
{
|
||||||
|
|
||||||
|
const auto localId = Controller::instance().activeConnection()->userId();
|
||||||
|
for (auto it = m_room->messageEvents().crbegin(); it != m_room->messageEvents().crend(); ++it) {
|
||||||
|
const auto &evt = **it;
|
||||||
|
if (const auto event = eventCast<const RoomMessageEvent>(&evt)) {
|
||||||
|
if (event->senderId() == localId && event->hasTextContent()) {
|
||||||
|
static QRegularExpression re("^s/([^/]*)/([^/]*)");
|
||||||
|
auto match = re.match(text);
|
||||||
|
if (!match.hasMatch()) {
|
||||||
|
// should not happen but still make sure to send the message normally
|
||||||
|
// just in case.
|
||||||
|
postMessage(text, QString(), QString(), QString(), QVariantMap());
|
||||||
|
}
|
||||||
|
const QString regex = match.captured(1);
|
||||||
|
const QString replacement = match.captured(2);
|
||||||
|
QString originalString;
|
||||||
|
if (event->content()) {
|
||||||
|
originalString = static_cast<const Quotient::EventContent::TextContent *>(event->content())->body;
|
||||||
|
} else {
|
||||||
|
originalString = event->plainBody();
|
||||||
|
}
|
||||||
|
m_room->postHtmlMessage(text, originalString.replace(regex, replacement), event->msgtype(), "", event->id());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ActionsHandler::postMessage(const QString &text,
|
void ActionsHandler::postMessage(const QString &text,
|
||||||
const QString &attachementPath,
|
const QString &attachementPath,
|
||||||
const QString &replyEventId,
|
const QString &replyEventId,
|
||||||
|
|||||||
@@ -58,6 +58,12 @@ public Q_SLOTS:
|
|||||||
void
|
void
|
||||||
postMessage(const QString &text, const QString &attachementPath, const QString &replyEventId, const QString &editEventId, const QVariantMap &usernames);
|
postMessage(const QString &text, const QString &attachementPath, const QString &replyEventId, const QString &editEventId, const QVariantMap &usernames);
|
||||||
|
|
||||||
|
/// \brief Send edit instructions (.e.g s/hallo/hello/)
|
||||||
|
///
|
||||||
|
/// This will automatically edit the last message posted and send the sed
|
||||||
|
/// instruction to IRC.
|
||||||
|
void postEdit(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Connection *m_connection = nullptr;
|
Connection *m_connection = nullptr;
|
||||||
NeoChatRoom *m_room = nullptr;
|
NeoChatRoom *m_room = nullptr;
|
||||||
|
|||||||
@@ -30,6 +30,10 @@
|
|||||||
<label>Show leave and join events in the timeline</label>
|
<label>Show leave and join events in the timeline</label>
|
||||||
<default>true</default>
|
<default>true</default>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry name="AllowQuickEdit" type="bool">
|
||||||
|
<label>Use s/text/replacement syntax to edit your last message.</label>
|
||||||
|
<default>false</default>
|
||||||
|
</entry>
|
||||||
</group>
|
</group>
|
||||||
<group name="Timeline">
|
<group name="Timeline">
|
||||||
<entry name="ShowAvatarInTimeline" type="bool">
|
<entry name="ShowAvatarInTimeline" type="bool">
|
||||||
|
|||||||
Reference in New Issue
Block a user