summary refs log tree commit diff
path: root/src/timeline/TimelineModel.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2024-03-08 18:43:59 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2024-03-08 18:45:18 +0100
commit7c2a152cfbc2197989f7d722deb961ac80269019 (patch)
tree1ff5bc7c938ceb2242a0d769f9f64ef5e980f683 /src/timeline/TimelineModel.cpp
parentFix buttons vanishing on the kde themes in the settings page (diff)
downloadnheko-7c2a152cfbc2197989f7d722deb961ac80269019.tar.xz
Add support for intentional mentions
This is still a bit flaky around when to remove a mention, but it should
work in most cases. Might add a toggle in the future to disable these
though.
Diffstat (limited to 'src/timeline/TimelineModel.cpp')
-rw-r--r--src/timeline/TimelineModel.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 05a3c45c..e7fb31f5 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -3069,9 +3069,7 @@ TimelineModel::setEdit(const QString &newEdit)
     }
 
     if (edit_.isEmpty()) {
-        this->textBeforeEdit  = input()->text();
-        this->replyBeforeEdit = reply_;
-        nhlog::ui()->debug("Stored: {}", textBeforeEdit.toStdString());
+        input()->storeForEdit();
     }
 
     auto quoted = [](QString in) { return in.replace("[", "\\[").replace("]", "\\]"); };
@@ -3083,6 +3081,24 @@ TimelineModel::setEdit(const QString &newEdit)
             setReply(QString::fromStdString(mtx::accessors::relations(e).reply_to().value_or("")));
             setThread(QString::fromStdString(mtx::accessors::relations(e).thread().value_or("")));
 
+            auto mentionsList = mtx::accessors::mentions(e);
+            QStringList mentions, mentionTexts;
+            if (mentionsList) {
+                if (mentionsList->room) {
+                    mentions.append(QStringLiteral(u"@room"));
+                    mentionTexts.append(QStringLiteral(u"@room"));
+                }
+
+                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))));
+                }
+            }
+
             auto msgType = mtx::accessors::msg_type(e);
             if (msgType == mtx::events::MessageType::Text ||
                 msgType == mtx::events::MessageType::Notice ||
@@ -3130,6 +3146,7 @@ TimelineModel::setEdit(const QString &newEdit)
             } else {
                 input()->setText(QLatin1String(""));
             }
+            input()->replaceMentions(std::move(mentions), std::move(mentionTexts));
 
             edit_ = newEdit;
         } else {
@@ -3148,9 +3165,7 @@ TimelineModel::resetEdit()
     if (!edit_.isEmpty()) {
         edit_ = QLatin1String("");
         emit editChanged(edit_);
-        nhlog::ui()->debug("Restoring: {}", textBeforeEdit.toStdString());
-        input()->setText(textBeforeEdit);
-        textBeforeEdit.clear();
+        input()->restoreAfterEdit();
         if (replyBeforeEdit.isEmpty())
             resetReply();
         else