summary refs log tree commit diff
path: root/src/ui/UserProfile.cpp
diff options
context:
space:
mode:
authorDeepBlueV7.X <nicolas.werner@hotmail.de>2023-10-25 23:37:10 +0000
committerGitHub <noreply@github.com>2023-10-25 23:37:10 +0000
commita583de297cf228c05870388b50a340018e8918d3 (patch)
tree3fb108930f991360fabd9427370ecbdd2715fdbd /src/ui/UserProfile.cpp
parentAdd missing include (diff)
parentSwitch to X icon and add close button (diff)
downloadnheko-a583de297cf228c05870388b50a340018e8918d3.tar.xz
Merge pull request #1541 from NepNep21/ignore-users
Support (un)ignoring users (#546)
Diffstat (limited to 'src/ui/UserProfile.cpp')
-rw-r--r--src/ui/UserProfile.cpp64
1 files changed, 58 insertions, 6 deletions
diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp
index 80def409..1b66a97d 100644
--- a/src/ui/UserProfile.cpp
+++ b/src/ui/UserProfile.cpp
@@ -11,11 +11,11 @@
 #include "Cache_p.h"
 #include "ChatPage.h"
 #include "Logging.h"
+#include "MainWindow.h"
+#include "MatrixClient.h"
 #include "UserProfile.h"
 #include "Utils.h"
-#include "encryption/DeviceVerificationFlow.h"
 #include "encryption/VerificationManager.h"
-#include "mtx/responses/crypto.hpp"
 #include "timeline/TimelineModel.h"
 #include "timeline/TimelineViewManager.h"
 #include "ui/UIA.h"
@@ -64,6 +64,19 @@ UserProfile::UserProfile(const QString &roomid,
           new RoomInfoModel(cache::client()->getCommonRooms(userid.toStdString()), this);
     else
         sharedRooms_ = new RoomInfoModel({}, this);
+
+    connect(ChatPage::instance(), &ChatPage::syncUI, this, [this](const mtx::responses::Sync &res) {
+        if (auto ignoreEv = std::ranges::find_if(
+              res.account_data.events,
+              [](const mtx::events::collections::RoomAccountDataEvents &e) {
+                  return std::holds_alternative<
+                    mtx::events::AccountDataEvent<mtx::events::account_data::IgnoredUsers>>(e);
+              });
+            ignoreEv != res.account_data.events.end()) {
+            // doesn't matter much if it was actually us
+            emit ignoredChanged();
+        }
+    });
 }
 
 QHash<int, QByteArray>
@@ -224,6 +237,49 @@ UserProfile::refreshDevices()
     fetchDeviceList(this->userid_);
 }
 
+bool
+UserProfile::ignored() const
+{
+    auto old = TimelineViewManager::instance()->getIgnoredUsers();
+    return old.contains(userid_);
+}
+
+void
+UserProfile::setIgnored(bool ignore)
+{
+    auto old = TimelineViewManager::instance()->getIgnoredUsers();
+    if (ignore) {
+        if (old.contains(userid_)) {
+            emit ignoredChanged();
+            return;
+        }
+        old.append(userid_);
+    } else {
+        if (!old.contains(userid_)) {
+            emit ignoredChanged();
+            return;
+        }
+        old.removeAll(userid_);
+    }
+
+    std::vector<mtx::events::account_data::IgnoredUser> content;
+    for (const QString &item : std::as_const(old)) {
+        content.emplace_back(item.toStdString());
+    }
+
+    mtx::events::account_data::IgnoredUsers payload{.users{content}};
+
+    auto userid = userid_;
+
+    http::client()->put_account_data(payload, [userid](mtx::http::RequestErr e) {
+        if (e) {
+            MainWindow::instance()->showNotification(
+              tr("Failed to ignore \"%1\": %2")
+                .arg(userid, QString::fromStdString(e->matrix_error.error)));
+        }
+    });
+}
+
 void
 UserProfile::fetchDeviceList(const QString &userID)
 {
@@ -345,10 +401,6 @@ UserProfile::banUser()
     ChatPage::instance()->banUser(roomid_, this->userid_, QLatin1String(""));
 }
 
-// void ignoreUser(){
-
-// }
-
 void
 UserProfile::kickUser()
 {