mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd:Ⓜ️ Demote membership from top-level key; remove from m::event tuple.
This commit is contained in:
parent
5d3dd964a0
commit
d64a49428e
19 changed files with 19 additions and 115 deletions
|
@ -60,8 +60,6 @@ enum ircd::m::event::conforms::code
|
|||
MISSING_ORIGIN, ///< origin empty
|
||||
INVALID_ORIGIN, ///< origin not a proper domain
|
||||
INVALID_OR_MISSING_REDACTS_ID, ///< for m.room.redaction
|
||||
MISSING_MEMBERSHIP, ///< for m.room.member, membership empty
|
||||
INVALID_MEMBERSHIP, ///< for m.room.member (does not check actual states)
|
||||
MISSING_CONTENT_MEMBERSHIP, ///< for m.room.member, content.membership
|
||||
INVALID_CONTENT_MEMBERSHIP, ///< for m.room.member, content.membership
|
||||
MISSING_PREV_EVENTS, ///< for non-m.room.create, empty prev_events
|
||||
|
|
|
@ -65,7 +65,6 @@ struct ircd::m::event
|
|||
json::property<name::depth, int64_t>,
|
||||
json::property<name::event_id, json::string>,
|
||||
json::property<name::hashes, json::object>,
|
||||
json::property<name::membership, json::string>,
|
||||
json::property<name::origin, json::string>,
|
||||
json::property<name::origin_server_ts, time_t>,
|
||||
json::property<name::prev_events, json::array>,
|
||||
|
|
|
@ -2596,7 +2596,7 @@ const
|
|||
{
|
||||
const string_view &membership_
|
||||
{
|
||||
unquote(at<"content"_>(event).at("membership"))
|
||||
m::membership(event)
|
||||
};
|
||||
|
||||
if(membership && membership_ != membership)
|
||||
|
|
|
@ -338,9 +338,12 @@ ircd::m::check_size(std::nothrow_t,
|
|||
ircd::string_view
|
||||
ircd::m::membership(const event &event)
|
||||
{
|
||||
return json::get<"membership"_>(event)?
|
||||
string_view{json::get<"membership"_>(event)}:
|
||||
unquote(json::get<"content"_>(event).get("membership"));
|
||||
const json::object &content
|
||||
{
|
||||
json::get<"content"_>(event)
|
||||
};
|
||||
|
||||
return unquote(content.get("membership"));
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@ -1591,8 +1594,6 @@ ircd::m::event_conforms_reflects
|
|||
"MISSING_ORIGIN",
|
||||
"INVALID_ORIGIN",
|
||||
"INVALID_OR_MISSING_REDACTS_ID",
|
||||
"MISSING_MEMBERSHIP",
|
||||
"INVALID_MEMBERSHIP",
|
||||
"MISSING_CONTENT_MEMBERSHIP",
|
||||
"INVALID_CONTENT_MEMBERSHIP",
|
||||
"MISSING_PREV_EVENTS",
|
||||
|
@ -1697,14 +1698,6 @@ ircd::m::event::conforms::conforms(const event &e)
|
|||
if(json::get<"redacts"_>(e) == json::get<"event_id"_>(e))
|
||||
set(SELF_REDACTS);
|
||||
|
||||
if(json::get<"type"_>(e) == "m.room.member")
|
||||
if(empty(json::get<"membership"_>(e)))
|
||||
set(MISSING_MEMBERSHIP);
|
||||
|
||||
if(json::get<"type"_>(e) == "m.room.member")
|
||||
if(!all_of<std::islower>(json::get<"membership"_>(e)))
|
||||
set(INVALID_MEMBERSHIP);
|
||||
|
||||
if(json::get<"type"_>(e) == "m.room.member")
|
||||
if(empty(unquote(json::get<"content"_>(e).get("membership"))))
|
||||
set(MISSING_CONTENT_MEMBERSHIP);
|
||||
|
|
|
@ -371,53 +371,20 @@ ircd::m::room::membership(const mutable_buffer &out,
|
|||
const m::id::user &user_id)
|
||||
const
|
||||
{
|
||||
static const event::keys::selection membership_keys
|
||||
{
|
||||
event::keys::include{"membership"}
|
||||
};
|
||||
|
||||
// Since this is a member function of m::room there might be a supplied
|
||||
// fopts. Whatever keys it has are irrelevant, but we can preserve gopts.
|
||||
const m::event::fetch::opts fopts
|
||||
{
|
||||
membership_keys, this->fopts? this->fopts->gopts : db::gopts{}
|
||||
};
|
||||
|
||||
string_view ret;
|
||||
const auto result_closure{[&out, &ret]
|
||||
(const m::event &event)
|
||||
const room::state state{*this};
|
||||
state.get(std::nothrow, "m.room.member", user_id, [&out, &ret]
|
||||
(const event::idx &event_idx)
|
||||
{
|
||||
ret =
|
||||
m::get(std::nothrow, event_idx, "content", [&out, &ret]
|
||||
(const json::object &content)
|
||||
{
|
||||
data(out), copy(out, m::membership(event))
|
||||
};
|
||||
}};
|
||||
|
||||
const room::state state{*this, &fopts};
|
||||
const bool exists
|
||||
{
|
||||
state.get(std::nothrow, "m.room.member"_sv, user_id, result_closure)
|
||||
};
|
||||
|
||||
// This branch is taken when the event exists but the event.membership had
|
||||
// no value. Due to wanton protocol violations event.membership may be
|
||||
// jsundefined and only event.content.membership will exist in event. This
|
||||
// is a rare case so both queries are optimized to only seek for their key.
|
||||
if(exists && !ret)
|
||||
{
|
||||
static const event::keys::selection content_membership_keys
|
||||
{
|
||||
event::keys::include{"content"}
|
||||
};
|
||||
|
||||
const m::event::fetch::opts fopts
|
||||
{
|
||||
content_membership_keys, this->fopts? this->fopts->gopts : db::gopts{}
|
||||
};
|
||||
|
||||
const room::state state{*this, &fopts};
|
||||
state.get(std::nothrow, "m.room.member"_sv, user_id, result_closure);
|
||||
}
|
||||
ret =
|
||||
{
|
||||
data(out), copy(out, unquote(content.get("membership")))
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -1643,7 +1610,6 @@ const
|
|||
static const event::keys::include keys
|
||||
{
|
||||
"event_id", // Added for any upstack usage (but may be unnecessary).
|
||||
"membership", // Required for membership test.
|
||||
"content", // Required because synapse events randomly have no event.membership
|
||||
};
|
||||
|
||||
|
@ -1726,9 +1692,8 @@ const
|
|||
static const event::keys::include keys
|
||||
{
|
||||
"event_id",
|
||||
"membership",
|
||||
"state_key",
|
||||
"content", // Required because synapse events randomly have no event.membership
|
||||
"content",
|
||||
};
|
||||
|
||||
// In this case the fetch opts isn't static so it can maintain the
|
||||
|
|
|
@ -41,7 +41,6 @@ default_fetch_opts
|
|||
"content",
|
||||
"depth",
|
||||
"event_id",
|
||||
"membership",
|
||||
"origin_server_ts",
|
||||
"redacts",
|
||||
"room_id",
|
||||
|
|
|
@ -65,7 +65,6 @@ invite__room_user(const m::room &room,
|
|||
{ event, { "type", "m.room.member" }},
|
||||
{ event, { "sender", sender }},
|
||||
{ event, { "state_key", target }},
|
||||
{ event, { "membership", "invite" }},
|
||||
{ content, { "membership", "invite" }},
|
||||
};
|
||||
|
||||
|
|
|
@ -69,7 +69,6 @@ join__room_user(const room &room,
|
|||
{ event, { "type", "m.room.member" }},
|
||||
{ event, { "sender", user_id }},
|
||||
{ event, { "state_key", user_id }},
|
||||
{ event, { "membership", "join" }},
|
||||
{ content, { "membership", "join" }},
|
||||
};
|
||||
|
||||
|
@ -192,7 +191,6 @@ bootstrap(const string_view &host,
|
|||
{ event, { "type", "m.room.member" }},
|
||||
{ event, { "sender", user_id }},
|
||||
{ event, { "state_key", user_id }},
|
||||
{ event, { "membership", "join" }},
|
||||
{ content, { "membership", "join" }},
|
||||
{ event, { "prev_events", prev_events }},
|
||||
{ event, { "auth_events", auth_events }},
|
||||
|
@ -241,7 +239,6 @@ bootstrap(const string_view &host,
|
|||
};
|
||||
|
||||
m::vm::copts opts;
|
||||
opts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
opts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
opts.prev_check_exists = false;
|
||||
opts.head_must_exist = false;
|
||||
|
|
|
@ -76,7 +76,6 @@ kick(const m::room &room,
|
|||
{
|
||||
{ event, { "type", "m.room.member" }},
|
||||
{ event, { "sender", sender }},
|
||||
{ event, { "membership", "leave" }},
|
||||
{ content, { "membership", "leave" }},
|
||||
};
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ leave__room_user(const room &room,
|
|||
{ event, { "type", "m.room.member" }},
|
||||
{ event, { "sender", user_id }},
|
||||
{ event, { "state_key", user_id }},
|
||||
{ event, { "membership", "leave" }},
|
||||
{ content, { "membership", "leave" }},
|
||||
};
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ default_fetch_opts
|
|||
"content",
|
||||
"depth",
|
||||
"event_id",
|
||||
"membership",
|
||||
"origin_server_ts",
|
||||
"prev_events",
|
||||
"redacts",
|
||||
|
|
|
@ -213,16 +213,5 @@ state__iov(const room &room,
|
|||
{ event, { "state_key", state_key }},
|
||||
};
|
||||
|
||||
const json::iov::add member_
|
||||
{
|
||||
event, type == "m.room.member",
|
||||
{
|
||||
"membership", [&content]() -> json::value
|
||||
{
|
||||
return content.at("membership");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return commit(room, event, content);
|
||||
}
|
||||
|
|
|
@ -6031,7 +6031,6 @@ console_cmd__eval__file(opt &out, const string_view &line)
|
|||
|
||||
m::vm::opts opts;
|
||||
opts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
opts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
opts.prev_check_exists = false;
|
||||
opts.notify = false;
|
||||
opts.verify = false;
|
||||
|
@ -9426,7 +9425,6 @@ console_cmd__fed__sync(opt &out, const string_view &line)
|
|||
|
||||
m::vm::opts vmopts;
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
vmopts.prev_check_exists = false;
|
||||
vmopts.head_must_exist = false;
|
||||
vmopts.history = false;
|
||||
|
@ -9520,7 +9518,6 @@ console_cmd__fed__state(opt &out, const string_view &line)
|
|||
|
||||
m::vm::opts vmopts;
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
vmopts.prev_check_exists = false;
|
||||
vmopts.head_must_exist = false;
|
||||
vmopts.verify = false;
|
||||
|
@ -9680,7 +9677,6 @@ console_cmd__fed__backfill(opt &out, const string_view &line)
|
|||
|
||||
m::vm::opts vmopts;
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
vmopts.prev_check_exists = false;
|
||||
vmopts.head_must_exist = false;
|
||||
vmopts.history = false;
|
||||
|
@ -9859,7 +9855,6 @@ console_cmd__fed__event(opt &out, const string_view &line)
|
|||
|
||||
m::vm::opts vmopts;
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
vmopts.prev_check_exists = false;
|
||||
vmopts.head_must_exist = false;
|
||||
vmopts.history = false;
|
||||
|
|
|
@ -158,13 +158,6 @@ check_event(const resource::request &request,
|
|||
"event.type must be m.room.member"
|
||||
};
|
||||
|
||||
if(at<"membership"_>(event) != "invite")
|
||||
throw m::error
|
||||
{
|
||||
http::NOT_MODIFIED, "M_INVALID_MEMBERSHIP",
|
||||
"event.membership must be invite."
|
||||
};
|
||||
|
||||
if(unquote(at<"content"_>(event).at("membership")) != "invite")
|
||||
throw m::error
|
||||
{
|
||||
|
|
|
@ -62,7 +62,6 @@ handle_pdu(client &client,
|
|||
{
|
||||
m::vm::opts vmopts;
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
vmopts.prev_check_exists = false;
|
||||
vmopts.nothrows = -1U;
|
||||
vmopts.infolog_accept = true;
|
||||
|
|
|
@ -95,13 +95,6 @@ put__send_join(client &client,
|
|||
"Event type must be m.room.member"
|
||||
};
|
||||
|
||||
if(json::get<"membership"_>(event) && json::get<"membership"_>(event) != "join")
|
||||
throw m::error
|
||||
{
|
||||
http::NOT_MODIFIED, "M_INVALID_MEMBERSHIP",
|
||||
"Event membership state must be 'join'."
|
||||
};
|
||||
|
||||
if(unquote(json::get<"content"_>(event).get("membership")) != "join")
|
||||
throw m::error
|
||||
{
|
||||
|
@ -118,7 +111,6 @@ put__send_join(client &client,
|
|||
|
||||
m::vm::opts vmopts;
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
m::vm::eval eval
|
||||
{
|
||||
event, vmopts
|
||||
|
|
|
@ -95,13 +95,6 @@ put__send_leave(client &client,
|
|||
"Event type must be m.room.member"
|
||||
};
|
||||
|
||||
if(json::get<"membership"_>(event) && json::get<"membership"_>(event) != "leave")
|
||||
throw m::error
|
||||
{
|
||||
http::NOT_MODIFIED, "M_INVALID_MEMBERSHIP",
|
||||
"Event membership state must be 'leave'."
|
||||
};
|
||||
|
||||
if(unquote(json::get<"content"_>(event).get("membership")) != "leave")
|
||||
throw m::error
|
||||
{
|
||||
|
@ -118,7 +111,6 @@ put__send_leave(client &client,
|
|||
|
||||
m::vm::opts vmopts;
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
m::vm::eval eval
|
||||
{
|
||||
event, vmopts
|
||||
|
|
|
@ -254,7 +254,6 @@ pretty__event(std::ostream &s,
|
|||
"type",
|
||||
"depth",
|
||||
"state_key",
|
||||
"membership",
|
||||
"redacts",
|
||||
};
|
||||
|
||||
|
@ -420,7 +419,6 @@ pretty_oneline__event(std::ostream &s,
|
|||
else
|
||||
s << "*" << " ";
|
||||
|
||||
out("membership", json::get<"membership"_>(event));
|
||||
out("redacts", json::get<"redacts"_>(event));
|
||||
|
||||
const json::object &contents
|
||||
|
|
|
@ -172,7 +172,6 @@ ircd::m::fetch::auth_chain_eval(const m::room::id &room_id,
|
|||
{
|
||||
m::vm::opts opts;
|
||||
opts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
opts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
opts.infolog_accept = true;
|
||||
opts.warnlog |= m::vm::fault::STATE;
|
||||
opts.warnlog &= ~m::vm::fault::EXISTS;
|
||||
|
|
Loading…
Reference in a new issue