Fix autocompletion
Now it will save a map from display name to id and use that to generate clean matrix.to links. This also make sure the colors used for the preview are correct by using NeoChatUser and fix the bug with the regex by simply removing the regex.
This commit is contained in:
@@ -167,7 +167,8 @@ QVariantMap ChatDocumentHandler::getAutocompletionInfo()
|
||||
};
|
||||
}
|
||||
|
||||
void ChatDocumentHandler::postMessage(const QString &text, const QString &attachementPath, const QString &replyEventId) const
|
||||
void ChatDocumentHandler::postMessage(const QString &text, const QString &attachementPath,
|
||||
const QString &replyEventId, const QVariantMap usernames) const
|
||||
{
|
||||
if (!m_room || !m_document) {
|
||||
return;
|
||||
@@ -177,6 +178,13 @@ void ChatDocumentHandler::postMessage(const QString &text, const QString &attach
|
||||
|
||||
cleanedText = cleanedText.trimmed();
|
||||
|
||||
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) {
|
||||
m_room->uploadFile(attachementPath, cleanedText);
|
||||
}
|
||||
@@ -200,7 +208,7 @@ void ChatDocumentHandler::postMessage(const QString &text, const QString &attach
|
||||
for (int i = 0; i < cleanedText.length(); i++) {
|
||||
rainbowText = rainbowText % QStringLiteral("<font color='") % rainbowColors.at(i % rainbowColors.length()) % "'>" % cleanedText.at(i) % "</font>";
|
||||
}
|
||||
m_room->postHtmlMessage(cleanedText, rainbowText, messageEventType, replyEventId);
|
||||
m_room->postHtmlMessage(text, rainbowText, messageEventType, replyEventId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
[[nodiscard]] NeoChatRoom *room() const;
|
||||
void setRoom(NeoChatRoom *room);
|
||||
|
||||
Q_INVOKABLE void postMessage(const QString &text, const QString &attachementPath, const QString &replyEventId) const;
|
||||
Q_INVOKABLE void postMessage(const QString &text, const QString &attachementPath, const QString &replyEventId, const QVariantMap usernames) const;
|
||||
|
||||
/// This function will look at the current QTextCursor and determine if there
|
||||
/// is the posibility to autocomplete it.
|
||||
|
||||
Reference in New Issue
Block a user