0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-30 04:38:52 +02:00

ircd:Ⓜ️:vm::eval: Fix generation and scope duration of event_id in array eval.

This commit is contained in:
Jason Volk 2019-09-13 15:27:02 -07:00
parent 0c45fb827d
commit 97881ac976
2 changed files with 22 additions and 6 deletions

View file

@ -1390,17 +1390,28 @@ ircd::m::vm::eval::eval(const json::array &pdus,
for(auto it(begin(events)); it != end(events); ++it) try for(auto it(begin(events)); it != end(events); ++it) try
{ {
auto &event{*it}; auto &event{*it};
if(!json::get<"event_id"_>(event))
event.event_id = event::id::v4 // If we set the event_id in the event instance we have to unset
// it so other contexts don't see an invalid reference.
const unwind event_id{[&event]
{ {
this->event_id, event event.event_id = json::get<"event_id"_>(event)?
}; event.event_id:
m::event::id{};
}};
// We have to set the event_id in the event instance if it didn't come
// with the event JSON.
if(!opts.edu && !event.event_id)
event.event_id = opts.room_version == "3"?
event::id{event::id::v3{this->event_id, event}}:
event::id{event::id::v4{this->event_id, event}};
// When a fault::EXISTS would not actually be revealed to the user in // When a fault::EXISTS would not actually be revealed to the user in
// any way we can elide a lot of grief by checking this here first and // any way we can elide a lot of grief by checking this here first and
// skipping the event. The query path will be adequately cached anyway. // skipping the event. The query path will be adequately cached anyway.
if(~(opts.warnlog | opts.errorlog) & fault::EXISTS) if(~(opts.warnlog | opts.errorlog) & fault::EXISTS)
if(m::exists(event.event_id)) if(event.event_id && m::exists(event.event_id))
continue; continue;
operator()(event); operator()(event);

View file

@ -692,6 +692,11 @@ try
eval.event_, &event eval.event_, &event
}; };
const scope_restore<event::id> eval_event_id
{
eval.event_id, event.event_id? event.event_id : eval.event_id
};
// Set a member to the room_id for convenient access, without stepping on // Set a member to the room_id for convenient access, without stepping on
// any room_id reference that exists there for whatever reason. // any room_id reference that exists there for whatever reason.
const scope_restore eval_room_id const scope_restore eval_room_id