summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2024-05-31 18:17:35 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2024-05-31 18:28:16 +0200
commitec9af40fc50142f32924efd9235ca5912b6fe395 (patch)
treef81bba9db7cff61d5f967d7ded1fb192108de3e9 /src/timeline
parentDisable image loaded workaround for Qt 6.7 and up (diff)
downloadnheko-ec9af40fc50142f32924efd9235ca5912b6fe395.tar.xz
fix mentions with markdown and in edits
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/InputBar.cpp4
-rw-r--r--src/timeline/TimelineModel.cpp16
2 files changed, 11 insertions, 9 deletions
diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp
index ac1d47a2..2d15d01a 100644
--- a/src/timeline/InputBar.cpp
+++ b/src/timeline/InputBar.cpp
@@ -462,8 +462,7 @@ replaceMatrixToMarkdownLink(QString input)
         int newline   = input.indexOf('\n', endOfName);
         if (endOfLink > endOfName && (newline == -1 || endOfLink < newline)) {
             auto name = input.mid(startOfName + 1, endOfName - startOfName - 1);
-            name.replace("\\[", "[");
-            name.replace("\\]", "]");
+            name.remove(QChar(u'\\'), Qt::CaseSensitive);
             input.replace(startOfName, endOfLink - startOfName + 1, name);
             replaced = true;
         }
@@ -522,6 +521,7 @@ InputBar::generateMentions()
     // this->containsAtRoom_ = false;
     // this->mentions_.clear();
     // this->mentionTexts_.clear();
+
     return mention;
 }
 
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 03606d90..4aa9af00 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -3080,8 +3080,6 @@ TimelineModel::setEdit(const QString &newEdit)
         input()->storeForEdit();
     }
 
-    auto quoted = [](QString in) { return in.replace("[", "\\[").replace("]", "\\]"); };
-
     if (edit_ != newEdit) {
         auto ev = events.get(newEdit.toStdString(), "");
         if (ev && mtx::accessors::sender(*ev) == http::client()->user_id().to_string()) {
@@ -3100,10 +3098,12 @@ TimelineModel::setEdit(const QString &newEdit)
                 for (const auto &user : mentionsList->user_ids) {
                     auto userid = QString::fromStdString(user);
                     mentions.append(userid);
-                    mentionTexts.append(
-                      QStringLiteral("[%1](https://matrix.to/#/%2)")
-                        .arg(displayName(userid).replace("[", "\\[").replace("]", "\\]"),
-                             QString(QUrl::toPercentEncoding(userid))));
+                    mentionTexts.append(QStringLiteral("[%1](https://matrix.to/#/%2)")
+                                          .arg(utils::escapeMentionMarkdown(
+                                                 // not using TimelineModel::displayName here,
+                                                 // because it would double html escape
+                                                 cache::displayName(room_id_, userid)),
+                                               QString(QUrl::toPercentEncoding(userid))));
                 }
             }
 
@@ -3127,7 +3127,9 @@ TimelineModel::setEdit(const QString &newEdit)
 
                     for (const auto &[user, link] : reverseNameMapping) {
                         // TODO(Nico): html unescape the user name
-                        editText.replace(user, QStringLiteral("[%1](%2)").arg(quoted(user), link));
+                        editText.replace(
+                          user,
+                          QStringLiteral("[%1](%2)").arg(utils::escapeMentionMarkdown(user), link));
                     }
                 }