0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

ircd:Ⓜ️:event: Add event_id member; reorg ctors.

This commit is contained in:
Jason Volk 2019-07-05 19:45:02 -07:00
parent 8b4b47fd03
commit 4a289c065a
7 changed files with 129 additions and 13 deletions

View file

@ -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;
};

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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
{

View file

@ -83,7 +83,7 @@ put__invite(client &client,
const m::event event
{
request["event"]
request["event"], event_id
};
char check_buf[48];

View file

@ -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)