mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 23:14:13 +01:00
ircd:Ⓜ️:user: Add a query for user to user visibility.
This commit is contained in:
parent
61e88e75bc
commit
b878f577d5
3 changed files with 57 additions and 0 deletions
|
@ -160,9 +160,13 @@ struct ircd::m::user::mitsein
|
|||
bool for_each(const closure_bool &) const;
|
||||
void for_each(const closure &) const;
|
||||
|
||||
// Counting convenience
|
||||
size_t count(const m::user &, const string_view &membership = {}) const;
|
||||
size_t count(const string_view &membership = {}) const;
|
||||
|
||||
// Existential convenience (does `user` and `other` share any common room).
|
||||
bool has(const m::user &other, const string_view &membership = {}) const;
|
||||
|
||||
mitsein(const m::user &user);
|
||||
};
|
||||
|
||||
|
|
14
ircd/m/m.cc
14
ircd/m/m.cc
|
@ -2711,6 +2711,20 @@ ircd::m::user::mitsein::mitsein(const m::user &user)
|
|||
{
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::user::mitsein::has(const m::user &other,
|
||||
const string_view &membership)
|
||||
const
|
||||
{
|
||||
// Return true if broken out of loop.
|
||||
return !for_each(other, membership, rooms::closure_bool{[]
|
||||
(const m::room &, const string_view &)
|
||||
{
|
||||
// Break out of loop at first shared room
|
||||
return false;
|
||||
}});
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::user::mitsein::count(const string_view &membership)
|
||||
const
|
||||
|
|
|
@ -8312,6 +8312,45 @@ console_cmd__user__events__count(opt &out, const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__user__sees(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"user_id_a", "user_id_b", "membership"
|
||||
}};
|
||||
|
||||
const m::user user_a
|
||||
{
|
||||
m::user(param.at("user_id_a"))
|
||||
};
|
||||
|
||||
const m::user user_b
|
||||
{
|
||||
m::user(param.at("user_id_b"))
|
||||
};
|
||||
|
||||
const string_view membership
|
||||
{
|
||||
param.at("membership", "join"_sv)
|
||||
};
|
||||
|
||||
const m::user::mitsein mitsein
|
||||
{
|
||||
user_a
|
||||
};
|
||||
|
||||
const bool result
|
||||
{
|
||||
mitsein.has(user_b, membership)
|
||||
};
|
||||
|
||||
out << std::boolalpha << result
|
||||
<< std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// users
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue