Hidden events: Make reusable read function

This commit is contained in:
tastytea 2022-01-13 05:49:32 +01:00 committed by Nicolas Werner
parent 72cfb06208
commit 7ebced29e9
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
2 changed files with 16 additions and 9 deletions

View file

@ -229,15 +229,7 @@ RoomSettings::RoomSettings(QString roomid, QObject *parent)
}
emit accessJoinRulesChanged();
if (auto hiddenEvents = cache::client()->getAccountData(
mtx::events::EventType::NhekoHiddenEvents, roomid_.toStdString())) {
if (auto tmp = std::get_if<mtx::events::EphemeralEvent<
mtx::events::account_data::nheko_extensions::HiddenEvents>>(&*hiddenEvents)) {
for (const auto event : tmp->content.hidden_event_types) {
hiddenEvents_.insert(mtx::events::to_string(event).data());
}
}
}
readHiddenEventsSettings(roomid_);
}
QString
@ -682,3 +674,17 @@ RoomSettings::eventHidden(const QString event) const
{
return hiddenEvents_.contains(event);
}
void
RoomSettings::readHiddenEventsSettings(const QString &roomId)
{
if (auto hiddenEvents = cache::client()->getAccountData(
mtx::events::EventType::NhekoHiddenEvents, roomId.toStdString())) {
if (auto tmp = std::get_if<mtx::events::EphemeralEvent<
mtx::events::account_data::nheko_extensions::HiddenEvents>>(&*hiddenEvents)) {
for (const auto event : tmp->content.hidden_event_types) {
hiddenEvents_.insert(mtx::events::to_string(event).data());
}
}
}
}

View file

@ -134,6 +134,7 @@ private:
void updateAccessRules(const std::string &room_id,
const mtx::events::state::JoinRules &,
const mtx::events::state::GuestAccess &);
void readHiddenEventsSettings(const QString &roomId = {});
private:
QString roomid_;