From 4eaba191de4fc1ae1709b90c97ec4030397f1d7c Mon Sep 17 00:00:00 2001 From: NepNep21 <43792621+NepNep21@users.noreply.github.com> Date: Thu, 7 Sep 2023 18:10:04 -0300 Subject: Use properties --- src/timeline/TimelineViewManager.cpp | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/timeline/TimelineViewManager.cpp') diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index b8bd679b..3e623d7a 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -12,6 +12,7 @@ #include #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,39 @@ TimelineViewManager::fixImageRendering(QQuickTextDocument *t, QQuickItem *i) QObject::connect(t->textDocument(), SIGNAL(imagesLoaded()), i, SLOT(updateWholeDocument())); } } + +using IgnoredUsers = mtx::events::EphemeralEvent; + +static QVector convertIgnoredToQt(const IgnoredUsers &ev) { + QVector users; + for (const mtx::events::account_data::IgnoredUser &user : ev.content.users) { + users.push_back(QString::fromStdString(user.id)); + } + + return users; +} + +QVector +TimelineViewManager::getIgnoredUsers() +{ + const auto cache = cache::client()->getAccountData(mtx::events::EventType::IgnoredUsers); + if (!cache) { + return {}; + } + + return convertIgnoredToQt(std::get(*cache)); +} + +void +TimelineViewManager::processIgnoredUsers(const mtx::responses::AccountData &data) +{ + for (const mtx::events::collections::RoomAccountDataEvents::variant &ev : data.events) { + if (!std::holds_alternative(ev)) { + continue; + } + const auto &ignoredEv = std::get(ev); + + emit this->ignoredUsersChanged(convertIgnoredToQt(ignoredEv)); + break; + } +} \ No newline at end of file -- cgit 1.5.1