diff options
author | DeepBlueV7.X <nicolas.werner@hotmail.de> | 2023-10-25 23:37:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-25 23:37:10 +0000 |
commit | a583de297cf228c05870388b50a340018e8918d3 (patch) | |
tree | 3fb108930f991360fabd9427370ecbdd2715fdbd /src/ChatPage.cpp | |
parent | Add missing include (diff) | |
parent | Switch to X icon and add close button (diff) | |
download | nheko-a583de297cf228c05870388b50a340018e8918d3.tar.xz |
Merge pull request #1541 from NepNep21/ignore-users
Support (un)ignoring users (#546)
Diffstat (limited to 'src/ChatPage.cpp')
-rw-r--r-- | src/ChatPage.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 25af8974..db5cbbe8 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -6,6 +6,9 @@ #include <QInputDialog> #include <QMessageBox> +#include <algorithm> +#include <unordered_set> + #include <mtx/responses.hpp> #include "AvatarProvider.h" @@ -775,6 +778,23 @@ ChatPage::handleSyncResponse(const mtx::responses::Sync &res, const std::string // Ensure that we have enough one-time keys available. ensureOneTimeKeyCount(res.device_one_time_keys_count, res.device_unused_fallback_key_types); + std::optional<mtx::events::account_data::IgnoredUsers> oldIgnoredUsers; + 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()) { + if (auto oldEv = cache::client()->getAccountData(mtx::events::EventType::IgnoredUsers)) + oldIgnoredUsers = + std::get<mtx::events::AccountDataEvent<mtx::events::account_data::IgnoredUsers>>( + *oldEv) + .content; + else + oldIgnoredUsers = mtx::events::account_data::IgnoredUsers{}; + } + // TODO: fine grained error handling try { cache::client()->saveState(res); @@ -783,6 +803,36 @@ ChatPage::handleSyncResponse(const mtx::responses::Sync &res, const std::string auto updates = cache::getRoomInfo(cache::client()->roomsWithStateUpdates(res)); emit syncUI(std::move(res)); + + // if the ignored users changed, clear timeline of all affected rooms. + if (oldIgnoredUsers) { + if (auto newEv = + cache::client()->getAccountData(mtx::events::EventType::IgnoredUsers)) { + std::vector<mtx::events::account_data::IgnoredUser> changedUsers{}; + std::ranges::set_symmetric_difference( + oldIgnoredUsers->users, + std::get<mtx::events::AccountDataEvent<mtx::events::account_data::IgnoredUsers>>( + *newEv) + .content.users, + std::back_inserter(changedUsers), + {}, + &mtx::events::account_data::IgnoredUser::id, + &mtx::events::account_data::IgnoredUser::id); + + std::unordered_set<std::string> roomsToReload; + for (const auto &user : changedUsers) { + auto commonRooms = cache::client()->getCommonRooms(user.id); + for (const auto &room : commonRooms) + roomsToReload.insert(room.first); + } + + for (const auto &room : roomsToReload) { + if (auto model = + view_manager_->rooms()->getRoomById(QString::fromStdString(room))) + model->clearTimeline(); + } + } + } } catch (const lmdb::map_full_error &e) { nhlog::db()->error("lmdb is full: {}", e.what()); cache::deleteOldData(); |