summary refs log tree commit diff
path: root/src/ui
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
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')
-rw-r--r--src/ui/UserProfile.cpp64
-rw-r--r--src/ui/UserProfile.h6
2 files changed, 63 insertions, 7 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() { diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h
index d8e06aa1..bc5b6a35 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h
@@ -157,6 +157,7 @@ class UserProfile final : public QObject Q_PROPERTY(int userVerified READ getUserStatus NOTIFY userStatusChanged) Q_PROPERTY(bool isLoading READ isLoading NOTIFY loadingChanged) Q_PROPERTY(bool userVerificationEnabled READ userVerificationEnabled NOTIFY userStatusChanged) + Q_PROPERTY(bool ignored READ ignored WRITE setIgnored NOTIFY ignoredChanged) Q_PROPERTY(bool isSelf READ isSelf CONSTANT) Q_PROPERTY(TimelineModel *room READ room CONSTANT) public: @@ -184,7 +185,6 @@ public: Q_INVOKABLE void refreshDevices(); Q_INVOKABLE void banUser(); Q_INVOKABLE void signOutDevice(const QString &deviceID); - // Q_INVOKABLE void ignoreUser(); Q_INVOKABLE void kickUser(); Q_INVOKABLE void startChat(); Q_INVOKABLE void startChat(bool encryptionEnabled); @@ -193,6 +193,9 @@ public: Q_INVOKABLE void changeAvatar(); Q_INVOKABLE void openGlobalProfile(); + void setIgnored(bool ignored); + bool ignored() const; + signals: void userStatusChanged(); void loadingChanged(); @@ -201,6 +204,7 @@ signals: void displayError(const QString &errorMessage); void globalUsernameRetrieved(const QString &globalUser); void devicesChanged(); + void ignoredChanged(); // internal void verificationStatiChanged();