0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd:Ⓜ️:rooms: Add central linkage to send a summary to !public.

This commit is contained in:
Jason Volk 2018-10-24 17:51:33 -07:00
parent 6c0a8b2c34
commit 133cb4825c
3 changed files with 57 additions and 10 deletions

View file

@ -41,4 +41,6 @@ namespace ircd::m::rooms
// 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);
event::id::buf summary_set(const m::room::id &, const json::object &summary);
event::id::buf summary_set(const m::room &);
} }

View file

@ -1468,6 +1468,43 @@ ircd::m::event_filter::event_filter(const mutable_buffer &buf,
// m/rooms.h // m/rooms.h
// //
ircd::m::event::id::buf
ircd::m::rooms::summary_set(const m::room &room)
{
if(!exists(room))
throw m::NOT_FOUND
{
"Cannot set a summary for room '%s' which I have no state for",
string_view{room.room_id}
};
const unique_buffer<mutable_buffer> buf
{
48_KiB
};
const json::object summary
{
summary_chunk(room, buf)
};
return summary_set(room.room_id, summary);
}
ircd::m::event::id::buf
ircd::m::rooms::summary_set(const m::room::id &room_id,
const json::object &summary)
{
using prototype = event::id::buf (const m::room::id &, const json::object &);
static mods::import<prototype> function
{
"m_rooms", "_summary_set"
};
return function(room_id, summary);
}
ircd::json::object ircd::json::object
ircd::m::rooms::summary_chunk(const m::room &room, ircd::m::rooms::summary_chunk(const m::room &room,
const mutable_buffer &buf) const mutable_buffer &buf)

View file

@ -12,11 +12,12 @@ namespace ircd::m::rooms
{ {
static string_view make_state_key(const mutable_buffer &out, const m::room::id &); static string_view make_state_key(const mutable_buffer &out, const m::room::id &);
static m::room::id::buf unmake_state_key(const string_view &); static m::room::id::buf unmake_state_key(const string_view &);
extern "C" event::id::buf _summary_set(const m::room::id &, const json::object &);
extern conf::item<size_t> fetch_limit;
extern conf::item<seconds> fetch_timeout;
extern "C" std::pair<size_t, std::string> _fetch_update_(const net::hostport &, const string_view &since, const size_t &limit, const seconds &timeout); extern "C" std::pair<size_t, std::string> _fetch_update_(const net::hostport &, const string_view &since, const size_t &limit, const seconds &timeout);
extern "C" std::pair<size_t, std::string> _fetch_update(const net::hostport &, const string_view &since = {}); extern "C" std::pair<size_t, std::string> _fetch_update(const net::hostport &, const string_view &since = {});
extern conf::item<size_t> fetch_limit;
extern conf::item<seconds> fetch_timeout;
static void remote_summary_chunk(const m::room &room, json::stack::object &obj); static void remote_summary_chunk(const m::room &room, json::stack::object &obj);
static void local_summary_chunk(const m::room &room, json::stack::object &obj); static void local_summary_chunk(const m::room &room, json::stack::object &obj);
@ -26,8 +27,8 @@ namespace ircd::m::rooms
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 room::id::buf public_room_id;
extern m::hookfn<vm::eval &> create_public_room_hook; extern m::hookfn<vm::eval &> create_public_room_hook;
extern const room::id::buf public_room_id;
} }
ircd::mapi::header ircd::mapi::header
@ -381,13 +382,7 @@ ircd::m::rooms::_fetch_update_(const net::hostport &hp,
unquote(summary.at("room_id")) unquote(summary.at("room_id"))
}; };
char state_key_buf[256]; _summary_set(room_id, summary);
const auto state_key
{
make_state_key(state_key_buf, room_id)
};
send(public_room_id, m::me, "ircd.rooms", state_key, summary);
} }
return return
@ -397,6 +392,19 @@ ircd::m::rooms::_fetch_update_(const net::hostport &hp,
}; };
} }
ircd::m::event::id::buf
ircd::m::rooms::_summary_set(const m::room::id &room_id,
const json::object &summary)
{
char state_key_buf[256];
const auto state_key
{
make_state_key(state_key_buf, room_id)
};
return send(public_room_id, m::me, "ircd.rooms", state_key, summary);
}
ircd::m::room::id::buf ircd::m::room::id::buf
ircd::m::rooms::unmake_state_key(const string_view &key) ircd::m::rooms::unmake_state_key(const string_view &key)
{ {