0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd:Ⓜ️:event::append: Add properties mask to opts; centralize. (Fixes #119)

This commit is contained in:
Jason Volk 2019-08-05 17:24:33 -07:00
parent 52dbf9f412
commit eddc5b3b55
7 changed files with 70 additions and 117 deletions

View file

@ -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<long>::min()};
bool query_txnid {true};
};

View file

@ -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

View file

@ -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

View file

@ -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))

View file

@ -27,8 +27,6 @@ namespace ircd::m::sync
extern conf::item<bool> crazyload_historical_members;
extern conf::item<int64_t> 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))

View file

@ -28,7 +28,6 @@ namespace ircd::m::sync
extern conf::item<bool> exposure_state;
extern conf::item<size_t> limit_default;
extern conf::item<size_t> 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);

View file

@ -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<bool> 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)
{