mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 09:40:12 +01:00
ircd:Ⓜ️:room::auth: Improve interface/linkage for auth_events generation.
This commit is contained in:
parent
eb050591c9
commit
1a1939e2c7
5 changed files with 70 additions and 48 deletions
|
@ -17,13 +17,20 @@ struct ircd::m::room::auth
|
|||
{
|
||||
using closure_bool = std::function<bool (const event::idx &)>;
|
||||
using closure = std::function<void (const event::idx &)>;
|
||||
using types = vector_view<const string_view>;
|
||||
|
||||
static bool for_each(const auth &, const closure_bool &);
|
||||
static void make_refs(const auth &, json::stack::array &, const types &, const m::id::user & = {});
|
||||
|
||||
m::room room;
|
||||
|
||||
static bool for_each(const auth &, const closure_bool &);
|
||||
public:
|
||||
bool for_each(const closure_bool &) const;
|
||||
void for_each(const closure &) const;
|
||||
|
||||
void make_refs(json::stack::array &, const types &, const m::id::user & = {}) const;
|
||||
json::array make_refs(const mutable_buffer &, const types &, const m::id::user & = {}) const;
|
||||
|
||||
auth(const m::room &room)
|
||||
:room{room}
|
||||
{}
|
||||
|
|
|
@ -2114,6 +2114,28 @@ const
|
|||
// room::auth
|
||||
//
|
||||
|
||||
ircd::json::array
|
||||
ircd::m::room::auth::make_refs(const mutable_buffer &buf,
|
||||
const types &types,
|
||||
const m::id::user &user)
|
||||
const
|
||||
{
|
||||
json::stack out{buf};
|
||||
json::stack::array array{out};
|
||||
make_refs(array, types, user);
|
||||
array.~array();
|
||||
return json::array{out.completed()};
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::room::auth::make_refs(json::stack::array &out,
|
||||
const types &types,
|
||||
const m::id::user &user)
|
||||
const
|
||||
{
|
||||
make_refs(*this, out, types, user);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::room::auth::for_each(const closure &c)
|
||||
const
|
||||
|
@ -2134,7 +2156,8 @@ const
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::m::room::auth::for_each(const auth &a, const closure_bool &c)
|
||||
ircd::m::room::auth::for_each(const auth &a,
|
||||
const closure_bool &c)
|
||||
{
|
||||
using prototype = bool (const auth &, const closure_bool &);
|
||||
|
||||
|
@ -2146,6 +2169,22 @@ ircd::m::room::auth::for_each(const auth &a, const closure_bool &c)
|
|||
return call(a, c);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::room::auth::make_refs(const auth &a,
|
||||
json::stack::array &out,
|
||||
const types &t,
|
||||
const m::id::user &u)
|
||||
{
|
||||
using prototype = void (const auth &, json::stack::array &, const types &, const m::id::user &);
|
||||
|
||||
static mods::import<prototype> call
|
||||
{
|
||||
"m_room", "ircd::m::room::auth::make_refs"
|
||||
};
|
||||
|
||||
return call(a, out, t, u);
|
||||
}
|
||||
|
||||
//
|
||||
// room::power
|
||||
//
|
||||
|
|
|
@ -5080,16 +5080,6 @@ console_cmd__stage__make_auth(opt &out, const string_view &line)
|
|||
stage.at(id)
|
||||
};
|
||||
|
||||
using prototype = json::array (const m::room &,
|
||||
const mutable_buffer &,
|
||||
const vector_view<const string_view> &,
|
||||
const string_view &);
|
||||
|
||||
static mods::import<prototype> make_auth__buf
|
||||
{
|
||||
"m_room", "make_auth__buf"
|
||||
};
|
||||
|
||||
static const string_view types_general[]
|
||||
{
|
||||
"m.room.create",
|
||||
|
@ -5127,8 +5117,13 @@ console_cmd__stage__make_auth(opt &out, const string_view &line)
|
|||
at<"room_id"_>(event)
|
||||
};
|
||||
|
||||
const m::room::auth auth
|
||||
{
|
||||
room
|
||||
};
|
||||
|
||||
thread_local char buf[1024];
|
||||
json::get<"auth_events"_>(event) = make_auth__buf(room, buf, types, member);
|
||||
json::get<"auth_events"_>(event) = auth.make_refs(buf, types, member);
|
||||
|
||||
stage.at(id) = json::strung
|
||||
{
|
||||
|
|
|
@ -250,15 +250,16 @@ purge(const m::room &room)
|
|||
return ret;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
make_auth(const m::room &room,
|
||||
json::stack::array &out,
|
||||
const vector_view<const string_view> &types,
|
||||
const string_view &member)
|
||||
void
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::room::auth::make_refs(const auth &auth,
|
||||
json::stack::array &out,
|
||||
const types &types,
|
||||
const user::id &user_id)
|
||||
{
|
||||
const m::room::state state
|
||||
{
|
||||
room
|
||||
auth.room
|
||||
};
|
||||
|
||||
const auto fetch{[&out, &state]
|
||||
|
@ -282,23 +283,8 @@ make_auth(const m::room &room,
|
|||
for(const auto &type : types)
|
||||
fetch(type, "");
|
||||
|
||||
if(member)
|
||||
fetch("m.room.member", member);
|
||||
}
|
||||
|
||||
extern "C" json::array
|
||||
make_auth__buf(const m::room &room,
|
||||
const mutable_buffer &buf,
|
||||
const vector_view<const string_view> &types,
|
||||
const string_view &member)
|
||||
{
|
||||
json::stack ps{buf};
|
||||
{
|
||||
json::stack::array top{ps};
|
||||
make_auth(room, top, types, member);
|
||||
}
|
||||
|
||||
return json::array{ps.completed()};
|
||||
if(user_id)
|
||||
fetch("m.room.member", user_id);
|
||||
}
|
||||
|
||||
extern "C" int64_t
|
||||
|
|
|
@ -212,17 +212,12 @@ ircd::m::vm::eval__commit_room(eval &eval,
|
|||
}
|
||||
};
|
||||
|
||||
using auth_prototype = json::array (const m::room &,
|
||||
const mutable_buffer &,
|
||||
const vector_view<const string_view> &,
|
||||
const string_view &);
|
||||
|
||||
static mods::import<auth_prototype> make_auth__buf
|
||||
const m::room::auth auth
|
||||
{
|
||||
"m_room", "make_auth__buf"
|
||||
room
|
||||
};
|
||||
|
||||
char ae_buf[512];
|
||||
char ae_buf[1024];
|
||||
json::array auth_events;
|
||||
if(depth != -1 && opts.add_auth_events)
|
||||
{
|
||||
|
@ -233,14 +228,14 @@ ircd::m::vm::eval__commit_room(eval &eval,
|
|||
"m.room.power_levels",
|
||||
};
|
||||
|
||||
const auto member
|
||||
const m::user::id &member
|
||||
{
|
||||
event.at("type") != "m.room.member"?
|
||||
string_view{event.at("sender")}:
|
||||
string_view{}
|
||||
m::user::id{event.at("sender")}:
|
||||
m::user::id{}
|
||||
};
|
||||
|
||||
auth_events = make_auth__buf(room, ae_buf, types, member);
|
||||
auth_events = auth.make_refs(ae_buf, types, member);
|
||||
}
|
||||
|
||||
const json::iov::add auth_events_
|
||||
|
|
Loading…
Add table
Reference in a new issue