0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd:Ⓜ️:rooms: Add public rooms count for total_room_count_estimate; cleanup.

This commit is contained in:
Jason Volk 2018-10-24 14:22:10 -07:00
parent f7c7850465
commit e85917abb1
4 changed files with 32 additions and 20 deletions

View file

@ -33,6 +33,8 @@ namespace ircd::m::rooms
bool for_each_public(const string_view &room_id_lb, const room::id::closure_bool &); bool for_each_public(const string_view &room_id_lb, const room::id::closure_bool &);
bool for_each_public(const room::id::closure_bool &); bool for_each_public(const room::id::closure_bool &);
size_t count_public(const string_view &server = {});
// 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,19 @@ ircd::m::rooms::for_each(const user &user,
return rooms.for_each(membership, closure); return rooms.for_each(membership, closure);
} }
size_t
ircd::m::rooms::count_public(const string_view &server)
{
using prototype = size_t (const string_view &);
static mods::import<prototype> function
{
"m_rooms", "_count_public"
};
return function(server);
}
bool bool
ircd::m::rooms::for_each_public(const room::id::closure_bool &closure) ircd::m::rooms::for_each_public(const room::id::closure_bool &closure)
{ {

View file

@ -16,17 +16,6 @@ IRCD_MODULE
"Client 7.5 :Public Rooms" "Client 7.5 :Public Rooms"
}; };
const ircd::m::room::id::buf
public_room_id
{
"public", ircd::my_host()
};
m::room public_
{
public_room_id
};
resource resource
publicrooms_resource publicrooms_resource
{ {
@ -105,11 +94,6 @@ post__publicrooms(client &client,
size_t count{0}; size_t count{0};
m::room::id::buf prev_batch_buf; m::room::id::buf prev_batch_buf;
m::room::id::buf next_batch_buf; m::room::id::buf next_batch_buf;
const m::room::state publix
{
public_
};
json::stack::object top{out}; json::stack::object top{out};
{ {
json::stack::member chunk_m{top, "chunk"}; json::stack::member chunk_m{top, "chunk"};
@ -132,7 +116,7 @@ post__publicrooms(client &client,
{ {
top, "total_room_count_estimate", json::value top, "total_room_count_estimate", json::value
{ {
long(publix.count("ircd.room")) ssize_t(m::rooms::count_public())
} }
}; };
@ -148,7 +132,7 @@ post__publicrooms(client &client,
top, "next_batch", next_batch_buf top, "next_batch", next_batch_buf
}; };
return {}; return response;
} }
resource::method resource::method

View file

@ -11,12 +11,13 @@
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" size_t _count_public(const string_view &server);
extern "C" bool _for_each_public(const string_view &room_id_lb, const room::id::closure_bool &); 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 &);
extern const ircd::m::room::id::buf public_room_id; extern const room::id::buf public_room_id;
extern m::hookfn<m::vm::eval &> create_public_room_hook; extern m::hookfn<vm::eval &> create_public_room_hook;
} }
ircd::mapi::header ircd::mapi::header
@ -70,6 +71,18 @@ 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);
} }
size_t
ircd::m::rooms::_count_public(const string_view &server)
{
const room::state state
{
public_room_id
};
//TODO: server
return state.count("ircd.room");
}
bool bool
ircd::m::rooms::_for_each_public(const string_view &room_id_lb, ircd::m::rooms::_for_each_public(const string_view &room_id_lb,
const room::id::closure_bool &closure) const room::id::closure_bool &closure)