diff --git a/include/ircd/m/rooms.h b/include/ircd/m/rooms.h index 0ebc89baf..10dfa57c2 100644 --- a/include/ircd/m/rooms.h +++ b/include/ircd/m/rooms.h @@ -41,4 +41,6 @@ namespace ircd::m::rooms // Linkage to utils that build a publicrooms summary from room state. void summary_chunk(const m::room &, json::stack::object &chunk); 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 &); } diff --git a/ircd/m/m.cc b/ircd/m/m.cc index 4ffbdf002..bd5d1748d 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -1468,6 +1468,43 @@ ircd::m::event_filter::event_filter(const mutable_buffer &buf, // 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 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 function + { + "m_rooms", "_summary_set" + }; + + return function(room_id, summary); +} + ircd::json::object ircd::m::rooms::summary_chunk(const m::room &room, const mutable_buffer &buf) diff --git a/modules/m_rooms.cc b/modules/m_rooms.cc index 84981909b..df674da71 100644 --- a/modules/m_rooms.cc +++ b/modules/m_rooms.cc @@ -12,11 +12,12 @@ namespace ircd::m::rooms { 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 &); + extern "C" event::id::buf _summary_set(const m::room::id &, const json::object &); - extern conf::item fetch_limit; - extern conf::item fetch_timeout; extern "C" std::pair _fetch_update_(const net::hostport &, const string_view &since, const size_t &limit, const seconds &timeout); extern "C" std::pair _fetch_update(const net::hostport &, const string_view &since = {}); + extern conf::item fetch_limit; + extern conf::item fetch_timeout; 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); @@ -26,8 +27,8 @@ namespace ircd::m::rooms 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 &); - extern const room::id::buf public_room_id; extern m::hookfn create_public_room_hook; + extern const room::id::buf public_room_id; } ircd::mapi::header @@ -381,13 +382,7 @@ ircd::m::rooms::_fetch_update_(const net::hostport &hp, unquote(summary.at("room_id")) }; - char state_key_buf[256]; - const auto state_key - { - make_state_key(state_key_buf, room_id) - }; - - send(public_room_id, m::me, "ircd.rooms", state_key, summary); + _summary_set(room_id, summary); } 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::rooms::unmake_state_key(const string_view &key) {