0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd:Ⓜ️:room::power: Add cheap composer for augmented default power_levels content.

This commit is contained in:
Jason Volk 2019-08-18 06:35:23 -07:00
parent 3418f85a67
commit abca51deea
2 changed files with 30 additions and 8 deletions

View file

@ -77,5 +77,7 @@ struct ircd::m::room::power
power(const m::room &);
power() = default;
using compose_closure = std::function<void (const string_view &, json::stack::object &)>;
static json::object compose_content(const mutable_buffer &out, const compose_closure &);
static json::object default_content(const mutable_buffer &out, const m::id::user &creator);
};

View file

@ -3659,6 +3659,24 @@ ircd::m::room::power::default_user_level
ircd::json::object
ircd::m::room::power::default_content(const mutable_buffer &buf,
const m::user::id &creator)
{
return compose_content(buf, [&creator]
(const string_view &key, json::stack::object &object)
{
if(key != "users")
return;
assert(default_creator_level == 100);
json::stack::member
{
object, creator, json::value(default_creator_level)
};
});
}
ircd::json::object
ircd::m::room::power::compose_content(const mutable_buffer &buf,
const compose_closure &closure)
{
json::stack out{buf};
json::stack::object content{out};
@ -3669,10 +3687,14 @@ ircd::m::room::power::default_content(const mutable_buffer &buf,
content, "ban", json::value(default_power_level)
};
json::stack::object
{
content, "events"
};
json::stack::object events
{
content, "events"
};
closure("events", events);
}
assert(default_event_level == 0);
json::stack::member
@ -3700,6 +3722,8 @@ ircd::m::room::power::default_content(const mutable_buffer &buf,
{
notifications, "room", json::value(default_power_level)
};
closure("notifications", notifications);
}
json::stack::member
@ -3718,11 +3742,7 @@ ircd::m::room::power::default_content(const mutable_buffer &buf,
content, "users"
};
assert(default_creator_level == 100);
json::stack::member
{
users, creator, json::value(default_creator_level)
};
closure("users", users);
}
assert(default_user_level == 0);