summary refs log tree commit diff
path: root/src/timeline/TimelineViewManager.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/timeline/TimelineViewManager.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/timeline/TimelineViewManager.cpp')
-rw-r--r--src/timeline/TimelineViewManager.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp

index b8bd679b..e2616c14 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp
@@ -12,6 +12,7 @@ #include <QString> #include "Cache.h" +#include "Cache_p.h" #include "ChatPage.h" #include "CombinedImagePackModel.h" #include "CommandCompleter.h" @@ -210,6 +211,7 @@ TimelineViewManager::sync(const mtx::responses::Sync &sync_) this->rooms_->sync(sync_); this->communities_->sync(sync_); this->presenceEmitter->sync(sync_.presence); + this->processIgnoredUsers(sync_.account_data); if (isInitialSync_) { this->isInitialSync_ = false; @@ -560,3 +562,41 @@ TimelineViewManager::fixImageRendering(QQuickTextDocument *t, QQuickItem *i) QObject::connect(t->textDocument(), SIGNAL(imagesLoaded()), i, SLOT(updateWholeDocument())); } } + +using IgnoredUsers = mtx::events::EphemeralEvent<mtx::events::account_data::IgnoredUsers>; + +static QVector<QString> +convertIgnoredToQt(const IgnoredUsers &ev) +{ + QVector<QString> users; + for (const mtx::events::account_data::IgnoredUser &user : ev.content.users) { + users.push_back(QString::fromStdString(user.id)); + } + + return users; +} + +QVector<QString> +TimelineViewManager::getIgnoredUsers() +{ + const auto cache = cache::client()->getAccountData(mtx::events::EventType::IgnoredUsers); + if (!cache) { + return {}; + } + + return convertIgnoredToQt(std::get<IgnoredUsers>(*cache)); +} + +void +TimelineViewManager::processIgnoredUsers(const mtx::responses::AccountData &data) +{ + for (const mtx::events::collections::RoomAccountDataEvents::variant &ev : data.events) { + if (!std::holds_alternative<IgnoredUsers>(ev)) { + continue; + } + const auto &ignoredEv = std::get<IgnoredUsers>(ev); + + emit this->ignoredUsersChanged(convertIgnoredToQt(ignoredEv)); + break; + } +} \ No newline at end of file