mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd:Ⓜ️ Split user's rooms iteration into separate interface.
This commit is contained in:
parent
66e81327d0
commit
55e4a8fcaf
4 changed files with 125 additions and 96 deletions
|
@ -22,8 +22,8 @@ namespace ircd::m::rooms
|
|||
void for_each(const room::closure &);
|
||||
|
||||
// All rooms for a user (alias to interface in user::)
|
||||
void for_each(const user &, const string_view &membership, const user::member_closure_bool &);
|
||||
void for_each(const user &, const string_view &membership, const user::member_closure &);
|
||||
void for_each(const user &, const user::member_closure_bool &);
|
||||
void for_each(const user &, const user::member_closure &);
|
||||
void for_each(const user &, const string_view &membership, const user::rooms::closure_bool &);
|
||||
void for_each(const user &, const string_view &membership, const user::rooms::closure &);
|
||||
void for_each(const user &, const user::rooms::closure_bool &);
|
||||
void for_each(const user &, const user::rooms::closure &);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace ircd::m
|
|||
struct ircd::m::user
|
||||
{
|
||||
struct room;
|
||||
struct rooms;
|
||||
using id = m::id::user;
|
||||
using closure = std::function<void (const user &)>;
|
||||
using closure_bool = std::function<bool (const user &)>;
|
||||
|
@ -55,13 +56,6 @@ 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();
|
||||
|
@ -86,6 +80,26 @@ struct ircd::m::user::room
|
|||
room &operator=(const room &) = delete;
|
||||
};
|
||||
|
||||
/// Interface to the rooms for a user.
|
||||
struct ircd::m::user::rooms
|
||||
{
|
||||
using closure = std::function<void (const m::room &, const string_view &)>;
|
||||
using closure_bool = std::function<bool (const m::room &, const string_view &)>;
|
||||
|
||||
m::user::room user_room;
|
||||
|
||||
public:
|
||||
// All rooms with specific membership
|
||||
void for_each(const string_view &membership, const closure_bool &) const;
|
||||
void for_each(const string_view &membership, const closure &) const;
|
||||
|
||||
// All rooms with any membership
|
||||
void for_each(const closure_bool &) const;
|
||||
void for_each(const closure &) const;
|
||||
|
||||
rooms(const m::user &user);
|
||||
};
|
||||
|
||||
inline ircd::m::user::operator
|
||||
const ircd::m::user::id &()
|
||||
const
|
||||
|
|
177
ircd/m/m.cc
177
ircd/m/m.cc
|
@ -902,32 +902,36 @@ ircd::m::node::room::room(const m::node &node)
|
|||
|
||||
void
|
||||
ircd::m::rooms::for_each(const user &user,
|
||||
const user::member_closure &closure)
|
||||
const user::rooms::closure &closure)
|
||||
{
|
||||
user.for_each(closure);
|
||||
const m::user::rooms rooms{user};
|
||||
rooms.for_each(closure);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::rooms::for_each(const user &user,
|
||||
const user::member_closure_bool &closure)
|
||||
const user::rooms::closure_bool &closure)
|
||||
{
|
||||
user.for_each(closure);
|
||||
const m::user::rooms rooms{user};
|
||||
rooms.for_each(closure);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::rooms::for_each(const user &user,
|
||||
const string_view &membership,
|
||||
const user::member_closure &closure)
|
||||
const user::rooms::closure &closure)
|
||||
{
|
||||
user.for_each(membership, closure);
|
||||
const m::user::rooms rooms{user};
|
||||
rooms.for_each(membership, closure);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::rooms::for_each(const user &user,
|
||||
const string_view &membership,
|
||||
const user::member_closure_bool &closure)
|
||||
const user::rooms::closure_bool &closure)
|
||||
{
|
||||
user.for_each(membership, closure);
|
||||
const m::user::rooms rooms{user};
|
||||
rooms.for_each(membership, closure);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1140,81 +1144,6 @@ 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,
|
||||
|
@ -1386,6 +1315,88 @@ ircd::m::user::room::room(const m::user &user)
|
|||
static_cast<m::room &>(*this) = room_id;
|
||||
}
|
||||
|
||||
//
|
||||
// user::rooms
|
||||
//
|
||||
|
||||
ircd::m::user::rooms::rooms(const m::user &user)
|
||||
:user_room{user}
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::user::rooms::for_each(const closure &closure)
|
||||
const
|
||||
{
|
||||
for_each(closure_bool{[&closure]
|
||||
(const m::room &room, const string_view &membership)
|
||||
{
|
||||
closure(room, membership);
|
||||
return true;
|
||||
}});
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::user::rooms::for_each(const closure_bool &closure)
|
||||
const
|
||||
{
|
||||
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::rooms::for_each(const string_view &membership,
|
||||
const closure &closure)
|
||||
const
|
||||
{
|
||||
for_each(membership, closure_bool{[&closure]
|
||||
(const m::room &room, const string_view &membership)
|
||||
{
|
||||
closure(room, membership);
|
||||
return true;
|
||||
}});
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::user::rooms::for_each(const string_view &membership,
|
||||
const closure_bool &closure)
|
||||
const
|
||||
{
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// m/room.h
|
||||
|
|
|
@ -341,8 +341,12 @@ initialsync_rooms__membership(client &client,
|
|||
const m::user::room &user_room,
|
||||
const string_view &membership)
|
||||
{
|
||||
const m::user &user{user_room.user};
|
||||
user.for_each(membership, [&client, &request, &out, &user_room]
|
||||
const m::user::rooms rooms
|
||||
{
|
||||
user_room.user
|
||||
};
|
||||
|
||||
rooms.for_each(membership, [&client, &request, &out, &user_room]
|
||||
(const m::room &room, const string_view &membership)
|
||||
{
|
||||
const m::room::id &room_id{room.room_id};
|
||||
|
|
Loading…
Reference in a new issue