Skip to content

Commit

Permalink
ircd::m::event::append: Add branch for bundled relations; add m.repla…
Browse files Browse the repository at this point in the history
…ce bundle.
  • Loading branch information
jevolk committed May 1, 2023
1 parent 4fe8580 commit f6b3b8b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/ircd/m/event/append.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct ircd::m::event::append
bool is_invisible(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 _txnid(json::stack::object &, const event &, const opts &);
void _prev_state(json::stack::object &, const event &, const opts &);
Expand Down Expand Up @@ -72,6 +74,8 @@ struct ircd::m::event::append::opts
bool query_prev_state {true};
bool query_redacted {true};
bool query_visible {false};
bool bundle_all {false};
bool bundle_replace {false};
};

inline
Expand Down
66 changes: 64 additions & 2 deletions matrix/event_append.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ ircd::m::event::append::_unsigned(json::stack::object &out,

_age(object, event, opts);
_txnid(object, event, opts);

_relations(object, event, opts);
if(defined(json::get<"state_key"_>(event)))
_prev_state(object, event, opts);
}
Expand All @@ -197,7 +197,7 @@ ircd::m::event::append::_prev_state(json::stack::object &out,
const event &event,
const opts &opts)
{
assert(defined(json::get<"state_key"_>(event)))
assert(defined(json::get<"state_key"_>(event)));

const bool query_prev_state
{
Expand Down Expand Up @@ -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
ircd::m::event::append::is_excluded(const event &event,
const opts &opts)
Expand Down

0 comments on commit f6b3b8b

Please sign in to comment.