diff --git a/include/ircd/m/event/append.h b/include/ircd/m/event/append.h index 9077744a9..e1d35221c 100644 --- a/include/ircd/m/event/append.h +++ b/include/ircd/m/event/append.h @@ -29,6 +29,7 @@ struct ircd::m::event::append::opts const id::user *user_id {nullptr}; const room *user_room {nullptr}; const int64_t *room_depth {nullptr}; + const event::keys *keys {nullptr}; long age {std::numeric_limits::min()}; bool query_txnid {true}; }; diff --git a/modules/client/rooms/context.cc b/modules/client/rooms/context.cc index c3ad7dfeb..301d2e28a 100644 --- a/modules/client/rooms/context.cc +++ b/modules/client/rooms/context.cc @@ -33,23 +33,6 @@ flush_hiwat { "default", 16384L }, }; -const m::event::fetch::opts -default_fetch_opts -{ - m::event::keys::include - { - "content", - "depth", - "event_id", - "origin_server_ts", - "redacts", - "room_id", - "sender", - "state_key", - "type", - }, -}; - log::log context_log { @@ -118,7 +101,7 @@ get__context(client &client, const m::event::fetch event { - event_id, default_fetch_opts + event_id }; const m::user::room &user_room @@ -180,7 +163,7 @@ get__context(client &client, m::room::messages before { - room, event_id, &default_fetch_opts + room, event_id }; if(before) @@ -220,7 +203,7 @@ get__context(client &client, m::room::messages after { - room, event_id, &default_fetch_opts + room, event_id }; if(after) @@ -260,7 +243,7 @@ get__context(client &client, const m::room::state state { - room, &default_fetch_opts + room }; // Setup the event::fetch instance outside of the closure to avoid diff --git a/modules/client/rooms/messages.cc b/modules/client/rooms/messages.cc index 4a2fa5a96..d5e97d72f 100644 --- a/modules/client/rooms/messages.cc +++ b/modules/client/rooms/messages.cc @@ -42,24 +42,6 @@ messages_log "m.messages" }; -static const m::event::fetch::opts -default_fetch_opts -{ - m::event::keys::include - { - "content", - "depth", - "event_id", - "origin_server_ts", - "prev_events", - "redacts", - "room_id", - "sender", - "state_key", - "type", - }, -}; - resource::response get__messages(client &client, const resource::request &request, @@ -110,7 +92,7 @@ get__messages(client &client, m::room::messages it { - room, page.from, &default_fetch_opts + room, page.from }; const auto room_depth diff --git a/modules/client/rooms/state.cc b/modules/client/rooms/state.cc index 889ddc926..597549339 100644 --- a/modules/client/rooms/state.cc +++ b/modules/client/rooms/state.cc @@ -13,27 +13,6 @@ using namespace ircd::m; using namespace ircd; -const event::keys::include -default_keys -{ - "content", - "depth", - "event_id", - "origin_server_ts", - "prev_events", - "redacts", - "room_id", - "sender", - "state_key", - "type", -}; - -const event::fetch::opts -default_fopts -{ - default_keys -}; - static resource::response get__state(client &client, const resource::request &request, @@ -131,7 +110,7 @@ get__state(client &client, const m::room::state state { - room, &default_fopts + room }; if(!type) @@ -139,7 +118,7 @@ get__state(client &client, const m::event::fetch event { - state.get(type, state_key), default_fopts + state.get(type, state_key) }; if(!visible(event, request.user_id)) diff --git a/modules/client/sync/rooms/state.cc b/modules/client/sync/rooms/state.cc index 0d283fab2..f51721457 100644 --- a/modules/client/sync/rooms/state.cc +++ b/modules/client/sync/rooms/state.cc @@ -27,8 +27,6 @@ namespace ircd::m::sync extern conf::item crazyload_historical_members; extern conf::item state_exposure_depth; //TODO: XXX - extern const event::keys::include _default_keys; - extern event::fetch::opts _default_fopts; extern item room_invite_state; extern item room_state; @@ -37,10 +35,7 @@ namespace ircd::m::sync ircd::mapi::header IRCD_MODULE { - "Client Sync :Room State", [] - { - ircd::m::sync::_default_fopts.query_json_force = true; - } + "Client Sync :Room State" }; decltype(ircd::m::sync::room_state) @@ -65,26 +60,6 @@ ircd::m::sync::room_invite_state } }; -decltype(ircd::m::sync::_default_keys) -ircd::m::sync::_default_keys -{ - "content", - "depth", - "event_id", - "origin_server_ts", - "redacts", - "room_id", - "sender", - "state_key", - "type", -}; - -decltype(ircd::m::sync::_default_fopts) -ircd::m::sync::_default_fopts -{ - _default_keys -}; - bool ircd::m::sync::room_state_linear(data &data) { @@ -286,7 +261,7 @@ ircd::m::sync::room_state_polylog_events(data &data) { const m::event::fetch event { - event_idx, std::nothrow, _default_fopts + event_idx, std::nothrow }; if(unlikely(!event.valid)) diff --git a/modules/client/sync/rooms/timeline.cc b/modules/client/sync/rooms/timeline.cc index 7a2bc6665..b9f45a906 100644 --- a/modules/client/sync/rooms/timeline.cc +++ b/modules/client/sync/rooms/timeline.cc @@ -28,7 +28,6 @@ namespace ircd::m::sync extern conf::item exposure_state; extern conf::item limit_default; extern conf::item limit_initial_default; - extern const event::keys::include default_keys; extern item room_timeline; } @@ -43,21 +42,6 @@ ircd::m::sync::room_timeline } }; -decltype(ircd::m::sync::default_keys) -ircd::m::sync::default_keys -{ - "content", - "depth", - "event_id", - "origin_server_ts", - "prev_events", - "redacts", - "room_id", - "sender", - "state_key", - "type", -}; - decltype(ircd::m::sync::limit_default) ircd::m::sync::limit_default { @@ -242,11 +226,6 @@ ircd::m::sync::_room_timeline_polylog_events(data &data, bool &limited, bool &ret) { - static const event::fetch::opts fopts - { - default_keys - }; - json::stack::array array { *data.out, "events" @@ -261,7 +240,7 @@ ircd::m::sync::_room_timeline_polylog_events(data &data, m::event::id::buf event_id; m::room::messages it { - room, &fopts + room }; ssize_t i(0); diff --git a/modules/m_event_append.cc b/modules/m_event_append.cc index 4730e002d..18aaf5f4f 100644 --- a/modules/m_event_append.cc +++ b/modules/m_event_append.cc @@ -16,6 +16,8 @@ IRCD_MODULE namespace ircd::m { + extern const event::keys::exclude event_append_exclude_keys; + extern const event::keys event_append_default_keys; extern conf::item event_append_info; extern log::log event_append_log; } @@ -34,6 +36,27 @@ ircd::m::event_append_info { "persist", false }, }; +/// Default event property mask of keys which we strip from the event sent +/// to the client. This mask is applied only if the caller of event::append{} +/// did not supply their mask to apply. It is also inferior to the user's +/// filter if supplied. +decltype(ircd::m::event_append_exclude_keys) +ircd::m::event_append_exclude_keys +{ + "auth_events", + "hashes", + "membership", + "origin", + "prev_state", + "signatures", +}; + +decltype(ircd::m::event_append_default_keys) +ircd::m::event_append_default_keys +{ + event_append_exclude_keys +}; + IRCD_MODULE_EXPORT ircd::m::event::append::append(json::stack::array &array, const event &event_, @@ -131,12 +154,43 @@ ircd::m::event::append::append(json::stack::object &object, } if(!json::get<"event_id"_>(event)) + json::stack::member + { + object, "event_id", event.event_id + }; + + // Get the list of properties to send to the client so we can strip + // the remaining and save b/w + // TODO: m::filter + const event::keys &keys { - auto _event(event); - json::get<"event_id"_>(_event) = event.event_id; - object.append(_event); - } - else object.append(event); + opts.keys? + *opts.keys: + event_append_default_keys + }; + + // Append the event members + for_each(event, [&keys, &object] + (const auto &key, const auto &val_) + { + if(!keys.has(key)) + return true; + + const json::value val + { + val_ + }; + + if(!defined(val)) + return true; + + json::stack::member + { + object, key, val + }; + + return true; + }); if(json::get<"state_key"_>(event) && has_event_idx) {