diff --git a/include/ircd/m/event/event.h b/include/ircd/m/event/event.h index 4645cdfb5..fae953c23 100644 --- a/include/ircd/m/event/event.h +++ b/include/ircd/m/event/event.h @@ -129,13 +129,19 @@ struct ircd::m::event static sha256::buf hash(const json::object &); static json::object hashes(const mutable_buffer &, json::iov &event, const string_view &content); + m::event::id event_id; json::object source; // Contextual availability only. explicit operator id() const; - using super_type::tuple; - event(const json::object &); + event(const json::object &, const id &, const keys &); + event(const json::object &, const id &); + event(id::buf &, const json::object &, const string_view &version = "1"); event(const json::object &, const keys &); + event(const json::object &); + explicit event(const json::members &); + explicit event(const json::iov &, const id &); + explicit event(const json::iov &); event() = default; }; diff --git a/ircd/m.cc b/ircd/m.cc index 098f85580..0ca6b91bc 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -1840,8 +1840,11 @@ ircd::m::visible(const event::id &event_id, const m::event event { - { "event_id", event_id }, - { "room_id", room_id } + json::members + { + { "event_id", event_id }, + { "room_id", room_id }, + } }; return visible(event, mxid); diff --git a/ircd/m_event.cc b/ircd/m_event.cc index 453439442..f57a26e1e 100644 --- a/ircd/m_event.cc +++ b/ircd/m_event.cc @@ -1532,7 +1532,7 @@ ircd::m::event::fetch::assign_from_json(const string_view &key) assert(fopts); event = { - source, fopts->keys + source, event::keys{fopts->keys} }; assert(!empty(source)); @@ -3208,7 +3208,7 @@ ircd::m::event::hash(json::iov &event, event, { "content", content } }; - return m::hash(event); + return m::hash(m::event{event}); } ircd::sha256::buf @@ -3368,7 +3368,7 @@ ircd::m::event::sign(json::iov &event, essential(event, contents, [&sk, &sig] (json::iov &event) { - sig = m::sign(event, sk); + sig = m::sign(m::event{event}, sk); }); return sig; @@ -3944,11 +3944,55 @@ ircd::m::my(const id::event &event_id) // event::event // +ircd::m::event::event(const json::members &members) +:super_type +{ + members +} +,event_id +{ + defined(json::get<"event_id"_>(*this))? + id{json::get<"event_id"_>(*this)}: + id{}, +} +{ +} + +ircd::m::event::event(const json::iov &members) +:event +{ + members, + members.has("event_id")? + id{members.at("event_id")}: + id{} +} +{ +} + +ircd::m::event::event(const json::iov &members, + const id &id) +:super_type +{ + members +} +,event_id +{ + id +} +{ +} + ircd::m::event::event(const json::object &source) :super_type { source } +,event_id +{ + defined(json::get<"event_id"_>(*this))? + id{json::get<"event_id"_>(*this)}: + id{}, +} ,source { source @@ -3962,6 +4006,66 @@ ircd::m::event::event(const json::object &source, { source, keys } +,event_id +{ + defined(json::get<"event_id"_>(*this))? + id{json::get<"event_id"_>(*this)}: + id{}, +} +,source +{ + source +} +{ +} + +ircd::m::event::event(id::buf &buf, + const json::object &source, + const string_view &version) +:event +{ + source, + version == "1"? + id{unquote(source.get("event_id"))}: + version == "2"? + id{unquote(source.get("event_id"))}: + version == "3"? + id{id::v3{buf, source}}: + version == "4"? + id{id::v4{buf, source}}: + id{id::v4{buf, source}}, +} +{ +} + +ircd::m::event::event(const json::object &source, + const id &event_id) +:super_type +{ + source +} +,event_id +{ + event_id +} +,source +{ + source +} +{ +} + +ircd::m::event::event(const json::object &source, + const id &event_id, + const keys &keys) +:super_type +{ + source, keys +} +,event_id +{ + event_id +} ,source { source diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 650c816d0..fdb83264c 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -1278,8 +1278,11 @@ const const m::event event_ { - { "event_id", event_id }, - { "room_id", room_id }, + json::members + { + { "event_id", event_id }, + { "room_id", room_id }, + } }; return m::visible(event_, mxid); diff --git a/modules/console.cc b/modules/console.cc index 647d01d79..f57e022fc 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -5678,7 +5678,7 @@ console_cmd__stage(opt &out, const string_view &line) if(stage.size() == id) { - m::event base_event + m::event base_event{json::members { { "depth", json::undefined_number }, { "origin", my_host() }, @@ -5687,7 +5687,7 @@ console_cmd__stage(opt &out, const string_view &line) { "room_id", m::my_room.room_id }, { "type", "m.room.message" }, { "prev_state", "[]" }, - }; + }}; const json::strung content{json::members { diff --git a/modules/federation/invite2.cc b/modules/federation/invite2.cc index 7f76c624e..1043f203a 100644 --- a/modules/federation/invite2.cc +++ b/modules/federation/invite2.cc @@ -83,7 +83,7 @@ put__invite(client &client, const m::event event { - request["event"] + request["event"], event_id }; char check_buf[48]; diff --git a/modules/m_vm.cc b/modules/m_vm.cc index a8f157636..530ec5fb4 100644 --- a/modules/m_vm.cc +++ b/modules/m_vm.cc @@ -484,7 +484,7 @@ ircd::m::vm::inject(eval &eval, const m::event event_tuple { - event + event, m::event::id{event_id} }; if(opts.debuglog_precommit)