mirror of
https://github.com/matrix-construct/construct
synced 2025-01-16 17:46:54 +01:00
ircd:Ⓜ️:room::members: Improve interface; add user::id specific iteration closure.
This commit is contained in:
parent
f9ade26b24
commit
0a1a35fdf4
2 changed files with 83 additions and 36 deletions
|
@ -275,6 +275,9 @@ struct ircd::m::room::state::opts
|
||||||
///
|
///
|
||||||
struct ircd::m::room::members
|
struct ircd::m::room::members
|
||||||
{
|
{
|
||||||
|
using closure = std::function<void (const id::user &)>;
|
||||||
|
using closure_bool = std::function<bool (const id::user &)>;
|
||||||
|
|
||||||
m::room room;
|
m::room room;
|
||||||
|
|
||||||
size_t count() const;
|
size_t count() const;
|
||||||
|
@ -283,8 +286,12 @@ struct ircd::m::room::members
|
||||||
bool test(const string_view &membership, const event::closure_bool &view) const;
|
bool test(const string_view &membership, const event::closure_bool &view) const;
|
||||||
bool test(const event::closure_bool &view) const;
|
bool test(const event::closure_bool &view) const;
|
||||||
|
|
||||||
void for_each(const string_view &membership, const event::closure &view) const;
|
void for_each(const string_view &membership, const event::closure &) const;
|
||||||
void for_each(const event::closure &view) const;
|
bool for_each(const string_view &membership, const closure_bool &) const;
|
||||||
|
void for_each(const string_view &membership, const closure &) const;
|
||||||
|
void for_each(const event::closure &) const;
|
||||||
|
bool for_each(const closure_bool &) const;
|
||||||
|
void for_each(const closure &) const;
|
||||||
|
|
||||||
members(const m::room &room)
|
members(const m::room &room)
|
||||||
:room{room}
|
:room{room}
|
||||||
|
|
108
ircd/m/room.cc
108
ircd/m/room.cc
|
@ -954,56 +954,95 @@ const
|
||||||
//
|
//
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::m::room::members::for_each(const event::closure &view)
|
ircd::m::room::members::for_each(const closure &closure)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
test([&view](const m::event &event)
|
for_each(string_view{}, closure);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::room::members::for_each(const closure_bool &closure)
|
||||||
|
const
|
||||||
{
|
{
|
||||||
view(event);
|
return for_each(string_view{}, closure);
|
||||||
return false;
|
}
|
||||||
});
|
|
||||||
|
void
|
||||||
|
ircd::m::room::members::for_each(const event::closure &closure)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
for_each(string_view{}, closure);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::room::members::test(const event::closure_bool &closure)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
const room::state state{room};
|
||||||
|
return state.test("m.room.member", event::closure_bool{[&closure]
|
||||||
|
(const m::event &event)
|
||||||
|
{
|
||||||
|
return closure(event);
|
||||||
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::m::room::members::for_each(const string_view &membership,
|
ircd::m::room::members::for_each(const string_view &membership,
|
||||||
const event::closure &view)
|
const closure &closure)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
test(membership, [&view](const m::event &event)
|
for_each(membership, closure_bool{[&closure]
|
||||||
|
(const user::id &user_id)
|
||||||
{
|
{
|
||||||
view(event);
|
closure(user_id);
|
||||||
|
return true;
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::room::members::for_each(const string_view &membership,
|
||||||
|
const closure_bool &closure)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return !test(membership, event::closure_bool{[&closure]
|
||||||
|
(const event &event)
|
||||||
|
{
|
||||||
|
const user::id &user_id
|
||||||
|
{
|
||||||
|
at<"state_key"_>(event)
|
||||||
|
};
|
||||||
|
|
||||||
|
return !closure(user_id);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ircd::m::room::members::for_each(const string_view &membership,
|
||||||
|
const event::closure &closure)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
test(membership, [&closure]
|
||||||
|
(const event &event)
|
||||||
|
{
|
||||||
|
closure(event);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
ircd::m::room::members::test(const event::closure_bool &view)
|
|
||||||
const
|
|
||||||
{
|
|
||||||
const room::state state
|
|
||||||
{
|
|
||||||
room
|
|
||||||
};
|
|
||||||
|
|
||||||
return state.test("m.room.member", event::closure_bool{[&view]
|
|
||||||
(const m::event &event)
|
|
||||||
{
|
|
||||||
return view(event);
|
|
||||||
}});
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::m::room::members::test(const string_view &membership,
|
ircd::m::room::members::test(const string_view &membership,
|
||||||
const event::closure_bool &view)
|
const event::closure_bool &closure)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
if(empty(membership))
|
||||||
|
return test(closure);
|
||||||
|
|
||||||
// joined members optimization. Only possible when seeking
|
// joined members optimization. Only possible when seeking
|
||||||
// membership="join" on the present state of the room.
|
// membership="join" on the present state of the room.
|
||||||
if(!room.event_id && membership == "join")
|
if(!room.event_id && membership == "join")
|
||||||
{
|
{
|
||||||
const room::state state{room};
|
|
||||||
const room::origins origins{room};
|
const room::origins origins{room};
|
||||||
return origins._test_([&view, &state]
|
return origins._test_([&closure, this]
|
||||||
(const string_view &key)
|
(const string_view &key)
|
||||||
{
|
{
|
||||||
const string_view &member
|
const string_view &member
|
||||||
|
@ -1012,24 +1051,25 @@ const
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ret{false};
|
bool ret{false};
|
||||||
state.get(std::nothrow, "m.room.member", member, [&view, &ret]
|
room.get(std::nothrow, "m.room.member", member, event::closure{[&closure, &ret]
|
||||||
(const m::event &event)
|
(const event &event)
|
||||||
{
|
{
|
||||||
ret = view(event);
|
ret = closure(event);
|
||||||
});
|
}});
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return test([&membership, &view](const event &event)
|
return test(event::closure_bool{[&membership, &closure]
|
||||||
|
(const event &event)
|
||||||
{
|
{
|
||||||
if(at<"membership"_>(event) == membership)
|
if(at<"membership"_>(event) == membership)
|
||||||
if(view(event))
|
if(closure(event))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
|
Loading…
Add table
Reference in a new issue