mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 12:38:48 +03:00
Improve state event redaction
This commit is contained in:
parent
ef53644155
commit
c543b2d4fa
3 changed files with 41 additions and 10 deletions
|
@ -3628,9 +3628,29 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
|
|||
te);
|
||||
// overwrite the content and add redation data
|
||||
std::visit(
|
||||
[redaction](auto &ev) {
|
||||
[&redaction, &room_id, &txn, &eventsDb, this](auto &ev) {
|
||||
ev.unsigned_data.redacted_because = *redaction;
|
||||
ev.unsigned_data.redacted_by = redaction->event_id;
|
||||
|
||||
if constexpr (isStateEvent_<decltype(ev)>) {
|
||||
auto statesdb = getStatesDb(txn, room_id);
|
||||
auto stateskeydb = getStatesKeyDb(txn, room_id);
|
||||
auto membersdb = getMembersDb(txn, room_id);
|
||||
mtx::events::StateEvent<mtx::events::msg::Redacted> redactedEvent;
|
||||
redactedEvent.event_id = ev.event_id;
|
||||
redactedEvent.state_key = ev.state_key;
|
||||
redactedEvent.type = ev.type;
|
||||
nhlog::db()->critical("Redacting: {}",
|
||||
nlohmann::json(redactedEvent).dump(2));
|
||||
|
||||
saveStateEvent(txn,
|
||||
statesdb,
|
||||
stateskeydb,
|
||||
membersdb,
|
||||
eventsDb,
|
||||
room_id,
|
||||
mtx::events::collections::StateEvents{redactedEvent});
|
||||
}
|
||||
},
|
||||
te.data);
|
||||
event = mtx::accessors::serialize_event(te.data);
|
||||
|
@ -5194,8 +5214,8 @@ to_json(nlohmann::json &j, const MemberInfo &info)
|
|||
void
|
||||
from_json(const nlohmann::json &j, MemberInfo &info)
|
||||
{
|
||||
info.name = j.at("name").get<std::string>();
|
||||
info.avatar_url = j.at("avatar_url").get<std::string>();
|
||||
info.name = j.value("name", "");
|
||||
info.avatar_url = j.value("avatar_url", "");
|
||||
info.is_direct = j.value("is_direct", false);
|
||||
info.reason = j.value("reason", "");
|
||||
}
|
||||
|
|
|
@ -113,8 +113,8 @@ struct MemberInfo
|
|||
{
|
||||
std::string name;
|
||||
std::string avatar_url;
|
||||
std::string reason;
|
||||
bool is_direct = false;
|
||||
std::string reason = "";
|
||||
bool is_direct = false;
|
||||
};
|
||||
|
||||
void
|
||||
|
|
|
@ -436,11 +436,22 @@ private:
|
|||
if (e.type != EventType::Unsupported) {
|
||||
if (std::is_same_v<std::remove_cv_t<std::remove_reference_t<decltype(e)>>,
|
||||
StateEvent<mtx::events::msg::Redacted>>) {
|
||||
if (e.type == EventType::RoomMember)
|
||||
membersdb.del(txn, e.state_key, "");
|
||||
else if (e.state_key.empty())
|
||||
statesdb.del(txn, to_string(e.type));
|
||||
else
|
||||
// apply the redaction event
|
||||
if (e.type == EventType::RoomMember) {
|
||||
// membership is not revoked, but names are yeeted (so we set the name
|
||||
// to the mxid)
|
||||
MemberInfo tmp{e.state_key, ""};
|
||||
membersdb.put(txn, e.state_key, nlohmann::json(tmp).dump());
|
||||
} else if (e.state_key.empty()) {
|
||||
// strictly speaking some stuff in those events can be redacted, but
|
||||
// this is close enough. Ref:
|
||||
// https://spec.matrix.org/v1.6/rooms/v10/#redactions
|
||||
if (e.type != EventType::RoomCreate &&
|
||||
e.type != EventType::RoomJoinRules &&
|
||||
e.type != EventType::RoomPowerLevels &&
|
||||
e.type != EventType::RoomHistoryVisibility)
|
||||
statesdb.del(txn, to_string(e.type));
|
||||
} else
|
||||
stateskeydb.del(
|
||||
txn, to_string(e.type), e.state_key + '\0' + e.event_id);
|
||||
} else if (e.state_key.empty()) {
|
||||
|
|
Loading…
Reference in a new issue