0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 00:02:34 +01:00

ircd:Ⓜ️:event::append: Add branch for bundled relations; add m.replace bundle.

This commit is contained in:
Jason Volk 2023-04-29 22:19:37 -07:00
parent 4fe85805bf
commit f6b3b8b758
2 changed files with 68 additions and 2 deletions

View file

@ -41,6 +41,8 @@ struct ircd::m::event::append
bool is_invisible(const event &, const opts &) const; bool is_invisible(const event &, const opts &) const;
bool is_excluded(const event &, const opts &) const; bool is_excluded(const event &, const opts &) const;
bool bundle_replace(json::stack::object &, const event &, const opts &);
void _relations(json::stack::object &, const event &, const opts &);
void _age(json::stack::object &, const event &, const opts &); void _age(json::stack::object &, const event &, const opts &);
void _txnid(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 _prev_state(json::stack::object &, const event &, const opts &);
@ -72,6 +74,8 @@ struct ircd::m::event::append::opts
bool query_prev_state {true}; bool query_prev_state {true};
bool query_redacted {true}; bool query_redacted {true};
bool query_visible {false}; bool query_visible {false};
bool bundle_all {false};
bool bundle_replace {false};
}; };
inline inline

View file

@ -187,7 +187,7 @@ ircd::m::event::append::_unsigned(json::stack::object &out,
_age(object, event, opts); _age(object, event, opts);
_txnid(object, event, opts); _txnid(object, event, opts);
_relations(object, event, opts);
if(defined(json::get<"state_key"_>(event))) if(defined(json::get<"state_key"_>(event)))
_prev_state(object, event, opts); _prev_state(object, event, opts);
} }
@ -197,7 +197,7 @@ ircd::m::event::append::_prev_state(json::stack::object &out,
const event &event, const event &event,
const opts &opts) const opts &opts)
{ {
assert(defined(json::get<"state_key"_>(event))) assert(defined(json::get<"state_key"_>(event)));
const bool query_prev_state const bool query_prev_state
{ {
@ -339,6 +339,68 @@ ircd::m::event::append::_age(json::stack::object &out,
}; };
} }
void
ircd::m::event::append::_relations(json::stack::object &out,
const event &event,
const opts &opts)
{
assert(out.s);
json::stack::checkpoint cp
{
*out.s, false
};
json::stack::object object
{
out, "m.relations"
};
bool commit
{
cp.committing()
};
if(opts.bundle_all || opts.bundle_replace)
commit |= bundle_replace(object, event, opts);
cp.committing(commit);
}
bool
ircd::m::event::append::bundle_replace(json::stack::object &out,
const event &event,
const opts &opts)
{
const m::replaced replaced
{
opts.event_idx, m::replaced::latest
};
const event::idx &replace_idx
{
replaced
};
if(likely(!replace_idx))
return false;
const m::event::fetch replace
{
std::nothrow, replace_idx
};
if(unlikely(!replace.valid))
return false;
json::stack::object object
{
out, "m.replace"
};
object.append(replace);
return true;
}
bool bool
ircd::m::event::append::is_excluded(const event &event, ircd::m::event::append::is_excluded(const event &event,
const opts &opts) const opts &opts)