0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-24 12:58:21 +02:00

ircd:Ⓜ️:user::pushers: Additional derivative utils for interface.

This commit is contained in:
Jason Volk 2020-10-24 21:24:38 -07:00
parent 7e22894437
commit 3cbf610cd0
2 changed files with 49 additions and 0 deletions

View file

@ -19,7 +19,13 @@ struct ircd::m::user::pushers
m::user user;
public:
bool for_each(const closure_bool &) const;
size_t count(const string_view &kind = {}) const;
bool any(const string_view &kind = {}) const;
bool has(const string_view &key) const;
bool get(std::nothrow_t, const string_view &key, const closure &) const;
void get(const string_view &key, const closure &) const;
bool set(const json::object &value) const;

View file

@ -120,6 +120,49 @@ const
});
}
bool
ircd::m::user::pushers::has(const string_view &key)
const
{
return !for_each([&key] // for_each() returns true if no match
(const event::idx &pusher_idx, const string_view &pushkey, const push::pusher &pusher)
{
return key != pushkey;
});
}
bool
ircd::m::user::pushers::any(const string_view &kind)
const
{
return !for_each([&kind] // for_each() returns true if no match
(const event::idx &pusher_idx, const string_view &pushkey, const push::pusher &pusher)
{
if(!kind)
return false;
if(json::get<"kind"_>(pusher) == kind)
return false;
return true;
});
}
size_t
ircd::m::user::pushers::count(const string_view &kind)
const
{
size_t ret{0};
for_each([&ret, &kind]
(const event::idx &pusher_idx, const string_view &pushkey, const push::pusher &pusher)
{
ret += !kind || json::get<"kind"_>(pusher) == kind;
return true;
});
return ret;
}
bool
ircd::m::user::pushers::for_each(const closure_bool &closure)
const