0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 22:41:12 +01:00

ircd:Ⓜ️:rooms: Add and use interface for publicrooms iteration.

This commit is contained in:
Jason Volk 2018-10-24 14:15:36 -07:00
parent 0291a0d83e
commit f7c7850465
4 changed files with 45 additions and 7 deletions

View file

@ -29,6 +29,10 @@ namespace ircd::m::rooms
bool for_each(const user &, const user::rooms::closure_bool &); bool for_each(const user &, const user::rooms::closure_bool &);
void for_each(const user &, const user::rooms::closure &); void for_each(const user &, const user::rooms::closure &);
// All public rooms only
bool for_each_public(const string_view &room_id_lb, const room::id::closure_bool &);
bool for_each_public(const room::id::closure_bool &);
// Linkage to utils that build a publicrooms summary from room state. // Linkage to utils that build a publicrooms summary from room state.
void summary_chunk(const m::room &, json::stack::object &chunk); void summary_chunk(const m::room &, json::stack::object &chunk);
json::object summary_chunk(const m::room &, const mutable_buffer &out); json::object summary_chunk(const m::room &, const mutable_buffer &out);

View file

@ -1532,6 +1532,26 @@ ircd::m::rooms::for_each(const user &user,
return rooms.for_each(membership, closure); return rooms.for_each(membership, closure);
} }
bool
ircd::m::rooms::for_each_public(const room::id::closure_bool &closure)
{
return for_each_public(string_view{}, closure);
}
bool
ircd::m::rooms::for_each_public(const string_view &room_id_lb,
const room::id::closure_bool &closure)
{
using prototype = bool (const string_view &, const room::id::closure_bool &);
static mods::import<prototype> function
{
"m_rooms", "_for_each_public"
};
return function(room_id_lb, closure);
}
void void
ircd::m::rooms::for_each(const room::closure &closure) ircd::m::rooms::for_each(const room::closure &closure)
{ {

View file

@ -114,14 +114,9 @@ post__publicrooms(client &client,
{ {
json::stack::member chunk_m{top, "chunk"}; json::stack::member chunk_m{top, "chunk"};
json::stack::array chunk{chunk_m}; json::stack::array chunk{chunk_m};
publix.for_each("ircd.room", since, [&] m::rooms::for_each_public(since, [&]
(const m::event &event) (const m::room::id &room_id)
{ {
const m::room::id &room_id
{
at<"state_key"_>(event)
};
json::stack::object obj{chunk}; json::stack::object obj{chunk};
m::rooms::summary_chunk(room_id, obj); m::rooms::summary_chunk(room_id, obj);

View file

@ -11,6 +11,7 @@
namespace ircd::m::rooms namespace ircd::m::rooms
{ {
extern "C" void _summary_chunk(const m::room &room, json::stack::object &obj); extern "C" void _summary_chunk(const m::room &room, json::stack::object &obj);
extern "C" bool _for_each_public(const string_view &room_id_lb, const room::id::closure_bool &);
extern "C" bool _for_each(const string_view &room_id_lb, const room::id::closure_bool &); extern "C" bool _for_each(const string_view &room_id_lb, const room::id::closure_bool &);
static void create_public_room(const m::event &, m::vm::eval &); static void create_public_room(const m::event &, m::vm::eval &);
@ -69,6 +70,24 @@ ircd::m::rooms::_for_each(const string_view &room_id_lb,
return state.for_each("ircd.room", room_id_lb, keys); return state.for_each("ircd.room", room_id_lb, keys);
} }
bool
ircd::m::rooms::_for_each_public(const string_view &room_id_lb,
const room::id::closure_bool &closure)
{
const room::state state
{
public_room_id
};
const room::state::keys_bool keys{[&closure]
(const string_view &room_id) -> bool
{
return closure(room_id);
}};
return state.for_each("ircd.room", room_id_lb, keys);
}
void void
ircd::m::rooms::_summary_chunk(const m::room &room, ircd::m::rooms::_summary_chunk(const m::room &room,
json::stack::object &obj) json::stack::object &obj)