summary refs log tree commit diff
path: root/src/UsersModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/UsersModel.cpp')
-rw-r--r--src/UsersModel.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/UsersModel.cpp b/src/UsersModel.cpp
index a017aa84..61d1bddd 100644
--- a/src/UsersModel.cpp
+++ b/src/UsersModel.cpp
@@ -11,6 +11,7 @@
 #include "CompletionModelRoles.h"
 #include "Logging.h"
 #include "UserSettingsPage.h"
+#include "Utils.h"
 
 UsersModel::UsersModel(const std::string &roomId, QObject *parent)
   : QAbstractListModel(parent)
@@ -24,10 +25,13 @@ UsersModel::UsersModel(const std::string &roomId, QObject *parent)
                   std::get_if<mtx::events::AccountDataEvent<mtx::events::account_data::Direct>>(
                     &e.value())) {
                 for (const auto &[userId, roomIds] : event->content.user_to_rooms) {
+                    if (roomIds.empty())
+                        continue;
+
                     displayNames.push_back(
-                      QString::fromStdString(cache::displayName(roomIds[0], userId)));
+                      QString::fromStdString(cache::displayName(roomIds.at(0), userId)));
                     userids.push_back(QString::fromStdString(userId));
-                    avatarUrls.push_back(cache::avatarUrl(QString::fromStdString(roomIds[0]),
+                    avatarUrls.push_back(cache::avatarUrl(QString::fromStdString(roomIds.at(0)),
                                                           QString::fromStdString(userId)));
                 }
             }
@@ -66,10 +70,7 @@ UsersModel::data(const QModelIndex &index, int role) const
         case CompletionModel::CompletionRole:
             if (UserSettings::instance()->markdown())
                 return QStringLiteral("[%1](https://matrix.to/#/%2)")
-                  .arg(QString(displayNames[index.row()])
-                         .replace("[", "\\[")
-                         .replace("]", "\\]")
-                         .toHtmlEscaped(),
+                  .arg(utils::escapeMentionMarkdown(QString(displayNames[index.row()])),
                        QString(QUrl::toPercentEncoding(userids[index.row()])));
             else
                 return displayNames[index.row()];