Skip to content

Commit

Permalink
ircd::m: Implement matrix-org/matrix-spec-proposals#3316 timestamp ma…
Browse files Browse the repository at this point in the history
…ssaging.
  • Loading branch information
jevolk committed Jul 12, 2022
1 parent 584a0f4 commit ec55b9b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/ircd/m/vm/opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ struct ircd::m::vm::copts
/// A matrix-spec opaque token from a client identifying this eval.
string_view client_txnid;

/// MSC3316 appservice timestamp massage; passed to `origin_server_ts`.
milliseconds ts {milliseconds::min()};

/// This bitmask covers all of the top-level properties of m::event
/// which will be generated internally during injection unless they
/// already exist. Clearing any of these bits will prevent the internal
Expand Down
9 changes: 7 additions & 2 deletions matrix/vm_inject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,14 @@ ircd::m::vm::inject(eval &eval,
{
event, opts.prop_mask.has("origin_server_ts"),
{
"origin_server_ts", []
"origin_server_ts", [&opts]
{
return json::value{ircd::time<milliseconds>()};
return json::value
{
opts.ts == milliseconds::min()?
ircd::time<milliseconds>():
opts.ts.count()
};
}
}
};
Expand Down
12 changes: 10 additions & 2 deletions modules/client/rooms/send.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,16 @@ put__send(client &client,
content_max,
};

m::vm::copts copts;
copts.client_txnid = transaction_id;
const m::vm::copts copts
{
.client_txnid = transaction_id,

// Bridges are authorized to set their own time.
.ts = request.bridge_id?
request.query.get("ts", milliseconds::min()):
milliseconds::min(),
};

const room room
{
room_id, &copts
Expand Down
15 changes: 14 additions & 1 deletion modules/client/rooms/state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,22 @@ put__state(client &client,
request.content
};

const m::vm::copts copts
{
// Bridges are authorized to set their own time.
.ts = request.bridge_id?
request.query.get("ts", milliseconds::min()):
milliseconds::min(),
};

const m::room room
{
room_id, &copts
};

const auto event_id
{
m::send(room_id, request.user_id, type, state_key, content)
m::send(room, request.user_id, type, state_key, content)
};

return m::resource::response
Expand Down

0 comments on commit ec55b9b

Please sign in to comment.