Revert "Improve sending message with mentions"

This reverts commit b9d34487a4
This commit is contained in:
Carl Schwan
2021-01-22 14:45:40 +00:00
parent b9d34487a4
commit 0f043e36c4
4 changed files with 30 additions and 16 deletions

View File

@@ -469,9 +469,14 @@ ToolBar {
autoCompleteEndPosition = cursorPosition
}
// store each user we autoComplete here, this will be helpful later to generate
// the matrix.to links.
// This use an hack to define: https://doc.qt.io/qt-5/qml-var.html#property-value-initialization-semantics
property var userAutocompleted: ({})
function postMessage() {
roomManager.actionsHandler.postMessage(inputField.text.trim(), attachmentPath,
replyEventID, editEventId);
replyEventID, editEventId, inputField.userAutocompleted);
clearAttachment();
currentRoom.markAllMessagesAsRead();
clear();
@@ -482,6 +487,10 @@ ToolBar {
function autoComplete() {
documentHandler.replaceAutoComplete(autoCompleteListView.currentItem.displayText)
// Unfortunally it doesn't
if (!autoCompleteListView.currentItem.isEmoji) {
inputField.userAutocompleted[autoCompleteListView.currentItem.displayText] = autoCompleteListView.currentItem.userId;
}
}
}
}
@@ -574,6 +583,7 @@ ToolBar {
function clear() {
inputField.clear()
inputField.userAutocompleted = {};
}
function clearEditReply() {

View File

@@ -159,15 +159,16 @@ void ActionsHandler::createRoom(const QString &name, const QString &topic)
}
void ActionsHandler::postMessage(const QString &text,
const QString &attachementPath, const QString &replyEventId, const QString &editEventId)
const QString &attachementPath, const QString &replyEventId, const QString &editEventId,
const QVariantMap usernames)
{
QString rawText = text;
QString cleanedText = text;
for (const auto *user : m_room->users()) {
const auto displayName = user->displayname(m_room);
cleanedText = cleanedText.replace(displayName,
"[" + displayName + "](https://matrix.to/#/" + user->id() + ")");
for (const auto username : usernames.keys()) {
const auto replacement = usernames.value(username);
cleanedText = cleanedText.replace(username,
"[" + username + "](https://matrix.to/#/" + replacement.toString() + ")");
}
if (attachementPath.length() > 0) {
@@ -270,6 +271,9 @@ void ActionsHandler::postMessage(const QString &text,
if (rawText.indexOf(partPrefix) == 0) {
rawText = rawText.remove(0, partPrefix.length());
const QStringList splittedText = rawText.split(" ");
qDebug() << m_room;
qDebug() << "m_room";
qDebug() << splittedText;
if (splittedText.count() == 0 || splittedText[0].isEmpty()) {
// leave current room
m_connection->leaveRoom(m_room);

View File

@@ -70,7 +70,8 @@ public Q_SLOTS:
///
/// This also interprets commands if any.
void postMessage(const QString &text, const QString &attachementPath,
const QString &replyEventId, const QString &editEventId);
const QString &replyEventId, const QString &editEventId,
const QVariantMap usernames);
private:
Connection *m_connection = nullptr;

View File

@@ -99,6 +99,7 @@ void NeoChatRoom::uploadFile(const QUrl &url, const QString &body)
});
connect(this, &Room::fileTransferProgress, [=](const QString &id, qint64 progress, qint64 total) {
if (id == txnId) {
qDebug() << "Progress:" << progress << total;
setFileUploadingProgress(int(float(progress) / float(total) * 100));
}
});
@@ -535,7 +536,9 @@ void NeoChatRoom::postMessage(const QString &text, MessageEventType type, const
void NeoChatRoom::postHtmlMessage(const QString &text, const QString &html, MessageEventType type, const QString &replyEventId, const QString &relateToEventId)
{
bool isRichText = Qt::mightBeRichText(html);
QString htmlWithLinks = html;
htmlWithLinks = htmlWithLinks.replace(QRegularExpression("@([^: ]*):([^ ]*\\.[^ ]*)"), "<a href=\"https://matrix.to/#/@$1:$2\">@$1:$2</a>");
bool isRichText = Qt::mightBeRichText(htmlWithLinks);
bool isReply = !replyEventId.isEmpty();
bool isEdit = !relateToEventId.isEmpty();
const auto replyIt = findInTimeline(replyEventId);
@@ -548,15 +551,11 @@ void NeoChatRoom::postHtmlMessage(const QString &text, const QString &html, Mess
QJsonObject json {
{"type", "m.room.message"},
{"msgtype", msgTypeToString(type)},
{"body", "* " + text},
{"format", "org.matrix.custom.html"},
{"formatted_body", html},
{"body", "* " + (isRichText ? text : htmlWithLinks)},
{"m.new_content",
QJsonObject {
{"body", text},
{"msgtype", msgTypeToString(type)},
{"format", "org.matrix.custom.html"},
{"formatted_body", html}
{"body", (isRichText ? text : htmlWithLinks)},
{"msgtype", msgTypeToString(type)}
}
},
{"m.relates_to",
@@ -595,7 +594,7 @@ void NeoChatRoom::postHtmlMessage(const QString &text, const QString &html, Mess
"\">In reply to</a> <a href=\"https://matrix.to/#/" +
replyEvt.senderId() + "\">" + replyEvt.senderId() +
"</a><br>" + eventToString(replyEvt, Qt::RichText) +
"</blockquote></mx-reply>" + (isRichText ? html : text)
"</blockquote></mx-reply>" + (isRichText ? htmlWithLinks : text)
}
};
// clang-format on