Cleanup ignore user functionality slightly
This commit is contained in:
parent
fce026725e
commit
a0a49b6c2a
7 changed files with 102 additions and 46 deletions
|
|
@ -6,6 +6,9 @@
|
|||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <algorithm>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <mtx/responses.hpp>
|
||||
|
||||
#include "AvatarProvider.h"
|
||||
|
|
@ -21,7 +24,6 @@
|
|||
#include "encryption/DeviceVerificationFlow.h"
|
||||
#include "encryption/Olm.h"
|
||||
#include "ui/RoomSummary.h"
|
||||
#include "ui/Theme.h"
|
||||
#include "ui/UserProfile.h"
|
||||
#include "voip/CallManager.h"
|
||||
|
||||
|
|
@ -29,8 +31,6 @@
|
|||
|
||||
#include "timeline/TimelineViewManager.h"
|
||||
|
||||
#include "blurhash.hpp"
|
||||
|
||||
ChatPage *ChatPage::instance_ = nullptr;
|
||||
static constexpr int CHECK_CONNECTIVITY_INTERVAL = 15'000;
|
||||
static constexpr int RETRY_TIMEOUT = 5'000;
|
||||
|
|
@ -765,6 +765,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);
|
||||
|
|
@ -773,6 +790,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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue