mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 06:08:48 +03:00
Store all state events
This commit is contained in:
parent
6548b84e29
commit
86766b739d
3 changed files with 38 additions and 51 deletions
|
@ -91,6 +91,26 @@ namespace {
|
||||||
std::unique_ptr<Cache> instance_ = nullptr;
|
std::unique_ptr<Cache> instance_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
bool
|
||||||
|
containsStateUpdates(const T &e)
|
||||||
|
{
|
||||||
|
return std::visit([](const auto &ev) { return Cache::isStateEvent(ev); }, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
containsStateUpdates(const mtx::events::collections::StrippedEvents &e)
|
||||||
|
{
|
||||||
|
using namespace mtx::events;
|
||||||
|
using namespace mtx::events::state;
|
||||||
|
|
||||||
|
return std::holds_alternative<StrippedEvent<state::Avatar>>(e) ||
|
||||||
|
std::holds_alternative<StrippedEvent<CanonicalAlias>>(e) ||
|
||||||
|
std::holds_alternative<StrippedEvent<Name>>(e) ||
|
||||||
|
std::holds_alternative<StrippedEvent<Member>>(e) ||
|
||||||
|
std::holds_alternative<StrippedEvent<Topic>>(e);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Cache::isHiddenEvent(lmdb::txn &txn,
|
Cache::isHiddenEvent(lmdb::txn &txn,
|
||||||
mtx::events::collections::TimelineEvents e,
|
mtx::events::collections::TimelineEvents e,
|
||||||
|
|
|
@ -271,6 +271,17 @@ public:
|
||||||
void deleteSecret(const std::string &name);
|
void deleteSecret(const std::string &name);
|
||||||
std::optional<std::string> secret(const std::string &name);
|
std::optional<std::string> secret(const std::string &name);
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
static constexpr bool isStateEvent(const mtx::events::StateEvent<T> &)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
template<class T>
|
||||||
|
static constexpr bool isStateEvent(const mtx::events::Event<T> &)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void newReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
|
void newReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
|
||||||
void roomReadStatus(const std::map<QString, bool> &status);
|
void roomReadStatus(const std::map<QString, bool> &status);
|
||||||
|
@ -368,58 +379,14 @@ private:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isStateEvent(event))
|
std::visit(
|
||||||
return;
|
[&txn, &statesdb](auto e) {
|
||||||
|
if constexpr (isStateEvent(e))
|
||||||
std::visit([&txn, &statesdb](
|
statesdb.put(txn, to_string(e.type), json(e).dump());
|
||||||
auto e) { statesdb.put(txn, to_string(e.type), json(e).dump()); },
|
},
|
||||||
event);
|
event);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
|
||||||
bool isStateEvent(const T &e)
|
|
||||||
{
|
|
||||||
using namespace mtx::events;
|
|
||||||
using namespace mtx::events::state;
|
|
||||||
|
|
||||||
return std::holds_alternative<StateEvent<Aliases>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<state::Avatar>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<CanonicalAlias>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<Create>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<GuestAccess>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<HistoryVisibility>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<JoinRules>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<Name>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<Member>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<PowerLevels>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<Topic>>(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
bool containsStateUpdates(const T &e)
|
|
||||||
{
|
|
||||||
using namespace mtx::events;
|
|
||||||
using namespace mtx::events::state;
|
|
||||||
|
|
||||||
return std::holds_alternative<StateEvent<state::Avatar>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<CanonicalAlias>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<Name>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<Member>>(e) ||
|
|
||||||
std::holds_alternative<StateEvent<Topic>>(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool containsStateUpdates(const mtx::events::collections::StrippedEvents &e)
|
|
||||||
{
|
|
||||||
using namespace mtx::events;
|
|
||||||
using namespace mtx::events::state;
|
|
||||||
|
|
||||||
return std::holds_alternative<StrippedEvent<state::Avatar>>(e) ||
|
|
||||||
std::holds_alternative<StrippedEvent<CanonicalAlias>>(e) ||
|
|
||||||
std::holds_alternative<StrippedEvent<Name>>(e) ||
|
|
||||||
std::holds_alternative<StrippedEvent<Member>>(e) ||
|
|
||||||
std::holds_alternative<StrippedEvent<Topic>>(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
void saveInvites(lmdb::txn &txn,
|
void saveInvites(lmdb::txn &txn,
|
||||||
const std::map<std::string, mtx::responses::InvitedRoom> &rooms);
|
const std::map<std::string, mtx::responses::InvitedRoom> &rooms);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue