mirror of
https://github.com/matrix-construct/construct
synced 2024-06-07 04:28:59 +02:00
ircd:Ⓜ️:room::power: Simplify iteration interface.
This commit is contained in:
parent
a6cf4c3c91
commit
0b41a1e78d
|
@ -42,8 +42,7 @@
|
|||
///
|
||||
struct ircd::m::room::power
|
||||
{
|
||||
using closure = std::function<void (const string_view &, const int64_t &)>;
|
||||
using closure_bool = std::function<bool (const string_view &, const int64_t &)>;
|
||||
using closure = std::function<bool (const string_view &, const int64_t &)>;
|
||||
|
||||
static const int64_t default_creator_level;
|
||||
static const int64_t default_power_level;
|
||||
|
@ -59,12 +58,10 @@ struct ircd::m::room::power
|
|||
|
||||
public:
|
||||
// Iterate a collection usually either "events" or "users" as per spec.
|
||||
bool for_each(const string_view &prop, const closure_bool &) const;
|
||||
void for_each(const string_view &prop, const closure &) const;
|
||||
bool for_each(const string_view &prop, const closure &) const;
|
||||
|
||||
// Iterates all of the integer levels, excludes the collections.
|
||||
bool for_each(const closure_bool &) const;
|
||||
void for_each(const closure &) const;
|
||||
bool for_each(const closure &) const;
|
||||
|
||||
bool has_level(const string_view &prop) const;
|
||||
bool has_collection(const string_view &prop) const;
|
||||
|
|
|
@ -352,7 +352,7 @@ try
|
|||
room::power::default_power_level
|
||||
};
|
||||
|
||||
power.for_each("notifications", room::power::closure_bool{[&required_level, &key]
|
||||
power.for_each("notifications", [&required_level, &key]
|
||||
(const auto &name, const auto &level)
|
||||
{
|
||||
if(name == key)
|
||||
|
@ -361,7 +361,7 @@ try
|
|||
return false;
|
||||
}
|
||||
else return true;
|
||||
}});
|
||||
});
|
||||
|
||||
const bool ret
|
||||
{
|
||||
|
|
|
@ -393,6 +393,7 @@ const
|
|||
(const string_view &, const int64_t &)
|
||||
{
|
||||
++ret;
|
||||
return true;
|
||||
});
|
||||
|
||||
return ret;
|
||||
|
@ -422,6 +423,7 @@ const
|
|||
(const string_view &, const int64_t &)
|
||||
{
|
||||
++ret;
|
||||
return true;
|
||||
});
|
||||
|
||||
return ret;
|
||||
|
@ -515,36 +517,16 @@ const
|
|||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::room::power::for_each(const closure &closure)
|
||||
const
|
||||
{
|
||||
for_each(string_view{}, closure);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::room::power::for_each(const closure_bool &closure)
|
||||
ircd::m::room::power::for_each(const closure &closure)
|
||||
const
|
||||
{
|
||||
return for_each(string_view{}, closure);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::room::power::for_each(const string_view &prop,
|
||||
const closure &closure)
|
||||
const
|
||||
{
|
||||
for_each(prop, closure_bool{[&closure]
|
||||
(const string_view &key, const int64_t &level)
|
||||
{
|
||||
closure(key, level);
|
||||
return true;
|
||||
}});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::room::power::for_each(const string_view &prop,
|
||||
const closure_bool &closure)
|
||||
const closure &closure)
|
||||
const
|
||||
{
|
||||
bool ret{true};
|
||||
|
|
|
@ -186,8 +186,7 @@ ircd::m::auth_room_power_levels(const m::event &event,
|
|||
};
|
||||
}
|
||||
|
||||
using closure = m::room::power::closure_bool;
|
||||
old_power.for_each("users", closure{[&new_power, ¤t_level]
|
||||
old_power.for_each("users", [&new_power, ¤t_level]
|
||||
(const string_view &user_id, const int64_t &old_level)
|
||||
{
|
||||
if(new_power.has_user(user_id))
|
||||
|
@ -211,9 +210,9 @@ ircd::m::auth_room_power_levels(const m::event &event,
|
|||
};
|
||||
|
||||
return true;
|
||||
}});
|
||||
});
|
||||
|
||||
new_power.for_each("users", closure{[&old_power, ¤t_level]
|
||||
new_power.for_each("users", [&old_power, ¤t_level]
|
||||
(const string_view &user_id, const int64_t &new_level)
|
||||
{
|
||||
if(old_power.has_user(user_id))
|
||||
|
@ -229,9 +228,9 @@ ircd::m::auth_room_power_levels(const m::event &event,
|
|||
};
|
||||
|
||||
return true;
|
||||
}});
|
||||
});
|
||||
|
||||
old_power.for_each("events", closure{[&new_power, ¤t_level]
|
||||
old_power.for_each("events", [&new_power, ¤t_level]
|
||||
(const string_view &type, const int64_t &old_level)
|
||||
{
|
||||
if(new_power.has_event(type))
|
||||
|
@ -255,9 +254,9 @@ ircd::m::auth_room_power_levels(const m::event &event,
|
|||
};
|
||||
|
||||
return true;
|
||||
}});
|
||||
});
|
||||
|
||||
new_power.for_each("events", closure{[&old_power, ¤t_level]
|
||||
new_power.for_each("events", [&old_power, ¤t_level]
|
||||
(const string_view &type, const int64_t &new_level)
|
||||
{
|
||||
if(old_power.has_event(type))
|
||||
|
@ -273,10 +272,10 @@ ircd::m::auth_room_power_levels(const m::event &event,
|
|||
};
|
||||
|
||||
return true;
|
||||
}});
|
||||
});
|
||||
|
||||
// d. For each entry being changed under the users key...
|
||||
old_power.for_each("users", closure{[&event, &new_power, ¤t_level]
|
||||
old_power.for_each("users", [&event, &new_power, ¤t_level]
|
||||
(const string_view &user_id, const int64_t &old_level)
|
||||
{
|
||||
// ...other than the sender's own entry:
|
||||
|
@ -296,7 +295,7 @@ ircd::m::auth_room_power_levels(const m::event &event,
|
|||
};
|
||||
|
||||
return true;
|
||||
}});
|
||||
});
|
||||
|
||||
// e. Otherwise, allow.
|
||||
data.allow = true;
|
||||
|
|
Loading…
Reference in a new issue