Implement quick edit
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "actionshandler.h"
|
||||
#include "controller.h"
|
||||
|
||||
#include "csapi/joining.h"
|
||||
#include <csapi/joining.h>
|
||||
#include <events/roommessageevent.h>
|
||||
|
||||
#include <KLocalizedString>
|
||||
#include <QDebug>
|
||||
@@ -56,6 +58,36 @@ void ActionsHandler::setConnection(Connection *connection)
|
||||
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,
|
||||
const QString &attachementPath,
|
||||
const QString &replyEventId,
|
||||
|
||||
Reference in New Issue
Block a user