ircd:Ⓜ️:event::append: Optimize opts, eliminate double-indirection; various reorg.
This commit is contained in:
parent
cd2b92b8fe
commit
741304271e
|
@ -36,6 +36,19 @@ struct ircd::m::event::append
|
||||||
static conf::item<bool> info;
|
static conf::item<bool> info;
|
||||||
static log::log log;
|
static log::log log;
|
||||||
|
|
||||||
|
bool is_ignored(const event &, const opts &) const;
|
||||||
|
bool is_redacted(const event &, const opts &) const;
|
||||||
|
bool is_invisible(const event &, const opts &) const;
|
||||||
|
bool is_excluded(const event &, const opts &) const;
|
||||||
|
|
||||||
|
void _age(json::stack::object &, const event &, const opts &);
|
||||||
|
void _txnid(json::stack::object &, const event &, const opts &);
|
||||||
|
void _prev_state(json::stack::object &, const event &, const opts &);
|
||||||
|
void _unsigned(json::stack::object &, const event &, const opts &);
|
||||||
|
|
||||||
|
bool members(json::stack::object &, const event &, const opts &);
|
||||||
|
bool object(json::stack::array &, const event &, const opts &);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
append(json::stack::object &, const event &, const opts &);
|
append(json::stack::object &, const event &, const opts &);
|
||||||
append(json::stack::object &, const event &);
|
append(json::stack::object &, const event &);
|
||||||
|
@ -47,11 +60,11 @@ struct ircd::m::event::append
|
||||||
/// can provide the best result.
|
/// can provide the best result.
|
||||||
struct ircd::m::event::append::opts
|
struct ircd::m::event::append::opts
|
||||||
{
|
{
|
||||||
const event::idx *event_idx {nullptr};
|
event::idx event_idx {0};
|
||||||
const string_view *client_txnid {nullptr};
|
string_view client_txnid;
|
||||||
const id::user *user_id {nullptr};
|
id::user user_id;
|
||||||
const room *user_room {nullptr};
|
id::room user_room_id;
|
||||||
const int64_t *room_depth {nullptr};
|
int64_t room_depth {-1L};
|
||||||
const event::keys *keys {nullptr};
|
const event::keys *keys {nullptr};
|
||||||
const m::event_filter *event_filter {nullptr};
|
const m::event_filter *event_filter {nullptr};
|
||||||
long age {std::numeric_limits<long>::min()};
|
long age {std::numeric_limits<long>::min()};
|
||||||
|
@ -72,3 +85,23 @@ ircd::m::event::append::append(json::stack::object &o,
|
||||||
const event &e)
|
const event &e)
|
||||||
:append{o, e, {}}
|
:append{o, e, {}}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::m::event::append::append(json::stack::array &array,
|
||||||
|
const event &event,
|
||||||
|
const opts &opts)
|
||||||
|
:returns<bool>{[this, &array, &event, &opts]
|
||||||
|
{
|
||||||
|
return object(array, event, opts);
|
||||||
|
}}
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline
|
||||||
|
ircd::m::event::append::append(json::stack::object &object,
|
||||||
|
const event &event,
|
||||||
|
const opts &opts)
|
||||||
|
:returns<bool>{[this, &object, &event, &opts]
|
||||||
|
{
|
||||||
|
return members(object, event, opts);
|
||||||
|
}}
|
||||||
|
{}
|
||||||
|
|
|
@ -55,10 +55,10 @@ ircd::m::event::append::default_keys
|
||||||
event::append::exclude_keys
|
event::append::exclude_keys
|
||||||
};
|
};
|
||||||
|
|
||||||
ircd::m::event::append::append(json::stack::array &array,
|
bool
|
||||||
const event &event_,
|
ircd::m::event::append::object(json::stack::array &array,
|
||||||
|
const event &event,
|
||||||
const opts &opts)
|
const opts &opts)
|
||||||
:returns<bool>{[&]
|
|
||||||
{
|
{
|
||||||
assert(array.s);
|
assert(array.s);
|
||||||
json::stack::checkpoint cp
|
json::stack::checkpoint cp
|
||||||
|
@ -66,29 +66,24 @@ ircd::m::event::append::append(json::stack::array &array,
|
||||||
*array.s
|
*array.s
|
||||||
};
|
};
|
||||||
|
|
||||||
json::stack::object object
|
json::stack::object _object
|
||||||
{
|
{
|
||||||
array
|
array
|
||||||
};
|
};
|
||||||
|
|
||||||
const bool ret
|
const bool ret
|
||||||
{
|
{
|
||||||
append
|
members(_object, event, opts)
|
||||||
{
|
|
||||||
object, event_, opts
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cp.committing(ret);
|
cp.committing(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}}
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::m::event::append::append(json::stack::object &object,
|
bool
|
||||||
const event &event,
|
ircd::m::event::append::members(json::stack::object &out,
|
||||||
const opts &opts)
|
const event &event,
|
||||||
:returns<bool>{[&]
|
const opts &opts)
|
||||||
{
|
{
|
||||||
// Assertions that the event being appended has some required fields. This
|
// Assertions that the event being appended has some required fields. This
|
||||||
// is a central butt-end test of data coming through the system to here.
|
// is a central butt-end test of data coming through the system to here.
|
||||||
|
@ -97,150 +92,35 @@ ircd::m::event::append::append(json::stack::object &object,
|
||||||
assert(defined(json::get<"sender"_>(event)));
|
assert(defined(json::get<"sender"_>(event)));
|
||||||
//assert(json::get<"origin_server_ts"_>(event));
|
//assert(json::get<"origin_server_ts"_>(event));
|
||||||
//assert(json::get<"origin_server_ts"_>(event) != json::undefined_number);
|
//assert(json::get<"origin_server_ts"_>(event) != json::undefined_number);
|
||||||
#if defined(RB_DEBUG)
|
if constexpr(RB_DEBUG_LEVEL)
|
||||||
if(unlikely(!defined(json::get<"type"_>(event))))
|
{
|
||||||
return false;
|
if(unlikely(!defined(json::get<"type"_>(event))))
|
||||||
|
return false;
|
||||||
|
|
||||||
if(unlikely(!defined(json::get<"sender"_>(event))))
|
if(unlikely(!defined(json::get<"sender"_>(event))))
|
||||||
return false;
|
return false;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
if(opts.event_filter && !m::match(*opts.event_filter, event))
|
if(opts.event_filter && !m::match(*opts.event_filter, event))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const auto ¬_types
|
if(is_excluded(event, opts))
|
||||||
{
|
|
||||||
exclude_types
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!opts.event_filter && token_exists(not_types, ' ', json::get<"type"_>(event)))
|
|
||||||
{
|
|
||||||
log::debug
|
|
||||||
{
|
|
||||||
log, "Not sending event %s because type '%s' excluded by configuration.",
|
|
||||||
string_view{event.event_id},
|
|
||||||
json::get<"type"_>(event),
|
|
||||||
};
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if(opts.query_visible && opts.user_id && !visible(event, *opts.user_id))
|
|
||||||
{
|
|
||||||
log::debug
|
|
||||||
{
|
|
||||||
log, "Not sending event %s because not visible to %s.",
|
|
||||||
string_view{event.event_id},
|
|
||||||
string_view{*opts.user_id},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
if(is_invisible(event, opts))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
const bool has_event_idx
|
|
||||||
{
|
|
||||||
opts.event_idx && *opts.event_idx
|
|
||||||
};
|
|
||||||
|
|
||||||
const bool is_state
|
|
||||||
{
|
|
||||||
defined(json::get<"state_key"_>(event))
|
|
||||||
};
|
|
||||||
|
|
||||||
const bool query_redacted
|
|
||||||
{
|
|
||||||
has_event_idx &&
|
|
||||||
opts.query_redacted &&
|
|
||||||
!is_state &&
|
|
||||||
(!opts.room_depth || *opts.room_depth > json::get<"depth"_>(event))
|
|
||||||
};
|
|
||||||
|
|
||||||
if(query_redacted && m::redacted(*opts.event_idx))
|
|
||||||
{
|
|
||||||
log::debug
|
|
||||||
{
|
|
||||||
log, "Not sending event %s because redacted.",
|
|
||||||
string_view{event.event_id},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
if(is_redacted(event, opts))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
const bool has_user
|
if(is_ignored(event, opts))
|
||||||
{
|
return false;
|
||||||
opts.user_id && opts.user_room
|
|
||||||
};
|
|
||||||
|
|
||||||
const bool check_ignores
|
|
||||||
{
|
|
||||||
has_user && !is_state
|
|
||||||
};
|
|
||||||
|
|
||||||
if(check_ignores && *opts.user_id != json::get<"sender"_>(event))
|
|
||||||
{
|
|
||||||
const m::user::ignores ignores
|
|
||||||
{
|
|
||||||
*opts.user_id
|
|
||||||
};
|
|
||||||
|
|
||||||
if(ignores.enforce("events") && ignores.has(json::get<"sender"_>(event)))
|
|
||||||
{
|
|
||||||
log::debug
|
|
||||||
{
|
|
||||||
log, "Not sending event %s because %s is ignored by %s",
|
|
||||||
string_view{event.event_id},
|
|
||||||
json::get<"sender"_>(event),
|
|
||||||
string_view{*opts.user_id}
|
|
||||||
};
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool sender_is_user
|
|
||||||
{
|
|
||||||
has_user && json::get<"sender"_>(event) == *opts.user_id
|
|
||||||
};
|
|
||||||
|
|
||||||
const bool has_client_txnid
|
|
||||||
{
|
|
||||||
opts.client_txnid && *opts.client_txnid
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto txnid_idx
|
|
||||||
{
|
|
||||||
!has_client_txnid && sender_is_user && opts.query_txnid?
|
|
||||||
opts.user_room->get(std::nothrow, "ircd.client.txnid", event.event_id):
|
|
||||||
0UL
|
|
||||||
};
|
|
||||||
|
|
||||||
const bool query_prev_state
|
|
||||||
{
|
|
||||||
opts.query_prev_state && has_event_idx && is_state
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto prev_state_idx
|
|
||||||
{
|
|
||||||
query_prev_state?
|
|
||||||
room::state::prev(*opts.event_idx):
|
|
||||||
0UL
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(RB_DEBUG) && 0
|
|
||||||
if(!has_client_txnid && !txnid_idx && sender_is_user && opts.query_txnid)
|
|
||||||
log::dwarning
|
|
||||||
{
|
|
||||||
log, "Could not find transaction_id for %s from %s in %s",
|
|
||||||
string_view{event.event_id},
|
|
||||||
json::get<"sender"_>(event),
|
|
||||||
json::get<"room_id"_>(event)
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
// For v3+ events
|
||||||
if(!json::get<"event_id"_>(event))
|
if(!json::get<"event_id"_>(event))
|
||||||
json::stack::member
|
json::stack::member
|
||||||
{
|
{
|
||||||
object, "event_id", event.event_id
|
out, "event_id", event.event_id
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get the list of properties to send to the client so we can strip
|
// Get the list of properties to send to the client so we can strip
|
||||||
|
@ -254,7 +134,7 @@ ircd::m::event::append::append(json::stack::object &object,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Append the event members
|
// Append the event members
|
||||||
for_each(event, [&keys, &object]
|
for_each(event, [&keys, &out]
|
||||||
(const auto &key, const auto &val_)
|
(const auto &key, const auto &val_)
|
||||||
{
|
{
|
||||||
if(!keys.has(key) && key != "redacts"_sv)
|
if(!keys.has(key) && key != "redacts"_sv)
|
||||||
|
@ -270,70 +150,77 @@ ircd::m::event::append::append(json::stack::object &object,
|
||||||
|
|
||||||
json::stack::member
|
json::stack::member
|
||||||
{
|
{
|
||||||
object, key, val
|
out, key, val
|
||||||
};
|
};
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
json::stack::object unsigned_
|
_unsigned(out, event, opts);
|
||||||
{
|
|
||||||
object, "unsigned"
|
|
||||||
};
|
|
||||||
|
|
||||||
const json::value age
|
if(unlikely(info))
|
||||||
{
|
log::info
|
||||||
// When the opts give an explicit age, use it.
|
|
||||||
opts.age != std::numeric_limits<long>::min()?
|
|
||||||
opts.age:
|
|
||||||
|
|
||||||
// If we have depth information, craft a value based on the
|
|
||||||
// distance to the head depth; if this is 0 in riot the event will
|
|
||||||
// "stick" at the bottom of the timeline. This may be advantageous
|
|
||||||
// in the future but for now we make sure the result is non-zero.
|
|
||||||
json::get<"depth"_>(event) >= 0 && opts.room_depth && *opts.room_depth >= 0L?
|
|
||||||
(*opts.room_depth + 1 - json::get<"depth"_>(event)) + 1:
|
|
||||||
|
|
||||||
// We don't have depth information, so we use the origin_server_ts.
|
|
||||||
// It is bad if it conflicts with other appends in the room which
|
|
||||||
// did have depth information.
|
|
||||||
!opts.room_depth && json::get<"origin_server_ts"_>(event)?
|
|
||||||
ircd::time<milliseconds>() - json::get<"origin_server_ts"_>(event):
|
|
||||||
|
|
||||||
// Finally, this special value will eliminate the age altogether
|
|
||||||
// during serialization.
|
|
||||||
json::undefined_number
|
|
||||||
};
|
|
||||||
|
|
||||||
json::stack::member
|
|
||||||
{
|
|
||||||
unsigned_, "age", age
|
|
||||||
};
|
|
||||||
|
|
||||||
if(has_client_txnid)
|
|
||||||
json::stack::member
|
|
||||||
{
|
{
|
||||||
unsigned_, "transaction_id", *opts.client_txnid
|
log, "%s %s idx:%lu in %s depth:%ld txnid:%s %s,%s",
|
||||||
|
string_view{opts.user_id},
|
||||||
|
string_view{event.event_id},
|
||||||
|
opts.event_idx,
|
||||||
|
json::get<"room_id"_>(event),
|
||||||
|
json::get<"depth"_>(event),
|
||||||
|
opts.client_txnid,
|
||||||
|
json::get<"type"_>(event),
|
||||||
|
json::get<"state_key"_>(event),
|
||||||
};
|
};
|
||||||
|
|
||||||
if(txnid_idx)
|
return true;
|
||||||
m::get(std::nothrow, txnid_idx, "content", [&unsigned_]
|
}
|
||||||
(const json::object &content)
|
|
||||||
{
|
void
|
||||||
json::stack::member
|
ircd::m::event::append::_unsigned(json::stack::object &out,
|
||||||
{
|
const event &event,
|
||||||
unsigned_, "transaction_id", unquote(content.get("transaction_id"))
|
const opts &opts)
|
||||||
};
|
{
|
||||||
});
|
json::stack::object object
|
||||||
|
{
|
||||||
|
out, "unsigned"
|
||||||
|
};
|
||||||
|
|
||||||
|
_age(object, event, opts);
|
||||||
|
_txnid(object, event, opts);
|
||||||
|
|
||||||
|
if(defined(json::get<"state_key"_>(event)))
|
||||||
|
_prev_state(object, event, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ircd::m::event::append::_prev_state(json::stack::object &out,
|
||||||
|
const event &event,
|
||||||
|
const opts &opts)
|
||||||
|
{
|
||||||
|
assert(defined(json::get<"state_key"_>(event)))
|
||||||
|
|
||||||
|
const bool query_prev_state
|
||||||
|
{
|
||||||
|
true
|
||||||
|
&& opts.event_idx
|
||||||
|
&& opts.query_prev_state
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto prev_state_idx
|
||||||
|
{
|
||||||
|
query_prev_state?
|
||||||
|
room::state::prev(opts.event_idx):
|
||||||
|
0UL
|
||||||
|
};
|
||||||
|
|
||||||
if(prev_state_idx)
|
if(prev_state_idx)
|
||||||
{
|
{
|
||||||
m::get(std::nothrow, prev_state_idx, "content", [&unsigned_]
|
m::get(std::nothrow, prev_state_idx, "content", [&out]
|
||||||
(const json::object &content)
|
(const json::object &content)
|
||||||
{
|
{
|
||||||
json::stack::member
|
json::stack::member
|
||||||
{
|
{
|
||||||
unsigned_, "prev_content", content
|
out, "prev_content", content
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -344,7 +231,7 @@ ircd::m::event::append::append(json::stack::object &object,
|
||||||
|
|
||||||
json::stack::member
|
json::stack::member
|
||||||
{
|
{
|
||||||
unsigned_, "replaces_state", json::value
|
out, "replaces_state", json::value
|
||||||
{
|
{
|
||||||
replaces_state_id?
|
replaces_state_id?
|
||||||
string_view{replaces_state_id}:
|
string_view{replaces_state_id}:
|
||||||
|
@ -352,24 +239,217 @@ ircd::m::event::append::append(json::stack::object &object,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(unlikely(info))
|
void
|
||||||
log::info
|
ircd::m::event::append::_txnid(json::stack::object &out,
|
||||||
|
const event &event,
|
||||||
|
const opts &opts)
|
||||||
|
{
|
||||||
|
const bool sender_is_user
|
||||||
|
{
|
||||||
|
json::get<"sender"_>(event) == opts.user_id
|
||||||
|
};
|
||||||
|
|
||||||
|
const bool query_txnid
|
||||||
|
{
|
||||||
|
true
|
||||||
|
&& !opts.client_txnid
|
||||||
|
&& opts.query_txnid
|
||||||
|
&& opts.user_room_id
|
||||||
|
&& sender_is_user
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto txnid_idx
|
||||||
|
{
|
||||||
|
query_txnid?
|
||||||
|
m::room(opts.user_room_id).get(std::nothrow, "ircd.client.txnid", event.event_id):
|
||||||
|
0UL
|
||||||
|
};
|
||||||
|
|
||||||
|
if constexpr(RB_DEBUG_LEVEL)
|
||||||
|
{
|
||||||
|
const bool missing_txnid
|
||||||
{
|
{
|
||||||
log, "%s %s idx:%lu in %s depth:%ld txnid:%s idx:%lu age:%ld %s,%s",
|
true
|
||||||
opts.user_id? string_view{*opts.user_id} : string_view{},
|
&& !opts.client_txnid
|
||||||
string_view{event.event_id},
|
&& !txnid_idx
|
||||||
opts.event_idx? *opts.event_idx : 0UL,
|
&& sender_is_user
|
||||||
json::get<"room_id"_>(event),
|
&& opts.query_txnid
|
||||||
json::get<"depth"_>(event),
|
|
||||||
has_client_txnid? *opts.client_txnid : string_view{},
|
|
||||||
txnid_idx,
|
|
||||||
int64_t(age),
|
|
||||||
json::get<"type"_>(event),
|
|
||||||
json::get<"state_key"_>(event),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return true;
|
if(unlikely(missing_txnid))
|
||||||
}}
|
log::dwarning
|
||||||
{
|
{
|
||||||
|
log, "Could not find transaction_id for %s from %s in %s",
|
||||||
|
string_view{event.event_id},
|
||||||
|
json::get<"sender"_>(event),
|
||||||
|
json::get<"room_id"_>(event)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if(opts.client_txnid)
|
||||||
|
json::stack::member
|
||||||
|
{
|
||||||
|
out, "transaction_id", opts.client_txnid
|
||||||
|
};
|
||||||
|
else if(txnid_idx)
|
||||||
|
m::get(std::nothrow, txnid_idx, "content", [&out]
|
||||||
|
(const json::object &content)
|
||||||
|
{
|
||||||
|
json::stack::member
|
||||||
|
{
|
||||||
|
out, "transaction_id", content.get("transaction_id")
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ircd::m::event::append::_age(json::stack::object &out,
|
||||||
|
const event &event,
|
||||||
|
const opts &opts)
|
||||||
|
{
|
||||||
|
const json::value age
|
||||||
|
{
|
||||||
|
// When the opts give an explicit age, use it.
|
||||||
|
opts.age != std::numeric_limits<long>::min()?
|
||||||
|
opts.age:
|
||||||
|
|
||||||
|
// If we have depth information, craft a value based on the
|
||||||
|
// distance to the head depth; if this is 0 in riot the event will
|
||||||
|
// "stick" at the bottom of the timeline. This may be advantageous
|
||||||
|
// in the future but for now we make sure the result is non-zero.
|
||||||
|
json::get<"depth"_>(event) >= 0 && opts.room_depth >= 0L?
|
||||||
|
(opts.room_depth + 1 - json::get<"depth"_>(event)) + 1:
|
||||||
|
|
||||||
|
// We don't have depth information, so we use the origin_server_ts.
|
||||||
|
// It is bad if it conflicts with other appends in the room which
|
||||||
|
// did have depth information.
|
||||||
|
opts.room_depth < 0 && json::get<"origin_server_ts"_>(event)?
|
||||||
|
ircd::time<milliseconds>() - json::get<"origin_server_ts"_>(event):
|
||||||
|
|
||||||
|
// Finally, this special value will eliminate the age altogether
|
||||||
|
// during serialization.
|
||||||
|
json::undefined_number
|
||||||
|
};
|
||||||
|
|
||||||
|
json::stack::member
|
||||||
|
{
|
||||||
|
out, "age", age
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::event::append::is_excluded(const event &event,
|
||||||
|
const opts &opts)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
const auto ¬_types
|
||||||
|
{
|
||||||
|
exclude_types
|
||||||
|
};
|
||||||
|
|
||||||
|
const bool ret
|
||||||
|
{
|
||||||
|
true
|
||||||
|
&& !opts.event_filter
|
||||||
|
&& token_exists(not_types, ' ', json::get<"type"_>(event))
|
||||||
|
};
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
log::debug
|
||||||
|
{
|
||||||
|
log, "Not sending event %s because type '%s' excluded by configuration.",
|
||||||
|
string_view{event.event_id},
|
||||||
|
json::get<"type"_>(event),
|
||||||
|
};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::event::append::is_invisible(const event &event,
|
||||||
|
const opts &opts)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
const bool ret
|
||||||
|
{
|
||||||
|
true
|
||||||
|
&& opts.query_visible
|
||||||
|
&& opts.user_id
|
||||||
|
&& !visible(event, opts.user_id)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
log::debug
|
||||||
|
{
|
||||||
|
log, "Not sending event %s because not visible to %s.",
|
||||||
|
string_view{event.event_id},
|
||||||
|
string_view{opts.user_id},
|
||||||
|
};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::event::append::is_redacted(const event &event,
|
||||||
|
const opts &opts)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
const bool ret
|
||||||
|
{
|
||||||
|
true
|
||||||
|
&& opts.event_idx
|
||||||
|
&& opts.query_redacted
|
||||||
|
&& !defined(json::get<"state_key"_>(event))
|
||||||
|
&& opts.room_depth > json::get<"depth"_>(event)
|
||||||
|
&& m::redacted(opts.event_idx)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
log::debug
|
||||||
|
{
|
||||||
|
log, "Not sending event %s because redacted.",
|
||||||
|
string_view{event.event_id},
|
||||||
|
};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::event::append::is_ignored(const event &event,
|
||||||
|
const opts &opts)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
const bool check_ignores
|
||||||
|
{
|
||||||
|
true
|
||||||
|
&& !defined(json::get<"state_key"_>(event))
|
||||||
|
&& opts.user_id
|
||||||
|
&& opts.user_room_id
|
||||||
|
&& opts.user_id != json::get<"sender"_>(event)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!check_ignores)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const m::user::ignores ignores
|
||||||
|
{
|
||||||
|
opts.user_id
|
||||||
|
};
|
||||||
|
|
||||||
|
if(ignores.enforce("events") && ignores.has(json::get<"sender"_>(event)))
|
||||||
|
{
|
||||||
|
log::debug
|
||||||
|
{
|
||||||
|
log, "Not sending event %s because %s is ignored by %s",
|
||||||
|
string_view{event.event_id},
|
||||||
|
json::get<"sender"_>(event),
|
||||||
|
string_view{opts.user_id}
|
||||||
|
};
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,10 +376,10 @@ append_event(json::stack::array &out,
|
||||||
{
|
{
|
||||||
out, event,
|
out, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &user_room.user.user_id,
|
.user_id = user_room.user.user_id,
|
||||||
.user_room = &user_room,
|
.user_room_id = user_room.room_id,
|
||||||
.room_depth = &room_depth,
|
.room_depth = room_depth,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,7 +206,7 @@ ircd::m::get_notifications(client &client,
|
||||||
{
|
{
|
||||||
event_object, event,
|
event_object, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.keys = ¬ification_event_keys,
|
.keys = ¬ification_event_keys,
|
||||||
//.query_txnid = false,
|
//.query_txnid = false,
|
||||||
//.query_prev_state = false,
|
//.query_prev_state = false,
|
||||||
|
|
|
@ -132,10 +132,10 @@ get__context(client &client,
|
||||||
{
|
{
|
||||||
_event, event,
|
_event, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event.event_idx,
|
.event_idx = event.event_idx,
|
||||||
.user_id = &user_room.user.user_id,
|
.user_id = user_room.user.user_id,
|
||||||
.user_room = &user_room,
|
.user_room_id = user_room.room_id,
|
||||||
.room_depth = &room_depth,
|
.room_depth = room_depth,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -179,10 +179,10 @@ get__context(client &client,
|
||||||
{
|
{
|
||||||
array, event,
|
array, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &user_room.user.user_id,
|
.user_id = user_room.user.user_id,
|
||||||
.user_room = &user_room,
|
.user_room_id = user_room.room_id,
|
||||||
.room_depth = &room_depth,
|
.room_depth = room_depth,
|
||||||
.query_txnid = true,
|
.query_txnid = true,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -233,10 +233,10 @@ get__context(client &client,
|
||||||
{
|
{
|
||||||
array, event,
|
array, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &user_room.user.user_id,
|
.user_id = user_room.user.user_id,
|
||||||
.user_room = &user_room,
|
.user_room_id = user_room.room_id,
|
||||||
.room_depth = &room_depth,
|
.room_depth = room_depth,
|
||||||
.query_txnid = true,
|
.query_txnid = true,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -301,10 +301,10 @@ get__context(client &client,
|
||||||
{
|
{
|
||||||
array, event,
|
array, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &user_room.user.user_id,
|
.user_id = user_room.user.user_id,
|
||||||
.user_room = &user_room,
|
.user_room_id = user_room.room_id,
|
||||||
.room_depth = &room_depth,
|
.room_depth = room_depth,
|
||||||
.query_txnid = false,
|
.query_txnid = false,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -58,8 +58,8 @@ get__event(client &client,
|
||||||
{
|
{
|
||||||
top, event,
|
top, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event.event_idx,
|
.event_idx = event.event_idx,
|
||||||
.user_id = &request.user_id,
|
.user_id = request.user_id,
|
||||||
.query_prev_state = false,
|
.query_prev_state = false,
|
||||||
.query_redacted = false,
|
.query_redacted = false,
|
||||||
.query_visible = false,
|
.query_visible = false,
|
||||||
|
|
|
@ -202,10 +202,10 @@ get__initialsync_local(client &client,
|
||||||
{
|
{
|
||||||
state, state_event,
|
state, state_event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &user.user_id,
|
.user_id = user.user_id,
|
||||||
.user_room = &user_room,
|
.user_room_id = user_room.room_id,
|
||||||
.room_depth = &room_depth,
|
.room_depth = room_depth,
|
||||||
.query_txnid = false,
|
.query_txnid = false,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -255,14 +255,17 @@ get__initialsync_local(client &client,
|
||||||
if(!visible(event, user.user_id))
|
if(!visible(event, user.user_id))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m::event::append(chunk, event,
|
m::event::append
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
chunk, event,
|
||||||
.user_id = &user.user_id,
|
{
|
||||||
.user_room = &user_room,
|
.event_idx = event_idx,
|
||||||
.room_depth = &room_depth,
|
.user_id = user.user_id,
|
||||||
.query_txnid = true,
|
.user_room_id = user_room.room_id,
|
||||||
});
|
.room_depth = room_depth,
|
||||||
|
.query_txnid = true,
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,8 +165,8 @@ get__members(client &client,
|
||||||
{
|
{
|
||||||
chunk, event,
|
chunk, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &request.user_id,
|
.user_id = request.user_id,
|
||||||
.query_txnid = false,
|
.query_txnid = false,
|
||||||
.query_prev_state = false,
|
.query_prev_state = false,
|
||||||
.query_redacted = false,
|
.query_redacted = false,
|
||||||
|
|
|
@ -152,10 +152,10 @@ get__messages(client &client,
|
||||||
{
|
{
|
||||||
chunk, event,
|
chunk, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &user_room.user.user_id,
|
.user_id = user_room.user.user_id,
|
||||||
.user_room = &user_room,
|
.user_room_id = user_room.room_id,
|
||||||
.room_depth = &room_depth,
|
.room_depth = room_depth,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -174,8 +174,8 @@ relations_chunk_append(client &client,
|
||||||
{
|
{
|
||||||
chunk, event,
|
chunk, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &request.user_id,
|
.user_id = request.user_id,
|
||||||
.query_txnid = false,
|
.query_txnid = false,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -206,8 +206,8 @@ append_event(const m::resource::request &request,
|
||||||
{
|
{
|
||||||
array, event,
|
array, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &request.user_id,
|
.user_id = request.user_id,
|
||||||
.query_txnid = false,
|
.query_txnid = false,
|
||||||
.query_prev_state = false,
|
.query_prev_state = false,
|
||||||
.query_redacted = false,
|
.query_redacted = false,
|
||||||
|
|
|
@ -550,8 +550,8 @@ try
|
||||||
{
|
{
|
||||||
result_event, event,
|
result_event, event,
|
||||||
{
|
{
|
||||||
.event_idx = &result.event_idx,
|
.event_idx = result.event_idx,
|
||||||
.user_id = &query.user_id,
|
.user_id = query.user_id,
|
||||||
.event_filter = &event_filter,
|
.event_filter = &event_filter,
|
||||||
.query_prev_state = false,
|
.query_prev_state = false,
|
||||||
.query_visible = true,
|
.query_visible = true,
|
||||||
|
@ -599,8 +599,8 @@ try
|
||||||
{
|
{
|
||||||
events_before, event,
|
events_before, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &query.user_id,
|
.user_id = query.user_id,
|
||||||
.event_filter = &event_filter,
|
.event_filter = &event_filter,
|
||||||
.query_prev_state = false,
|
.query_prev_state = false,
|
||||||
.query_visible = true,
|
.query_visible = true,
|
||||||
|
@ -628,8 +628,8 @@ try
|
||||||
{
|
{
|
||||||
events_after, event,
|
events_after, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &query.user_id,
|
.user_id = query.user_id,
|
||||||
.event_filter = &event_filter,
|
.event_filter = &event_filter,
|
||||||
.query_prev_state = false,
|
.query_prev_state = false,
|
||||||
.query_visible = true,
|
.query_visible = true,
|
||||||
|
|
|
@ -221,10 +221,10 @@ ircd::m::sync::room_state_linear_events(data &data)
|
||||||
{
|
{
|
||||||
array, event,
|
array, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &data.user.user_id,
|
.user_id = data.user.user_id,
|
||||||
.user_room = &data.user_room,
|
.user_room_id = data.user_room.room_id,
|
||||||
.room_depth = &data.room_depth,
|
.room_depth = data.room_depth,
|
||||||
.query_txnid = false,
|
.query_txnid = false,
|
||||||
.query_prev_state = true,
|
.query_prev_state = true,
|
||||||
}
|
}
|
||||||
|
@ -265,10 +265,10 @@ ircd::m::sync::room_state_linear_events(data &data)
|
||||||
{
|
{
|
||||||
array, *data.event,
|
array, *data.event,
|
||||||
{
|
{
|
||||||
.event_idx = &data.event_idx,
|
.event_idx = data.event_idx,
|
||||||
.user_id = &data.user.user_id,
|
.user_id = data.user.user_id,
|
||||||
.user_room = &data.user_room,
|
.user_room_id = data.user_room.room_id,
|
||||||
.room_depth = &data.room_depth,
|
.room_depth = data.room_depth,
|
||||||
.query_txnid = false,
|
.query_txnid = false,
|
||||||
.query_prev_state = true,
|
.query_prev_state = true,
|
||||||
}
|
}
|
||||||
|
@ -377,10 +377,10 @@ ircd::m::sync::room_state_polylog_events(data &data)
|
||||||
{
|
{
|
||||||
array, event,
|
array, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &data.user.user_id,
|
.user_id = data.user.user_id,
|
||||||
.user_room = &data.user_room,
|
.user_room_id = data.user_room.room_id,
|
||||||
.room_depth = &data.room_depth,
|
.room_depth = data.room_depth,
|
||||||
.query_txnid = false,
|
.query_txnid = false,
|
||||||
.query_prev_state = false,
|
.query_prev_state = false,
|
||||||
}
|
}
|
||||||
|
@ -517,10 +517,10 @@ ircd::m::sync::room_state_phased_events(data &data)
|
||||||
{
|
{
|
||||||
array, event,
|
array, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.user_id = &data.user.user_id,
|
.user_id = data.user.user_id,
|
||||||
.user_room = &data.user_room,
|
.user_room_id = data.user_room.room_id,
|
||||||
.room_depth = &data.room_depth,
|
.room_depth = data.room_depth,
|
||||||
.query_txnid = false,
|
.query_txnid = false,
|
||||||
.query_prev_state = true,
|
.query_prev_state = true,
|
||||||
}
|
}
|
||||||
|
@ -664,10 +664,10 @@ ircd::m::sync::room_state_phased_member_events(data &data,
|
||||||
{
|
{
|
||||||
array, event,
|
array, event,
|
||||||
{
|
{
|
||||||
.event_idx = &sender_idx,
|
.event_idx = sender_idx,
|
||||||
.user_id = &data.user.user_id,
|
.user_id = data.user.user_id,
|
||||||
.user_room = &data.user_room,
|
.user_room_id = data.user_room.room_id,
|
||||||
.room_depth = &data.room_depth,
|
.room_depth = data.room_depth,
|
||||||
.query_txnid = false,
|
.query_txnid = false,
|
||||||
.query_prev_state = false,
|
.query_prev_state = false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,11 +212,11 @@ ircd::m::sync::room_timeline_linear(data &data)
|
||||||
{
|
{
|
||||||
array, *data.event,
|
array, *data.event,
|
||||||
{
|
{
|
||||||
.event_idx = &data.event_idx,
|
.event_idx = data.event_idx,
|
||||||
.client_txnid = &data.client_txnid,
|
.client_txnid = data.client_txnid,
|
||||||
.user_id = &data.user.user_id,
|
.user_id = data.user.user_id,
|
||||||
.user_room = &data.user_room,
|
.user_room_id = data.user_room.room_id,
|
||||||
.room_depth = &data.room_depth,
|
.room_depth = data.room_depth,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -289,11 +289,11 @@ ircd::m::sync::_room_timeline_linear_command(data &data)
|
||||||
{
|
{
|
||||||
array, *data.event,
|
array, *data.event,
|
||||||
{
|
{
|
||||||
.event_idx = &data.event_idx,
|
.event_idx = data.event_idx,
|
||||||
.client_txnid = &data.client_txnid,
|
.client_txnid = data.client_txnid,
|
||||||
.user_id = &data.user.user_id,
|
.user_id = data.user.user_id,
|
||||||
.user_room = &data.user_room,
|
.user_room_id = data.user_room.room_id,
|
||||||
.room_depth = &data.room_depth,
|
.room_depth = data.room_depth,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -400,11 +400,11 @@ ircd::m::sync::_room_timeline_polylog_events(data &data,
|
||||||
{
|
{
|
||||||
array, event,
|
array, event,
|
||||||
{
|
{
|
||||||
.event_idx = &event_idx,
|
.event_idx = event_idx,
|
||||||
.client_txnid = &data.client_txnid,
|
.client_txnid = data.client_txnid,
|
||||||
.user_id = &data.user.user_id,
|
.user_id = data.user.user_id,
|
||||||
.user_room = &data.user_room,
|
.user_room_id = data.user_room.room_id,
|
||||||
.room_depth = &data.room_depth,
|
.room_depth = data.room_depth,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -677,14 +677,15 @@ ircd::m::bridge::append(const config &config,
|
||||||
const event::idx &event_idx,
|
const event::idx &event_idx,
|
||||||
const event &event)
|
const event &event)
|
||||||
{
|
{
|
||||||
event::append::opts opts;
|
|
||||||
opts.event_idx = &event_idx;
|
|
||||||
opts.query_txnid = false;
|
|
||||||
opts.query_prev_state = true;
|
|
||||||
opts.query_redacted = false;
|
|
||||||
event::append
|
event::append
|
||||||
{
|
{
|
||||||
events, event, opts
|
events, event, event::append::opts
|
||||||
|
{
|
||||||
|
.event_idx = event_idx,
|
||||||
|
.query_txnid = false,
|
||||||
|
.query_prev_state = true,
|
||||||
|
.query_redacted = false,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
log::debug
|
log::debug
|
||||||
|
|
Loading…
Reference in New Issue