mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 00:32:35 +01:00
ircd:Ⓜ️ Add user room membership convenience interface; apply.
This commit is contained in:
parent
777525f85a
commit
e9df8b699c
3 changed files with 87 additions and 17 deletions
|
@ -53,6 +53,13 @@ struct ircd::m::user
|
|||
json::object account_data(const mutable_buffer &out, const string_view &type) const; //nothrow
|
||||
event::id::buf account_data(const m::user &sender, const string_view &type, const json::object &value);
|
||||
|
||||
using member_closure = std::function<void (const m::room &, const string_view &)>;
|
||||
using member_closure_bool = std::function<bool (const m::room &, const string_view &)>;
|
||||
void for_each(const string_view &membership, const member_closure_bool &) const;
|
||||
void for_each(const string_view &membership, const member_closure &) const;
|
||||
void for_each(const member_closure_bool &) const;
|
||||
void for_each(const member_closure &) const;
|
||||
|
||||
bool is_active() const;
|
||||
event::id::buf deactivate();
|
||||
event::id::buf activate();
|
||||
|
|
75
ircd/m/m.cc
75
ircd/m/m.cc
|
@ -1058,6 +1058,81 @@ const
|
|||
return function(*this);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::user::for_each(const member_closure &closure)
|
||||
const
|
||||
{
|
||||
for_each(member_closure_bool{[&closure]
|
||||
(const m::room &room, const string_view &membership)
|
||||
{
|
||||
closure(room, membership);
|
||||
return true;
|
||||
}});
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::user::for_each(const member_closure_bool &closure)
|
||||
const
|
||||
{
|
||||
const m::user::room user_room{*this};
|
||||
const m::room::state state{user_room};
|
||||
state.test("ircd.member", [&closure]
|
||||
(const m::event &event)
|
||||
{
|
||||
const m::room::id &room_id
|
||||
{
|
||||
at<"state_key"_>(event)
|
||||
};
|
||||
|
||||
const string_view &membership
|
||||
{
|
||||
unquote(at<"content"_>(event).at("membership"))
|
||||
};
|
||||
|
||||
return !closure(room_id, membership);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::user::for_each(const string_view &membership,
|
||||
const member_closure &closure)
|
||||
const
|
||||
{
|
||||
for_each(membership, member_closure_bool{[&closure]
|
||||
(const m::room &room, const string_view &membership)
|
||||
{
|
||||
closure(room, membership);
|
||||
return true;
|
||||
}});
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::user::for_each(const string_view &membership,
|
||||
const member_closure_bool &closure)
|
||||
const
|
||||
{
|
||||
const m::user::room user_room{*this};
|
||||
const m::room::state state{user_room};
|
||||
state.test("ircd.member", [&membership, &closure]
|
||||
(const m::event &event)
|
||||
{
|
||||
const string_view &membership_
|
||||
{
|
||||
unquote(at<"content"_>(event).at("membership"))
|
||||
};
|
||||
|
||||
if(membership_ != membership)
|
||||
return false;
|
||||
|
||||
const m::room::id &room_id
|
||||
{
|
||||
at<"state_key"_>(event)
|
||||
};
|
||||
|
||||
return !closure(room_id, membership);
|
||||
});
|
||||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::user::account_data(const m::user &sender,
|
||||
const string_view &type,
|
||||
|
|
|
@ -341,24 +341,12 @@ initialsync_rooms__membership(client &client,
|
|||
const m::user::room &user_room,
|
||||
const string_view &membership)
|
||||
{
|
||||
const m::room::state user_state{user_room};
|
||||
user_state.for_each("ircd.member", [&]
|
||||
(const m::event &event)
|
||||
const m::user &user{user_room.user};
|
||||
user.for_each(membership, [&client, &request, &out, &user_room]
|
||||
(const m::room &room, const string_view &membership)
|
||||
{
|
||||
const auto &membership_
|
||||
{
|
||||
unquote(at<"content"_>(event).at("membership"))
|
||||
};
|
||||
|
||||
if(membership_ != membership)
|
||||
return;
|
||||
|
||||
const m::room::id &room_id
|
||||
{
|
||||
unquote(at<"state_key"_>(event))
|
||||
};
|
||||
|
||||
json::stack::member member{out, string_view{room_id}};
|
||||
const m::room::id &room_id{room.room_id};
|
||||
json::stack::member member{out, room_id};
|
||||
json::stack::object object{member};
|
||||
initialsync_room(client, request, object, user_room, room_id);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue