Replace uses of SystemTime with new UInt-based timestamp types

This commit is contained in:
Jonas Platte 2021-05-13 01:13:24 +02:00
parent c34d570fff
commit 5710d2740c
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
45 changed files with 217 additions and 270 deletions

View File

@ -1,9 +1,7 @@
//! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-account-3pid) //! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-account-3pid)
use std::time::SystemTime;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::thirdparty::Medium; use ruma_common::{thirdparty::Medium, MilliSecondsSinceUnixEpoch};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
ruma_api! { ruma_api! {
@ -58,12 +56,10 @@ pub struct ThirdPartyIdentifier {
pub medium: Medium, pub medium: Medium,
/// The time when the identifier was validated by the identity server. /// The time when the identifier was validated by the identity server.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub validated_at: MilliSecondsSinceUnixEpoch,
pub validated_at: SystemTime,
/// The time when the homeserver associated the third party identifier with the user. /// The time when the homeserver associated the third party identifier with the user.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub added_at: MilliSecondsSinceUnixEpoch,
pub added_at: SystemTime,
} }
/// Initial set of fields of `ThirdPartyIdentifier`. /// Initial set of fields of `ThirdPartyIdentifier`.
@ -79,10 +75,10 @@ pub struct ThirdPartyIdentifierInit {
pub medium: Medium, pub medium: Medium,
/// The time when the identifier was validated by the identity server. /// The time when the identifier was validated by the identity server.
pub validated_at: SystemTime, pub validated_at: MilliSecondsSinceUnixEpoch,
/// The time when the homeserver associated the third party identifier with the user. /// The time when the homeserver associated the third party identifier with the user.
pub added_at: SystemTime, pub added_at: MilliSecondsSinceUnixEpoch,
} }
impl From<ThirdPartyIdentifierInit> for ThirdPartyIdentifier { impl From<ThirdPartyIdentifierInit> for ThirdPartyIdentifier {
@ -94,8 +90,9 @@ impl From<ThirdPartyIdentifierInit> for ThirdPartyIdentifier {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::time::{Duration, UNIX_EPOCH}; use std::convert::TryInto;
use ruma_common::MilliSecondsSinceUnixEpoch;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use super::{Medium, ThirdPartyIdentifier}; use super::{Medium, ThirdPartyIdentifier};
@ -105,8 +102,8 @@ mod tests {
let third_party_id = ThirdPartyIdentifier { let third_party_id = ThirdPartyIdentifier {
address: "monkey@banana.island".into(), address: "monkey@banana.island".into(),
medium: Medium::Email, medium: Medium::Email,
validated_at: UNIX_EPOCH + Duration::from_millis(1_535_176_800_000), validated_at: MilliSecondsSinceUnixEpoch(1_535_176_800_000_u64.try_into().unwrap()),
added_at: UNIX_EPOCH + Duration::from_millis(1_535_336_848_756), added_at: MilliSecondsSinceUnixEpoch(1_535_336_848_756_u64.try_into().unwrap()),
}; };
let third_party_id_serialized = json!({ let third_party_id_serialized = json!({

View File

@ -1,7 +1,6 @@
//! Endpoints for managing devices. //! Endpoints for managing devices.
use std::time::SystemTime; use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::DeviceIdBox; use ruma_identifiers::DeviceIdBox;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -25,12 +24,8 @@ pub struct Device {
pub last_seen_ip: Option<String>, pub last_seen_ip: Option<String>,
/// Unix timestamp that the session was last active. /// Unix timestamp that the session was last active.
#[serde( #[serde(skip_serializing_if = "Option::is_none")]
with = "ruma_serde::time::opt_ms_since_unix_epoch", pub last_seen_ts: Option<MilliSecondsSinceUnixEpoch>,
default,
skip_serializing_if = "Option::is_none"
)]
pub last_seen_ts: Option<SystemTime>,
} }
impl Device { impl Device {

View File

@ -1,8 +1,7 @@
//! [GET /_matrix/media/r0/preview_url](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-media-r0-preview-url) //! [GET /_matrix/media/r0/preview_url](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-media-r0-preview-url)
use std::time::SystemTime;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch;
use serde::Serialize; use serde::Serialize;
use serde_json::value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue}; use serde_json::value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue};
@ -23,8 +22,7 @@ ruma_api! {
/// Preferred point in time (in milliseconds) to return a preview for. /// Preferred point in time (in milliseconds) to return a preview for.
#[ruma_api(query)] #[ruma_api(query)]
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub ts: MilliSecondsSinceUnixEpoch,
pub ts: SystemTime,
} }
#[derive(Default)] #[derive(Default)]
@ -42,7 +40,7 @@ ruma_api! {
impl<'a> Request<'a> { impl<'a> Request<'a> {
/// Creates a new `Request` with the given url and timestamp. /// Creates a new `Request` with the given url and timestamp.
pub fn new(url: &'a str, ts: SystemTime) -> Self { pub fn new(url: &'a str, ts: MilliSecondsSinceUnixEpoch) -> Self {
Self { url, ts } Self { url, ts }
} }
} }

View File

@ -1,10 +1,8 @@
//! [GET /_matrix/client/r0/notifications](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-notifications) //! [GET /_matrix/client/r0/notifications](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-notifications)
use std::time::SystemTime;
use js_int::UInt; use js_int::UInt;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::push::Action; use ruma_common::{push::Action, MilliSecondsSinceUnixEpoch};
use ruma_events::AnySyncRoomEvent; use ruma_events::AnySyncRoomEvent;
use ruma_identifiers::RoomId; use ruma_identifiers::RoomId;
use ruma_serde::Raw; use ruma_serde::Raw;
@ -89,8 +87,7 @@ pub struct Notification {
pub room_id: RoomId, pub room_id: RoomId,
/// The time at which the event notification was sent. /// The time at which the event notification was sent.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub ts: MilliSecondsSinceUnixEpoch,
pub ts: SystemTime,
} }
impl Notification { impl Notification {
@ -101,7 +98,7 @@ impl Notification {
event: Raw<AnySyncRoomEvent>, event: Raw<AnySyncRoomEvent>,
read: bool, read: bool,
room_id: RoomId, room_id: RoomId,
ts: SystemTime, ts: MilliSecondsSinceUnixEpoch,
) -> Self { ) -> Self {
Self { actions, event, profile_tag: None, read, room_id, ts } Self { actions, event, profile_tag: None, read, room_id, ts }
} }

View File

@ -1,8 +1,9 @@
//! [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-admin-whois-userid) //! [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-admin-whois-userid)
use std::{collections::BTreeMap, time::SystemTime}; use std::collections::BTreeMap;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -73,8 +74,7 @@ pub struct ConnectionInfo {
pub ip: Option<String>, pub ip: Option<String>,
/// Time when that the session was last active. /// Time when that the session was last active.
#[serde(with = "ruma_serde::time::opt_ms_since_unix_epoch")] pub last_seen: Option<MilliSecondsSinceUnixEpoch>,
pub last_seen: Option<SystemTime>,
/// User agent string last seen in the session. /// User agent string last seen in the session.
pub user_agent: Option<String>, pub user_agent: Option<String>,

View File

@ -63,7 +63,6 @@ fn expand_serialize_event(
fields: &[Field], fields: &[Field],
ruma_events: &TokenStream, ruma_events: &TokenStream,
) -> TokenStream { ) -> TokenStream {
let js_int = quote! { #ruma_events::exports::js_int };
let serde = quote! { #ruma_events::exports::serde }; let serde = quote! { #ruma_events::exports::serde };
let ident = &input.ident; let ident = &input.ident;
@ -84,17 +83,6 @@ fn expand_serialize_event(
state.serialize_field("prev_content", content)?; state.serialize_field("prev_content", content)?;
} }
} }
} else if name == "origin_server_ts" {
quote! {
let time_since_epoch =
self.origin_server_ts.duration_since(::std::time::UNIX_EPOCH).unwrap();
let timestamp = <#js_int::UInt as ::std::convert::TryFrom<_>>::try_from(
time_since_epoch.as_millis(),
).map_err(S::Error::custom)?;
state.serialize_field("origin_server_ts", &timestamp)?;
}
} else if name == "unsigned" { } else if name == "unsigned" {
quote! { quote! {
if !self.unsigned.is_empty() { if !self.unsigned.is_empty() {
@ -136,7 +124,6 @@ fn expand_deserialize_event(
fields: &[Field], fields: &[Field],
ruma_events: &TokenStream, ruma_events: &TokenStream,
) -> syn::Result<TokenStream> { ) -> syn::Result<TokenStream> {
let js_int = quote! { #ruma_events::exports::js_int };
let serde = quote! { #ruma_events::exports::serde }; let serde = quote! { #ruma_events::exports::serde };
let serde_json = quote! { #ruma_events::exports::serde_json }; let serde_json = quote! { #ruma_events::exports::serde_json };
@ -171,8 +158,6 @@ fn expand_deserialize_event(
} else { } else {
quote! { #content_type } quote! { #content_type }
} }
} else if name == "origin_server_ts" {
quote! { #js_int::UInt }
} else { } else {
quote! { #ty } quote! { #ty }
} }
@ -236,15 +221,6 @@ fn expand_deserialize_event(
}; };
} }
} }
} else if name == "origin_server_ts" {
quote! {
let origin_server_ts = origin_server_ts
.map(|time| {
let t = time.into();
::std::time::UNIX_EPOCH + ::std::time::Duration::from_millis(t)
})
.ok_or_else(|| #serde::de::Error::missing_field("origin_server_ts"))?;
}
} else if name == "unsigned" { } else if name == "unsigned" {
quote! { let unsigned = unsigned.unwrap_or_default(); } quote! { let unsigned = unsigned.unwrap_or_default(); }
} else { } else {

View File

@ -937,10 +937,11 @@ fn field_return_type(
var: &EventKindVariation, var: &EventKindVariation,
ruma_events: &TokenStream, ruma_events: &TokenStream,
) -> TokenStream { ) -> TokenStream {
let ruma_common = quote! { #ruma_events::exports::ruma_common };
let ruma_identifiers = quote! { #ruma_events::exports::ruma_identifiers }; let ruma_identifiers = quote! { #ruma_events::exports::ruma_identifiers };
match name { match name {
"origin_server_ts" => quote! { ::std::time::SystemTime }, "origin_server_ts" => quote! { #ruma_common::MilliSecondsSinceUnixEpoch },
"room_id" => quote! { #ruma_identifiers::RoomId }, "room_id" => quote! { #ruma_identifiers::RoomId },
"event_id" => quote! { #ruma_identifiers::EventId }, "event_id" => quote! { #ruma_identifiers::EventId },
"sender" => quote! { #ruma_identifiers::UserId }, "sender" => quote! { #ruma_identifiers::UserId },

View File

@ -1,5 +1,4 @@
use std::time::SystemTime; use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events_macros::Event; use ruma_events_macros::Event;
use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomId, UserId};
@ -56,7 +55,7 @@ pub struct MessageEvent<C: MessageEventContent> {
pub sender: UserId, pub sender: UserId,
/// Timestamp in milliseconds on originating homeserver when this event was sent. /// Timestamp in milliseconds on originating homeserver when this event was sent.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// The ID of the room associated with this event. /// The ID of the room associated with this event.
pub room_id: RoomId, pub room_id: RoomId,
@ -82,7 +81,7 @@ pub struct SyncMessageEvent<C: MessageEventContent> {
pub sender: UserId, pub sender: UserId,
/// Timestamp in milliseconds on originating homeserver when this event was sent. /// Timestamp in milliseconds on originating homeserver when this event was sent.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// Additional key-value pairs not signed by the homeserver. /// Additional key-value pairs not signed by the homeserver.
pub unsigned: Unsigned, pub unsigned: Unsigned,
@ -105,7 +104,7 @@ pub struct RedactedMessageEvent<C: RedactedMessageEventContent> {
pub sender: UserId, pub sender: UserId,
/// Timestamp in milliseconds on originating homeserver when this event was sent. /// Timestamp in milliseconds on originating homeserver when this event was sent.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// The ID of the room associated with this event. /// The ID of the room associated with this event.
pub room_id: RoomId, pub room_id: RoomId,
@ -132,7 +131,7 @@ pub struct RedactedSyncMessageEvent<C: RedactedMessageEventContent> {
pub sender: UserId, pub sender: UserId,
/// Timestamp in milliseconds on originating homeserver when this event was sent. /// Timestamp in milliseconds on originating homeserver when this event was sent.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// Additional key-value pairs not signed by the homeserver. /// Additional key-value pairs not signed by the homeserver.
pub unsigned: RedactedSyncUnsigned, pub unsigned: RedactedSyncUnsigned,
@ -155,7 +154,7 @@ pub struct StateEvent<C: StateEventContent> {
pub sender: UserId, pub sender: UserId,
/// Timestamp in milliseconds on originating homeserver when this event was sent. /// Timestamp in milliseconds on originating homeserver when this event was sent.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// The ID of the room associated with this event. /// The ID of the room associated with this event.
pub room_id: RoomId, pub room_id: RoomId,
@ -190,7 +189,7 @@ pub struct SyncStateEvent<C: StateEventContent> {
pub sender: UserId, pub sender: UserId,
/// Timestamp in milliseconds on originating homeserver when this event was sent. /// Timestamp in milliseconds on originating homeserver when this event was sent.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// A unique key which defines the overwriting semantics for this piece of room state. /// A unique key which defines the overwriting semantics for this piece of room state.
/// ///
@ -255,7 +254,7 @@ pub struct RedactedStateEvent<C: RedactedStateEventContent> {
pub sender: UserId, pub sender: UserId,
/// Timestamp in milliseconds on originating homeserver when this event was sent. /// Timestamp in milliseconds on originating homeserver when this event was sent.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// The ID of the room associated with this event. /// The ID of the room associated with this event.
pub room_id: RoomId, pub room_id: RoomId,
@ -288,7 +287,7 @@ pub struct RedactedSyncStateEvent<C: RedactedStateEventContent> {
pub sender: UserId, pub sender: UserId,
/// Timestamp in milliseconds on originating homeserver when this event was sent. /// Timestamp in milliseconds on originating homeserver when this event was sent.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// A unique key which defines the overwriting semantics for this piece of room state. /// A unique key which defines the overwriting semantics for this piece of room state.
/// ///

View File

@ -1,7 +1,6 @@
//! Types for the *m.key.verification.request* event. //! Types for the *m.key.verification.request* event.
use std::time::SystemTime; use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events_macros::EventContent; use ruma_events_macros::EventContent;
use ruma_identifiers::DeviceIdBox; use ruma_identifiers::DeviceIdBox;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -27,6 +26,5 @@ pub struct RequestToDeviceEventContent {
/// ///
/// If the request is in the future by more than 5 minutes or more than 10 minutes in /// If the request is in the future by more than 5 minutes or more than 10 minutes in
/// the past, the message should be ignored by the receiver. /// the past, the message should be ignored by the receiver.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub timestamp: MilliSecondsSinceUnixEpoch,
pub timestamp: SystemTime,
} }

View File

@ -143,7 +143,7 @@ extern crate self as ruma_events;
/// It is not considered part of ruma-events' public API. /// It is not considered part of ruma-events' public API.
#[doc(hidden)] #[doc(hidden)]
pub mod exports { pub mod exports {
pub use js_int; pub use ruma_common;
pub use ruma_identifiers; pub use ruma_identifiers;
pub use serde; pub use serde;
pub use serde_json; pub use serde_json;

View File

@ -8,9 +8,10 @@
//! The stubbed versions of each PDU type remove the `event_id` field (if any) //! The stubbed versions of each PDU type remove the `event_id` field (if any)
//! and the `room_id` field for use in PDU templates. //! and the `room_id` field for use in PDU templates.
use std::{collections::BTreeMap, time::SystemTime}; use std::collections::BTreeMap;
use js_int::UInt; use js_int::UInt;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::EventType; use ruma_events::EventType;
use ruma_identifiers::{EventId, RoomId, ServerNameBox, ServerSigningKeyId, UserId}; use ruma_identifiers::{EventId, RoomId, ServerNameBox, ServerSigningKeyId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -46,8 +47,7 @@ pub struct RoomV1Pdu {
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver /// Timestamp (milliseconds since the UNIX epoch) on originating homeserver
/// of when this event was created. /// of when this event was created.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub origin_server_ts: MilliSecondsSinceUnixEpoch,
pub origin_server_ts: SystemTime,
// TODO: Encode event type as content enum variant, like event enums do // TODO: Encode event type as content enum variant, like event enums do
/// The event's type. /// The event's type.
@ -106,8 +106,7 @@ pub struct RoomV3Pdu {
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver /// Timestamp (milliseconds since the UNIX epoch) on originating homeserver
/// of when this event was created. /// of when this event was created.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub origin_server_ts: MilliSecondsSinceUnixEpoch,
pub origin_server_ts: SystemTime,
// TODO: Encode event type as content enum variant, like event enums do // TODO: Encode event type as content enum variant, like event enums do
/// The event's type. /// The event's type.

View File

@ -15,8 +15,10 @@ pub struct RoomEventContent(pub PolicyRuleEventContent);
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::time::{Duration, UNIX_EPOCH}; use std::convert::TryInto;
use js_int::int;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::{event_id, room_id, user_id}; use ruma_identifiers::{event_id, room_id, user_id};
use ruma_serde::Raw; use ruma_serde::Raw;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -32,12 +34,12 @@ mod tests {
let room_event = RoomEvent { let room_event = RoomEvent {
event_id: event_id!("$143273582443PhrSn:example.org"), event_id: event_id!("$143273582443PhrSn:example.org"),
sender: user_id!("@example:example.org"), sender: user_id!("@example:example.org"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1_432_735_824_653), origin_server_ts: MilliSecondsSinceUnixEpoch(1_432_735_824_653_u64.try_into().unwrap()),
room_id: room_id!("!jEsUZKDJdhlrceRyVU:example.org"), room_id: room_id!("!jEsUZKDJdhlrceRyVU:example.org"),
state_key: "rule:#*:example.org".into(), state_key: "rule:#*:example.org".into(),
prev_content: None, prev_content: None,
unsigned: Unsigned { unsigned: Unsigned {
age: Some(1234.into()), age: Some(int!(1234)),
transaction_id: None, transaction_id: None,
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
relations: None, relations: None,

View File

@ -3,10 +3,9 @@
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
time::SystemTime,
}; };
use ruma_common::receipt::ReceiptType; use ruma_common::{receipt::ReceiptType, MilliSecondsSinceUnixEpoch};
use ruma_events_macros::EphemeralRoomEventContent; use ruma_events_macros::EphemeralRoomEventContent;
use ruma_identifiers::{EventId, UserId}; use ruma_identifiers::{EventId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -50,10 +49,6 @@ pub type UserReceipts = BTreeMap<UserId, Receipt>;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Receipt { pub struct Receipt {
/// The time when the receipt was sent. /// The time when the receipt was sent.
#[serde( #[serde(skip_serializing_if = "Option::is_none")]
with = "ruma_serde::time::opt_ms_since_unix_epoch", pub ts: Option<MilliSecondsSinceUnixEpoch>,
default,
skip_serializing_if = "Option::is_none"
)]
pub ts: Option<SystemTime>,
} }

View File

@ -1,8 +1,9 @@
//! Types describing event relations after MSC 2674, 2675, 2676, 2677. //! Types describing event relations after MSC 2674, 2675, 2676, 2677.
use std::{fmt::Debug, time::SystemTime}; use std::fmt::Debug;
use js_int::UInt; use js_int::UInt;
use ruma_common::MilliSecondsSinceUnixEpoch;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Summary of all reactions with the given key to an event. /// Summary of all reactions with the given key to an event.
@ -13,12 +14,8 @@ pub struct BundledReaction {
pub key: String, pub key: String,
/// Time of the bundled reaction being compiled on the server. /// Time of the bundled reaction being compiled on the server.
#[serde( #[serde(skip_serializing_if = "Option::is_none")]
with = "ruma_serde::time::opt_ms_since_unix_epoch", pub origin_server_ts: Option<MilliSecondsSinceUnixEpoch>,
default,
skip_serializing_if = "Option::is_none"
)]
pub origin_server_ts: Option<SystemTime>,
/// Number of reactions. /// Number of reactions.
pub count: UInt, pub count: UInt,
@ -26,7 +23,11 @@ pub struct BundledReaction {
impl BundledReaction { impl BundledReaction {
/// Creates a new `BundledReaction`. /// Creates a new `BundledReaction`.
pub fn new(key: String, origin_server_ts: Option<SystemTime>, count: UInt) -> Self { pub fn new(
key: String,
origin_server_ts: Option<MilliSecondsSinceUnixEpoch>,
count: UInt,
) -> Self {
Self { key, origin_server_ts, count } Self { key, origin_server_ts, count }
} }
} }

View File

@ -39,8 +39,8 @@ impl CanonicalAliasEventContent {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::time::{Duration, UNIX_EPOCH}; use js_int::uint;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::{event_id, room_alias_id, room_id, user_id}; use ruma_identifiers::{event_id, room_alias_id, room_id, user_id};
use ruma_serde::Raw; use ruma_serde::Raw;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -56,7 +56,7 @@ mod tests {
alt_aliases: Vec::new(), alt_aliases: Vec::new(),
}, },
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
prev_content: None, prev_content: None,
room_id: room_id!("!dummy:example.com"), room_id: room_id!("!dummy:example.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),

View File

@ -254,10 +254,10 @@ impl StrippedStateEvent<MemberEventContent> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::time::{Duration, UNIX_EPOCH}; use js_int::uint;
use maplit::btreemap; use maplit::btreemap;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::{server_name, server_signing_key_id}; use ruma_identifiers::{server_name, server_signing_key_id};
use ruma_serde::Raw; use ruma_serde::Raw;
use serde_json::{from_value as from_json_value, json}; use serde_json::{from_value as from_json_value, json};
@ -300,7 +300,7 @@ mod tests {
unsigned, unsigned,
prev_content: None, prev_content: None,
} if event_id == "$h29iv0s8:example.com" } if event_id == "$h29iv0s8:example.com"
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& room_id == "!n8f893n9:example.com" && room_id == "!n8f893n9:example.com"
&& sender == "@carl:example.com" && sender == "@carl:example.com"
&& state_key == "example.com" && state_key == "example.com"
@ -352,7 +352,7 @@ mod tests {
third_party_invite: None, third_party_invite: None,
}), }),
} if event_id == "$h29iv0s8:example.com" } if event_id == "$h29iv0s8:example.com"
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& room_id == "!n8f893n9:example.com" && room_id == "!n8f893n9:example.com"
&& sender == "@carl:example.com" && sender == "@carl:example.com"
&& state_key == "example.com" && state_key == "example.com"
@ -423,7 +423,7 @@ mod tests {
} }
&& token == "abc123" && token == "abc123"
&& event_id == "$143273582443PhrSn:example.org" && event_id == "$143273582443PhrSn:example.org"
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(233) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(233))
&& room_id == "!jEsUZKDJdhlrceRyVU:example.org" && room_id == "!jEsUZKDJdhlrceRyVU:example.org"
&& sender == "@alice:example.org" && sender == "@alice:example.org"
&& state_key == "@alice:example.org" && state_key == "@alice:example.org"
@ -493,7 +493,7 @@ mod tests {
}), }),
}), }),
} if event_id == "$143273582443PhrSn:example.org" } if event_id == "$143273582443PhrSn:example.org"
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(233) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(233))
&& room_id == "!jEsUZKDJdhlrceRyVU:example.org" && room_id == "!jEsUZKDJdhlrceRyVU:example.org"
&& sender == "@alice:example.org" && sender == "@alice:example.org"
&& state_key == "@alice:example.org" && state_key == "@alice:example.org"
@ -569,7 +569,7 @@ mod tests {
}), }),
}), }),
} if event_id == "$143273582443PhrSn:example.org" } if event_id == "$143273582443PhrSn:example.org"
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(233) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(233))
&& room_id == "!jEsUZKDJdhlrceRyVU:example.org" && room_id == "!jEsUZKDJdhlrceRyVU:example.org"
&& sender == "@alice:example.org" && sender == "@alice:example.org"
&& state_key == "@alice:example.org" && state_key == "@alice:example.org"

View File

@ -56,10 +56,9 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::time::{Duration, UNIX_EPOCH}; use js_int::{int, uint};
use js_int::int;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::{event_id, room_id, user_id}; use ruma_identifiers::{event_id, room_id, user_id};
use ruma_serde::Raw; use ruma_serde::Raw;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -72,7 +71,7 @@ mod tests {
let name_event = StateEvent { let name_event = StateEvent {
content: NameEventContent { name: Some("The room name".into()) }, content: NameEventContent { name: Some("The room name".into()) },
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
prev_content: None, prev_content: None,
room_id: room_id!("!n8f893n9:example.com"), room_id: room_id!("!n8f893n9:example.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
@ -101,7 +100,7 @@ mod tests {
let name_event = StateEvent { let name_event = StateEvent {
content: NameEventContent { name: Some("The room name".into()) }, content: NameEventContent { name: Some("The room name".into()) },
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
prev_content: Some(NameEventContent { name: Some("The old name".into()) }), prev_content: Some(NameEventContent { name: Some("The old name".into()) }),
room_id: room_id!("!n8f893n9:example.com"), room_id: room_id!("!n8f893n9:example.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),

View File

@ -27,11 +27,9 @@ impl PinnedEventsEventContent {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::{ use std::convert::{TryFrom, TryInto};
convert::TryFrom,
time::{Duration, UNIX_EPOCH},
};
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::{EventId, RoomId, ServerName, UserId}; use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
use ruma_serde::Raw; use ruma_serde::Raw;
@ -49,7 +47,7 @@ mod tests {
let event = StateEvent { let event = StateEvent {
content: content.clone(), content: content.clone(),
event_id: EventId::new(server_name), event_id: EventId::new(server_name),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1_432_804_485_886_u64), origin_server_ts: MilliSecondsSinceUnixEpoch(1_432_804_485_886_u64.try_into().unwrap()),
prev_content: None, prev_content: None,
room_id: RoomId::new(server_name), room_id: RoomId::new(server_name),
sender: UserId::new(server_name), sender: UserId::new(server_name),

View File

@ -143,14 +143,12 @@ fn is_default_power_level(l: &Int) -> bool {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::{ use std::collections::BTreeMap;
collections::BTreeMap,
time::{Duration, UNIX_EPOCH},
};
use assign::assign; use assign::assign;
use js_int::int; use js_int::{int, uint};
use maplit::btreemap; use maplit::btreemap;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::{event_id, room_id, user_id}; use ruma_identifiers::{event_id, room_id, user_id};
use serde_json::{json, to_value as to_json_value}; use serde_json::{json, to_value as to_json_value};
@ -175,7 +173,7 @@ mod tests {
notifications: NotificationPowerLevels::default(), notifications: NotificationPowerLevels::default(),
}, },
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
prev_content: None, prev_content: None,
room_id: room_id!("!n8f893n9:example.com"), room_id: room_id!("!n8f893n9:example.com"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),
@ -218,7 +216,7 @@ mod tests {
notifications: assign!(NotificationPowerLevels::new(), { room: int!(23) }), notifications: assign!(NotificationPowerLevels::new(), { room: int!(23) }),
}, },
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
prev_content: Some(PowerLevelsEventContent { prev_content: Some(PowerLevelsEventContent {
// Make just one field different so we at least know they're two different objects. // Make just one field different so we at least know they're two different objects.
ban: int!(42), ban: int!(42),

View File

@ -1,7 +1,6 @@
//! Types for the *m.room.redaction* event. //! Types for the *m.room.redaction* event.
use std::time::SystemTime; use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events_macros::{Event, EventContent}; use ruma_events_macros::{Event, EventContent};
use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -27,7 +26,7 @@ pub struct RedactionEvent {
pub sender: UserId, pub sender: UserId,
/// Timestamp in milliseconds on originating homeserver when this event was sent. /// Timestamp in milliseconds on originating homeserver when this event was sent.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// The ID of the room associated with this event. /// The ID of the room associated with this event.
pub room_id: RoomId, pub room_id: RoomId,
@ -52,7 +51,7 @@ pub struct SyncRedactionEvent {
pub sender: UserId, pub sender: UserId,
/// Timestamp in milliseconds on originating homeserver when this event was sent. /// Timestamp in milliseconds on originating homeserver when this event was sent.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// Additional key-value pairs not signed by the homeserver. /// Additional key-value pairs not signed by the homeserver.
pub unsigned: Unsigned, pub unsigned: Unsigned,

View File

@ -1,7 +1,7 @@
use std::time::{Duration, UNIX_EPOCH}; use js_int::uint;
use maplit::btreemap; use maplit::btreemap;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
custom::CustomEventContent, AnyMessageEvent, AnyStateEvent, AnyStateEventContent, custom::CustomEventContent, AnyMessageEvent, AnyStateEvent, AnyStateEventContent,
AnySyncMessageEvent, AnySyncRoomEvent, MessageEvent, StateEvent, SyncMessageEvent, AnySyncMessageEvent, AnySyncRoomEvent, MessageEvent, StateEvent, SyncMessageEvent,
@ -53,7 +53,7 @@ fn serialize_custom_message_event() {
event_type: "m.room.message".into(), event_type: "m.room.message".into(),
}, },
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(10), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10)),
room_id: room_id!("!room:room.com"), room_id: room_id!("!room:room.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),
@ -93,7 +93,7 @@ fn serialize_custom_state_event() {
event_type: "m.made.up".into(), event_type: "m.made.up".into(),
}, },
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(10), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10)),
prev_content: None, prev_content: None,
room_id: room_id!("!roomid:room.com"), room_id: room_id!("!roomid:room.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
@ -147,7 +147,7 @@ fn deserialize_custom_state_event() {
unsigned, unsigned,
}) if data == expected_content && event_type == "m.reaction" }) if data == expected_content && event_type == "m.reaction"
&& event_id == event_id!("$h29iv0s8:example.com") && event_id == event_id!("$h29iv0s8:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(10) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(10))
&& sender == user_id!("@carl:example.com") && sender == user_id!("@carl:example.com")
&& room_id == room_id!("!room:room.com") && room_id == room_id!("!room:room.com")
&& state_key.is_empty() && state_key.is_empty()
@ -183,7 +183,7 @@ fn deserialize_custom_state_sync_event() {
unsigned, unsigned,
} if data == expected_content && event_type == "m.reaction" } if data == expected_content && event_type == "m.reaction"
&& event_id == event_id!("$h29iv0s8:example.com") && event_id == event_id!("$h29iv0s8:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(10) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(10))
&& sender == user_id!("@carl:example.com") && sender == user_id!("@carl:example.com")
&& state_key.is_empty() && state_key.is_empty()
&& !unsigned.is_empty() && !unsigned.is_empty()
@ -221,7 +221,7 @@ fn deserialize_custom_message_sync_event() {
unsigned, unsigned,
})) if data == expected_content && event_type == "m.ruma_custom" })) if data == expected_content && event_type == "m.ruma_custom"
&& event_id == event_id!("$h29iv0s8:example.com") && event_id == event_id!("$h29iv0s8:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(10) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(10))
&& sender == user_id!("@carl:example.com") && sender == user_id!("@carl:example.com")
&& !unsigned.is_empty() && !unsigned.is_empty()
); );

View File

@ -1,6 +1,6 @@
use std::time::UNIX_EPOCH; use js_int::uint;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::{event_id, room_alias_id, room_id, user_id}; use ruma_identifiers::{event_id, room_alias_id, room_id, user_id};
use serde_json::{from_value as from_json_value, json, Value as JsonValue}; use serde_json::{from_value as from_json_value, json, Value as JsonValue};
@ -201,7 +201,7 @@ fn message_event_serialization() {
let event = MessageEvent { let event = MessageEvent {
content: MessageEventContent::text_plain("test"), content: MessageEventContent::text_plain("test"),
event_id: event_id!("$1234:example.com"), event_id: event_id!("$1234:example.com"),
origin_server_ts: UNIX_EPOCH, origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(0)),
room_id: room_id!("!roomid:example.com"), room_id: room_id!("!roomid:example.com"),
sender: user_id!("@test:example.com"), sender: user_id!("@test:example.com"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),

View File

@ -1,8 +1,7 @@
use std::time::{Duration, UNIX_EPOCH}; use js_int::uint;
use maplit::btreemap; use maplit::btreemap;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::receipt::ReceiptType; use ruma_common::{receipt::ReceiptType, MilliSecondsSinceUnixEpoch};
use ruma_identifiers::{event_id, room_id, user_id}; use ruma_identifiers::{event_id, room_id, user_id};
use ruma_serde::Raw; use ruma_serde::Raw;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -66,7 +65,7 @@ fn ephemeral_serialize_receipt() {
content: AnyEphemeralRoomEventContent::Receipt(ReceiptEventContent(btreemap! { content: AnyEphemeralRoomEventContent::Receipt(ReceiptEventContent(btreemap! {
event_id => btreemap! { event_id => btreemap! {
ReceiptType::Read => btreemap! { ReceiptType::Read => btreemap! {
user_id => Receipt { ts: Some(UNIX_EPOCH + Duration::from_millis(1)) }, user_id => Receipt { ts: Some(MilliSecondsSinceUnixEpoch(uint!(1))) },
}, },
}, },
})), })),
@ -121,6 +120,6 @@ fn deserialize_ephemeral_receipt() {
.map(|r| r.get(&ReceiptType::Read).unwrap().get(&user_id).unwrap()) .map(|r| r.get(&ReceiptType::Read).unwrap().get(&user_id).unwrap())
.map(|r| r.ts) .map(|r| r.ts)
.unwrap() .unwrap()
== Some(UNIX_EPOCH + Duration::from_millis(1)) == Some(MilliSecondsSinceUnixEpoch(uint!(1)))
); );
} }

View File

@ -1,8 +1,7 @@
use std::time::{Duration, UNIX_EPOCH};
use assign::assign; use assign::assign;
use js_int::UInt; use js_int::{uint, UInt};
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::{event_id, mxc_uri, room_id, user_id}; use ruma_identifiers::{event_id, mxc_uri, room_id, user_id};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -60,7 +59,7 @@ fn deserialize_message_event() {
unsigned, unsigned,
}) if sdp == "Hello" && call_id == "foofoo" && version == UInt::new(1).unwrap() }) if sdp == "Hello" && call_id == "foofoo" && version == UInt::new(1).unwrap()
&& event_id == event_id!("$h29iv0s8:example.com") && event_id == event_id!("$h29iv0s8:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& room_id == room_id!("!roomid:room.com") && room_id == room_id!("!roomid:room.com")
&& sender == user_id!("@carl:example.com") && sender == user_id!("@carl:example.com")
&& unsigned.is_empty() && unsigned.is_empty()
@ -88,7 +87,7 @@ fn serialize_message_event() {
mxc_uri!("mxc://matrix.org/arsrns98rsRSR"), mxc_uri!("mxc://matrix.org/arsrns98rsRSR"),
), ),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
room_id: room_id!("!roomid:room.com"), room_id: room_id!("!roomid:room.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),

View File

@ -1,8 +1,7 @@
use std::time::{Duration, UNIX_EPOCH};
use assign::assign; use assign::assign;
use js_int::{uint, UInt}; use js_int::{uint, UInt};
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
call::{answer::AnswerEventContent, SessionDescription, SessionDescriptionType}, call::{answer::AnswerEventContent, SessionDescription, SessionDescriptionType},
room::{ImageInfo, ThumbnailInfo}, room::{ImageInfo, ThumbnailInfo},
@ -34,7 +33,7 @@ fn message_serialize_sticker() {
mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs"), mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs"),
)), )),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
room_id: room_id!("!roomid:room.com"), room_id: room_id!("!roomid:room.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),
@ -139,7 +138,7 @@ fn deserialize_message_call_answer() {
unsigned, unsigned,
} if sdp == "Hello" && call_id == "foofoo" && version == UInt::new(1).unwrap() } if sdp == "Hello" && call_id == "foofoo" && version == UInt::new(1).unwrap()
&& event_id == event_id!("$h29iv0s8:example.com") && event_id == event_id!("$h29iv0s8:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& room_id == room_id!("!roomid:room.com") && room_id == room_id!("!roomid:room.com")
&& sender == user_id!("@carl:example.com") && sender == user_id!("@carl:example.com")
&& unsigned.is_empty() && unsigned.is_empty()
@ -203,7 +202,7 @@ fn deserialize_message_sticker() {
unsigned unsigned
} if event_id == event_id!("$h29iv0s8:example.com") } if event_id == event_id!("$h29iv0s8:example.com")
&& body == "Hello" && body == "Hello"
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& room_id == room_id!("!roomid:room.com") && room_id == room_id!("!roomid:room.com")
&& sender == user_id!("@carl:example.com") && sender == user_id!("@carl:example.com")
&& height == UInt::new(423) && height == UInt::new(423)
@ -279,7 +278,7 @@ fn deserialize_message_then_convert_to_full() {
&& call_id == "foofoo" && call_id == "foofoo"
&& version == uint!(1) && version == uint!(1)
&& event_id == "$h29iv0s8:example.com" && event_id == "$h29iv0s8:example.com"
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& room_id == "!roomid:room.com" && room_id == "!roomid:room.com"
&& sender == "@carl:example.com" && sender == "@carl:example.com"
&& unsigned.is_empty() && unsigned.is_empty()

View File

@ -1,10 +1,8 @@
#![cfg(not(feature = "unstable-pre-spec"))] #![cfg(not(feature = "unstable-pre-spec"))]
use std::{ use std::{collections::BTreeMap, convert::TryInto};
collections::BTreeMap,
time::{Duration, SystemTime},
};
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
pdu::{EventHash, Pdu, RoomV1Pdu, RoomV3Pdu}, pdu::{EventHash, Pdu, RoomV1Pdu, RoomV3Pdu},
EventType, EventType,
@ -30,7 +28,7 @@ fn serialize_pdu_as_v1() {
event_id: event_id!("$somejoinevent:matrix.org"), event_id: event_id!("$somejoinevent:matrix.org"),
sender: user_id!("@sender:example.com"), sender: user_id!("@sender:example.com"),
origin: "matrix.org".into(), origin: "matrix.org".into(),
origin_server_ts: SystemTime::UNIX_EPOCH + Duration::from_millis(1_592_050_773_658), origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()),
kind: EventType::RoomPowerLevels, kind: EventType::RoomPowerLevels,
content: json!({"testing": 123}), content: json!({"testing": 123}),
state_key: Some("state".into()), state_key: Some("state".into()),
@ -96,7 +94,7 @@ fn serialize_pdu_as_v3() {
room_id: room_id!("!n8f893n9:example.com"), room_id: room_id!("!n8f893n9:example.com"),
sender: user_id!("@sender:example.com"), sender: user_id!("@sender:example.com"),
origin: "matrix.org".into(), origin: "matrix.org".into(),
origin_server_ts: SystemTime::UNIX_EPOCH + Duration::from_millis(1_592_050_773_658), origin_server_ts: MilliSecondsSinceUnixEpoch(1_592_050_773_658_u64.try_into().unwrap()),
kind: EventType::RoomPowerLevels, kind: EventType::RoomPowerLevels,
content: json!({"testing": 123}), content: json!({"testing": 123}),
state_key: Some("state".into()), state_key: Some("state".into()),

View File

@ -1,6 +1,6 @@
use std::time::{Duration, UNIX_EPOCH}; use js_int::uint;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
custom::RedactedCustomEventContent, custom::RedactedCustomEventContent,
room::{ room::{
@ -27,7 +27,7 @@ fn sync_unsigned() -> RedactedSyncUnsigned {
content: RedactionEventContent { reason: Some("redacted because".into()) }, content: RedactionEventContent { reason: Some("redacted because".into()) },
redacts: event_id!("$h29iv0s8:example.com"), redacts: event_id!("$h29iv0s8:example.com"),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),
})); }));
@ -42,7 +42,7 @@ fn full_unsigned() -> RedactedUnsigned {
room_id: room_id!("!roomid:room.com"), room_id: room_id!("!roomid:room.com"),
redacts: event_id!("$h29iv0s8:example.com"), redacts: event_id!("$h29iv0s8:example.com"),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),
})); }));
@ -55,7 +55,7 @@ fn redacted_message_event_serialize() {
let redacted = RedactedSyncMessageEvent { let redacted = RedactedSyncMessageEvent {
content: RedactedMessageEventContent, content: RedactedMessageEventContent,
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: RedactedSyncUnsigned::default(), unsigned: RedactedSyncUnsigned::default(),
}; };
@ -77,7 +77,7 @@ fn redacted_aliases_event_serialize_no_content() {
content: RedactedAliasesEventContent { aliases: None }, content: RedactedAliasesEventContent { aliases: None },
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
state_key: "".into(), state_key: "".into(),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: RedactedSyncUnsigned::default(), unsigned: RedactedSyncUnsigned::default(),
}; };
@ -100,7 +100,7 @@ fn redacted_aliases_event_serialize_with_content() {
content: RedactedAliasesEventContent { aliases: Some(vec![]) }, content: RedactedAliasesEventContent { aliases: Some(vec![]) },
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
state_key: "".to_owned(), state_key: "".to_owned(),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: RedactedSyncUnsigned::default(), unsigned: RedactedSyncUnsigned::default(),
}; };
@ -189,7 +189,7 @@ fn redacted_deserialize_any_room_sync() {
content: RedactionEventContent { reason: Some("redacted because".into()) }, content: RedactionEventContent { reason: Some("redacted because".into()) },
redacts: event_id!("$h29iv0s8:example.com"), redacts: event_id!("$h29iv0s8:example.com"),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
room_id: room_id!("!roomid:room.com"), room_id: room_id!("!roomid:room.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),
@ -301,7 +301,7 @@ fn redacted_custom_event_deserialize() {
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
state_key: "hello there".into(), state_key: "hello there".into(),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
unsigned: unsigned.clone(), unsigned: unsigned.clone(),
}; };
@ -337,7 +337,7 @@ fn redact_method_properly_redacts() {
content: RedactionEventContent { reason: Some("redacted because".into()) }, content: RedactionEventContent { reason: Some("redacted because".into()) },
redacts: event_id!("$143273582443PhrSn:example.com"), redacts: event_id!("$143273582443PhrSn:example.com"),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
room_id: room_id!("!roomid:room.com"), room_id: room_id!("!roomid:room.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),
@ -358,6 +358,6 @@ fn redact_method_properly_redacts() {
&& unsigned.redacted_because.is_some() && unsigned.redacted_because.is_some()
&& room_id == room_id!("!roomid:room.com") && room_id == room_id!("!roomid:room.com")
&& sender == user_id!("@user:example.com") && sender == user_id!("@user:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
); );
} }

View File

@ -1,6 +1,6 @@
use std::time::{Duration, UNIX_EPOCH}; use js_int::uint;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
room::redaction::{RedactionEvent, RedactionEventContent}, room::redaction::{RedactionEvent, RedactionEventContent},
AnyMessageEvent, Unsigned, AnyMessageEvent, Unsigned,
@ -31,7 +31,7 @@ fn serialize_redaction() {
content: RedactionEventContent { reason: Some("being a turd".into()) }, content: RedactionEventContent { reason: Some("being a turd".into()) },
redacts: event_id!("$nomore:example.com"), redacts: event_id!("$nomore:example.com"),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
room_id: room_id!("!roomid:room.com"), room_id: room_id!("!roomid:room.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),
@ -63,7 +63,7 @@ fn deserialize_redaction() {
}) if reas == "being a turd" }) if reas == "being a turd"
&& event_id == event_id!("$h29iv0s8:example.com") && event_id == event_id!("$h29iv0s8:example.com")
&& redacts == event_id!("$nomore:example.com") && redacts == event_id!("$nomore:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& room_id == room_id!("!roomid:room.com") && room_id == room_id!("!roomid:room.com")
&& sender == user_id!("@carl:example.com") && sender == user_id!("@carl:example.com")
&& unsigned.is_empty() && unsigned.is_empty()

View File

@ -1,7 +1,7 @@
use std::time::{Duration, UNIX_EPOCH};
use assign::assign; use assign::assign;
use js_int::uint;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch;
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
use ruma_events::{ use ruma_events::{
key::verification::VerificationMethod, room::message::KeyVerificationRequestEventContent, key::verification::VerificationMethod, room::message::KeyVerificationRequestEventContent,
@ -44,7 +44,7 @@ fn serialization() {
file: None, file: None,
})), })),
event_id: event_id!("$143273582443PhrSn:example.org"), event_id: event_id!("$143273582443PhrSn:example.org"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(10_000), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(10_000)),
room_id: room_id!("!testroomid:example.org"), room_id: room_id!("!testroomid:example.org"),
sender: user_id!("@user:example.org"), sender: user_id!("@user:example.org"),
unsigned: Unsigned::default(), unsigned: Unsigned::default(),

View File

@ -1,7 +1,6 @@
use std::time::{Duration, UNIX_EPOCH}; use js_int::{uint, UInt};
use js_int::UInt;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
room::{ room::{
aliases::AliasesEventContent, aliases::AliasesEventContent,
@ -41,7 +40,7 @@ fn serialize_aliases_with_prev_content() {
"#somewhere:localhost" "#somewhere:localhost"
)])), )])),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
prev_content: Some(AnyStateEventContent::RoomAliases(AliasesEventContent::new(vec![ prev_content: Some(AnyStateEventContent::RoomAliases(AliasesEventContent::new(vec![
room_alias_id!("#inner:localhost"), room_alias_id!("#inner:localhost"),
]))), ]))),
@ -64,7 +63,7 @@ fn serialize_aliases_without_prev_content() {
"#somewhere:localhost" "#somewhere:localhost"
)])), )])),
event_id: event_id!("$h29iv0s8:example.com"), event_id: event_id!("$h29iv0s8:example.com"),
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
prev_content: None, prev_content: None,
room_id: room_id!("!roomid:room.com"), room_id: room_id!("!roomid:room.com"),
sender: user_id!("@carl:example.com"), sender: user_id!("@carl:example.com"),
@ -124,7 +123,7 @@ fn deserialize_aliases_with_prev_content() {
unsigned, unsigned,
} if content.aliases == vec![room_alias_id!("#somewhere:localhost")] } if content.aliases == vec![room_alias_id!("#somewhere:localhost")]
&& event_id == event_id!("$h29iv0s8:example.com") && event_id == event_id!("$h29iv0s8:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& prev_content.aliases == vec![room_alias_id!("#inner:localhost")] && prev_content.aliases == vec![room_alias_id!("#inner:localhost")]
&& room_id == room_id!("!roomid:room.com") && room_id == room_id!("!roomid:room.com")
&& sender == user_id!("@carl:example.com") && sender == user_id!("@carl:example.com")
@ -151,7 +150,7 @@ fn deserialize_aliases_sync_with_room_id() {
unsigned, unsigned,
} if content.aliases == vec![room_alias_id!("#somewhere:localhost")] } if content.aliases == vec![room_alias_id!("#somewhere:localhost")]
&& event_id == event_id!("$h29iv0s8:example.com") && event_id == event_id!("$h29iv0s8:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& prev_content.aliases == vec![room_alias_id!("#inner:localhost")] && prev_content.aliases == vec![room_alias_id!("#inner:localhost")]
&& sender == user_id!("@carl:example.com") && sender == user_id!("@carl:example.com")
&& state_key.is_empty() && state_key.is_empty()
@ -210,7 +209,7 @@ fn deserialize_avatar_without_prev_content() {
state_key, state_key,
unsigned unsigned
} if event_id == event_id!("$h29iv0s8:example.com") } if event_id == event_id!("$h29iv0s8:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& room_id == room_id!("!roomid:room.com") && room_id == room_id!("!roomid:room.com")
&& sender == user_id!("@carl:example.com") && sender == user_id!("@carl:example.com")
&& state_key.is_empty() && state_key.is_empty()
@ -287,7 +286,7 @@ fn deserialize_member_event_with_top_level_membership_field() {
.. ..
} }
)) if event_id == event_id!("$h29iv0s8:example.com") )) if event_id == event_id!("$h29iv0s8:example.com")
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& sender == user_id!("@example:localhost") && sender == user_id!("@example:localhost")
&& content.displayname == Some("example".into()) && content.displayname == Some("example".into())
); );
@ -318,7 +317,7 @@ fn deserialize_full_event_convert_to_sync() {
unsigned, unsigned,
}) if content.aliases == vec![room_alias_id!("#somewhere:localhost")] }) if content.aliases == vec![room_alias_id!("#somewhere:localhost")]
&& event_id == "$h29iv0s8:example.com" && event_id == "$h29iv0s8:example.com"
&& origin_server_ts == UNIX_EPOCH + Duration::from_millis(1) && origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
&& prev_content.aliases == vec![room_alias_id!("#inner:localhost")] && prev_content.aliases == vec![room_alias_id!("#inner:localhost")]
&& sender == "@carl:example.com" && sender == "@carl:example.com"
&& state_key.is_empty() && state_key.is_empty()

View File

@ -1,9 +1,8 @@
//! [GET /_matrix/federation/v1/backfill/{roomId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-backfill-roomid) //! [GET /_matrix/federation/v1/backfill/{roomId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-backfill-roomid)
use std::time::SystemTime;
use js_int::UInt; use js_int::UInt;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::pdu::Pdu; use ruma_events::pdu::Pdu;
use ruma_identifiers::{EventId, RoomId, ServerNameBox}; use ruma_identifiers::{EventId, RoomId, ServerNameBox};
use ruma_serde::Raw; use ruma_serde::Raw;
@ -37,8 +36,7 @@ ruma_api! {
pub origin: ServerNameBox, pub origin: ServerNameBox,
/// POSIX timestamp in milliseconds on originating homeserver when this transaction started. /// POSIX timestamp in milliseconds on originating homeserver when this transaction started.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub origin_server_ts: MilliSecondsSinceUnixEpoch,
pub origin_server_ts: SystemTime,
/// List of persistent updates to rooms. /// List of persistent updates to rooms.
pub pdus: Vec<Raw<Pdu>>, pub pdus: Vec<Raw<Pdu>>,
@ -60,7 +58,11 @@ impl Response {
/// * the `server_name` of the homeserver. /// * the `server_name` of the homeserver.
/// * the timestamp in milliseconds of when this transaction started. /// * the timestamp in milliseconds of when this transaction started.
/// * the list of persistent updates to rooms. /// * the list of persistent updates to rooms.
pub fn new(origin: ServerNameBox, origin_server_ts: SystemTime, pdus: Vec<Raw<Pdu>>) -> Self { pub fn new(
origin: ServerNameBox,
origin_server_ts: MilliSecondsSinceUnixEpoch,
pdus: Vec<Raw<Pdu>>,
) -> Self {
Self { origin, origin_server_ts, pdus } Self { origin, origin_server_ts, pdus }
} }
} }

View File

@ -1,7 +1,8 @@
//! Server discovery endpoints. //! Server discovery endpoints.
use std::{collections::BTreeMap, time::SystemTime}; use std::collections::BTreeMap;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::{ServerNameBox, ServerSigningKeyId}; use ruma_identifiers::{ServerNameBox, ServerSigningKeyId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -31,8 +32,7 @@ impl VerifyKey {
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct OldVerifyKey { pub struct OldVerifyKey {
/// Timestamp when this key expired. /// Timestamp when this key expired.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub expired_ts: MilliSecondsSinceUnixEpoch,
pub expired_ts: SystemTime,
/// The Unpadded Base64 encoded key. /// The Unpadded Base64 encoded key.
pub key: String, pub key: String,
@ -40,7 +40,7 @@ pub struct OldVerifyKey {
impl OldVerifyKey { impl OldVerifyKey {
/// Creates a new `OldVerifyKey` with the given expiry time and key. /// Creates a new `OldVerifyKey` with the given expiry time and key.
pub fn new(expired_ts: SystemTime, key: String) -> Self { pub fn new(expired_ts: MilliSecondsSinceUnixEpoch, key: String) -> Self {
Self { expired_ts, key } Self { expired_ts, key }
} }
} }
@ -65,15 +65,14 @@ pub struct ServerSigningKeys {
/// Timestamp when the keys should be refreshed. This field MUST be ignored in room /// Timestamp when the keys should be refreshed. This field MUST be ignored in room
/// versions 1, 2, 3, and 4. /// versions 1, 2, 3, and 4.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub valid_until_ts: MilliSecondsSinceUnixEpoch,
pub valid_until_ts: SystemTime,
} }
impl ServerSigningKeys { impl ServerSigningKeys {
/// Creates a new `ServerSigningKeys` with the given server name and validity timestamp. /// Creates a new `ServerSigningKeys` with the given server name and validity timestamp.
/// ///
/// All other fields will be empty. /// All other fields will be empty.
pub fn new(server_name: ServerNameBox, valid_until_ts: SystemTime) -> Self { pub fn new(server_name: ServerNameBox, valid_until_ts: MilliSecondsSinceUnixEpoch) -> Self {
Self { Self {
server_name, server_name,
verify_keys: BTreeMap::new(), verify_keys: BTreeMap::new(),

View File

@ -1,8 +1,7 @@
//! [GET /_matrix/key/v2/query/{serverName}/{keyId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-key-v2-query-servername-keyid) //! [GET /_matrix/key/v2/query/{serverName}/{keyId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-key-v2-query-servername-keyid)
use std::time::SystemTime;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::ServerName; use ruma_identifiers::ServerName;
use crate::discovery::ServerSigningKeys; use crate::discovery::ServerSigningKeys;
@ -29,8 +28,8 @@ ruma_api! {
/// ///
/// If not supplied, the current time as determined by the receiving server is used. /// If not supplied, the current time as determined by the receiving server is used.
#[ruma_api(query)] #[ruma_api(query)]
#[serde(default = "SystemTime::now", with = "ruma_serde::time::ms_since_unix_epoch")] #[serde(default = "MilliSecondsSinceUnixEpoch::now")]
pub minimum_valid_until_ts: SystemTime, pub minimum_valid_until_ts: MilliSecondsSinceUnixEpoch,
} }
response: { response: {
@ -41,7 +40,10 @@ ruma_api! {
impl<'a> Request<'a> { impl<'a> Request<'a> {
/// Creates a new `Request` with the given server name and `minimum_valid_until` timestamp. /// Creates a new `Request` with the given server name and `minimum_valid_until` timestamp.
pub fn new(server_name: &'a ServerName, minimum_valid_until_ts: SystemTime) -> Self { pub fn new(
server_name: &'a ServerName,
minimum_valid_until_ts: MilliSecondsSinceUnixEpoch,
) -> Self {
Self { server_name, minimum_valid_until_ts } Self { server_name, minimum_valid_until_ts }
} }
} }

View File

@ -1,8 +1,9 @@
//! [POST /_matrix/key/v2/query](https://matrix.org/docs/spec/server_server/r0.1.4#post-matrix-key-v2-query) //! [POST /_matrix/key/v2/query](https://matrix.org/docs/spec/server_server/r0.1.4#post-matrix-key-v2-query)
use std::{collections::BTreeMap, time::SystemTime}; use std::collections::BTreeMap;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_identifiers::{ServerNameBox, ServerSigningKeyId}; use ruma_identifiers::{ServerNameBox, ServerSigningKeyId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -38,8 +39,7 @@ ruma_api! {
/// If not supplied, the current time as determined by the notary server /// If not supplied, the current time as determined by the notary server
/// is used. /// is used.
#[ruma_api(query)] #[ruma_api(query)]
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub minimum_valid_until_ts: MilliSecondsSinceUnixEpoch,
pub minimum_valid_until_ts: SystemTime,
} }
response: { response: {
@ -52,7 +52,7 @@ impl Request {
/// Creates a new `Request` with the given query criteria and `minimum_valid_until` timestamp. /// Creates a new `Request` with the given query criteria and `minimum_valid_until` timestamp.
pub fn new( pub fn new(
server_keys: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, QueryCriteria>>, server_keys: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, QueryCriteria>>,
minimum_valid_until_ts: SystemTime, minimum_valid_until_ts: MilliSecondsSinceUnixEpoch,
) -> Self { ) -> Self {
Self { server_keys, minimum_valid_until_ts } Self { server_keys, minimum_valid_until_ts }
} }
@ -75,12 +75,8 @@ pub struct QueryCriteria {
/// ///
/// If not supplied, the current time as determined by the notary server is /// If not supplied, the current time as determined by the notary server is
/// used. /// used.
#[serde( #[serde(skip_serializing_if = "Option::is_none")]
default, pub minimum_valid_until_ts: Option<MilliSecondsSinceUnixEpoch>,
skip_serializing_if = "Option::is_none",
with = "ruma_serde::time::opt_ms_since_unix_epoch"
)]
pub minimum_valid_until_ts: Option<SystemTime>,
} }
impl QueryCriteria { impl QueryCriteria {

View File

@ -1,8 +1,7 @@
//! [GET /_matrix/federation/v1/event/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-event-eventid) //! [GET /_matrix/federation/v1/event/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-event-eventid)
use std::time::SystemTime;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::pdu::Pdu; use ruma_events::pdu::Pdu;
use ruma_identifiers::{EventId, ServerNameBox}; use ruma_identifiers::{EventId, ServerNameBox};
use ruma_serde::Raw; use ruma_serde::Raw;
@ -28,8 +27,7 @@ ruma_api! {
pub origin: ServerNameBox, pub origin: ServerNameBox,
/// Time on originating homeserver when this transaction started. /// Time on originating homeserver when this transaction started.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub origin_server_ts: MilliSecondsSinceUnixEpoch,
pub origin_server_ts: SystemTime,
/// The event. /// The event.
#[serde(rename = "pdus", with = "ruma_serde::single_element_seq")] #[serde(rename = "pdus", with = "ruma_serde::single_element_seq")]
@ -46,7 +44,11 @@ impl<'a> Request<'a> {
impl Response { impl Response {
/// Creates a new `Response` with the given server name, timestamp, and event. /// Creates a new `Response` with the given server name, timestamp, and event.
pub fn new(origin: ServerNameBox, origin_server_ts: SystemTime, pdu: Raw<Pdu>) -> Self { pub fn new(
origin: ServerNameBox,
origin_server_ts: MilliSecondsSinceUnixEpoch,
pdu: Raw<Pdu>,
) -> Self {
Self { origin, origin_server_ts, pdu } Self { origin, origin_server_ts, pdu }
} }
} }

View File

@ -1,8 +1,7 @@
//! [PUT /_matrix/federation/v1/invite/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v1-invite-roomid-eventid) //! [PUT /_matrix/federation/v1/invite/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v1-invite-roomid-eventid)
use std::time::SystemTime;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{pdu::Pdu, room::member::MemberEventContent, AnyStrippedStateEvent, EventType}; use ruma_events::{pdu::Pdu, room::member::MemberEventContent, AnyStrippedStateEvent, EventType};
use ruma_identifiers::{EventId, RoomId, ServerName, UserId}; use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
use ruma_serde::Raw; use ruma_serde::Raw;
@ -34,8 +33,7 @@ ruma_api! {
pub origin: &'a ServerName, pub origin: &'a ServerName,
/// A timestamp added by the inviting homeserver. /// A timestamp added by the inviting homeserver.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub origin_server_ts: MilliSecondsSinceUnixEpoch,
pub origin_server_ts: SystemTime,
/// The value `m.room.member`. /// The value `m.room.member`.
#[serde(rename = "type")] #[serde(rename = "type")]
@ -98,7 +96,7 @@ pub struct RequestInit<'a> {
pub origin: &'a ServerName, pub origin: &'a ServerName,
/// A timestamp added by the inviting homeserver. /// A timestamp added by the inviting homeserver.
pub origin_server_ts: SystemTime, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// The user ID of the invited member. /// The user ID of the invited member.
pub state_key: &'a UserId, pub state_key: &'a UserId,

View File

@ -1,9 +1,8 @@
//! [PUT /_matrix/federation/v1/send_leave/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v1-send-leave-roomid-eventid) //! [PUT /_matrix/federation/v1/send_leave/{roomId}/{eventId}](https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v1-send-leave-roomid-eventid)
use std::time::SystemTime;
use js_int::UInt; use js_int::UInt;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{room::member::MemberEventContent, EventType}; use ruma_events::{room::member::MemberEventContent, EventType};
use ruma_identifiers::{EventId, RoomId, ServerName, UserId}; use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
use ruma_serde::Raw; use ruma_serde::Raw;
@ -38,8 +37,7 @@ ruma_api! {
/// A timestamp added by the leaving homeserver. /// A timestamp added by the leaving homeserver.
#[ruma_api(query)] #[ruma_api(query)]
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub origin_server_ts: MilliSecondsSinceUnixEpoch,
pub origin_server_ts: SystemTime,
/// The value `m.room.member`. /// The value `m.room.member`.
#[ruma_api(query)] #[ruma_api(query)]
@ -87,7 +85,7 @@ impl<'a> Request<'a> {
event_id: &'a EventId, event_id: &'a EventId,
sender: &'a UserId, sender: &'a UserId,
origin: &'a ServerName, origin: &'a ServerName,
origin_server_ts: SystemTime, origin_server_ts: MilliSecondsSinceUnixEpoch,
event_type: EventType, event_type: EventType,
state_key: &'a str, state_key: &'a str,
content: Raw<MemberEventContent>, content: Raw<MemberEventContent>,

View File

@ -1,8 +1,9 @@
//! [PUT /_matrix/federation/v1/send/{txnId}](https://matrix.org/docs/spec/server_server/r0.1.3#put-matrix-federation-v1-send-txnid) //! [PUT /_matrix/federation/v1/send/{txnId}](https://matrix.org/docs/spec/server_server/r0.1.3#put-matrix-federation-v1-send-txnid)
use std::{collections::BTreeMap, time::SystemTime}; use std::collections::BTreeMap;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::pdu::Pdu; use ruma_events::pdu::Pdu;
use ruma_identifiers::{EventId, ServerName}; use ruma_identifiers::{EventId, ServerName};
use ruma_serde::Raw; use ruma_serde::Raw;
@ -29,8 +30,7 @@ ruma_api! {
/// POSIX timestamp in milliseconds on the originating homeserver when this transaction /// POSIX timestamp in milliseconds on the originating homeserver when this transaction
/// started. /// started.
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub origin_server_ts: MilliSecondsSinceUnixEpoch,
pub origin_server_ts: SystemTime,
/// List of persistent updates to rooms. /// List of persistent updates to rooms.
/// ///
@ -60,7 +60,7 @@ impl<'a> Request<'a> {
pub fn new( pub fn new(
transaction_id: &'a str, transaction_id: &'a str,
origin: &'a ServerName, origin: &'a ServerName,
origin_server_ts: SystemTime, origin_server_ts: MilliSecondsSinceUnixEpoch,
) -> Self { ) -> Self {
Self { transaction_id, origin, origin_server_ts, pdus: &[], edus: &[] } Self { transaction_id, origin, origin_server_ts, pdus: &[], edus: &[] }
} }

View File

@ -1,10 +1,11 @@
//! [POST /_matrix/push/v1/notify](https://matrix.org/docs/spec/push_gateway/r0.1.1#post-matrix-push-v1-notify) //! [POST /_matrix/push/v1/notify](https://matrix.org/docs/spec/push_gateway/r0.1.1#post-matrix-push-v1-notify)
use std::time::SystemTime;
use js_int::UInt; use js_int::UInt;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::push::{PusherData, Tweak}; use ruma_common::{
push::{PusherData, Tweak},
SecondsSinceUnixEpoch,
};
use ruma_events::EventType; use ruma_events::EventType;
use ruma_identifiers::{EventId, RoomAliasId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomAliasId, RoomId, UserId};
use ruma_serde::{Outgoing, StringEnum}; use ruma_serde::{Outgoing, StringEnum};
@ -192,11 +193,8 @@ pub struct Device {
pub pushkey: String, pub pushkey: String,
/// The unix timestamp (in seconds) when the pushkey was last updated. /// The unix timestamp (in seconds) when the pushkey was last updated.
#[serde( #[serde(skip_serializing_if = "Option::is_none")]
with = "ruma_serde::time::opt_s_since_unix_epoch", pub pushkey_ts: Option<SecondsSinceUnixEpoch>,
skip_serializing_if = "Option::is_none"
)]
pub pushkey_ts: Option<SystemTime>,
/// A dictionary of additional pusher-specific data. For 'http' pushers, /// A dictionary of additional pusher-specific data. For 'http' pushers,
/// this is the data dictionary passed in at pusher creation minus the `url` /// this is the data dictionary passed in at pusher creation minus the `url`
@ -292,9 +290,8 @@ mod tweak_serde {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::time::{Duration, SystemTime};
use js_int::uint; use js_int::uint;
use ruma_common::SecondsSinceUnixEpoch;
use ruma_events::EventType; use ruma_events::EventType;
use ruma_identifiers::{event_id, room_alias_id, room_id, user_id}; use ruma_identifiers::{event_id, room_alias_id, room_id, user_id};
use serde_json::{ use serde_json::{
@ -339,7 +336,7 @@ mod tests {
let count = NotificationCounts { unread: uint!(2), ..NotificationCounts::default() }; let count = NotificationCounts { unread: uint!(2), ..NotificationCounts::default() };
let device = Device { let device = Device {
pushkey_ts: Some(SystemTime::UNIX_EPOCH + Duration::from_secs(123)), pushkey_ts: Some(SecondsSinceUnixEpoch(uint!(123))),
tweaks: vec![ tweaks: vec![
Tweak::Highlight(true), Tweak::Highlight(true),
Tweak::Sound("silence".into()), Tweak::Sound("silence".into()),

View File

@ -18,6 +18,7 @@ unstable-pre-spec = ["ruma-events/unstable-pre-spec"]
itertools = "0.10.0" itertools = "0.10.0"
js_int = "0.2.0" js_int = "0.2.0"
maplit = "1.0.2" maplit = "1.0.2"
ruma-common = { version = "0.5.0", path = "../ruma-common" }
ruma-events = { version = "=0.22.0-alpha.3", path = "../ruma-events" } ruma-events = { version = "=0.22.0-alpha.3", path = "../ruma-events" }
ruma-identifiers = { version = "0.19.0", path = "../ruma-identifiers" } ruma-identifiers = { version = "0.19.0", path = "../ruma-identifiers" }
ruma-serde = { version = "0.3.1", path = "../ruma-serde" } ruma-serde = { version = "0.3.1", path = "../ruma-serde" }

View File

@ -6,15 +6,15 @@
// `cargo bench --bench <name of the bench> -- --save-baseline <name>`. // `cargo bench --bench <name of the bench> -- --save-baseline <name>`.
use std::{ use std::{
collections::{BTreeMap, BTreeSet}, collections::{BTreeMap, BTreeSet},
convert::TryFrom, convert::{TryFrom, TryInto},
sync::Arc, sync::Arc,
time::{Duration, UNIX_EPOCH},
}; };
use criterion::{criterion_group, criterion_main, Criterion}; use criterion::{criterion_group, criterion_main, Criterion};
use event::StateEvent; use event::StateEvent;
use js_int::uint; use js_int::uint;
use maplit::btreemap; use maplit::btreemap;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
pdu::{EventHash, Pdu, RoomV3Pdu}, pdu::{EventHash, Pdu, RoomV3Pdu},
room::{ room::{
@ -40,7 +40,7 @@ fn lexico_topo_sort(c: &mut Criterion) {
}; };
b.iter(|| { b.iter(|| {
let _ = StateResolution::lexicographical_topological_sort(&graph, |id| { let _ = StateResolution::lexicographical_topological_sort(&graph, |id| {
(0, UNIX_EPOCH, id.clone()) (0, MilliSecondsSinceUnixEpoch(uint!(0)), id.clone())
}); });
}) })
}); });
@ -376,7 +376,7 @@ where
rest: Pdu::RoomV3Pdu(RoomV3Pdu { rest: Pdu::RoomV3Pdu(RoomV3Pdu {
room_id: room_id(), room_id: room_id(),
sender, sender,
origin_server_ts: UNIX_EPOCH + Duration::from_secs(ts), origin_server_ts: MilliSecondsSinceUnixEpoch(ts.try_into().unwrap()),
state_key, state_key,
kind: ev_type, kind: ev_type,
content, content,
@ -522,9 +522,10 @@ fn BAN_STATE_SET() -> BTreeMap<EventId, Arc<StateEvent>> {
} }
pub mod event { pub mod event {
use std::{collections::BTreeMap, time::SystemTime}; use std::collections::BTreeMap;
use js_int::UInt; use js_int::UInt;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
pdu::{EventHash, Pdu}, pdu::{EventHash, Pdu},
room::member::MembershipState, room::member::MembershipState,
@ -559,7 +560,7 @@ pub mod event {
self.content() self.content()
} }
fn origin_server_ts(&self) -> SystemTime { fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch {
*self.origin_server_ts() *self.origin_server_ts()
} }
@ -656,7 +657,7 @@ pub mod event {
} }
} }
pub fn origin_server_ts(&self) -> &SystemTime { pub fn origin_server_ts(&self) -> &MilliSecondsSinceUnixEpoch {
match &self.rest { match &self.rest {
Pdu::RoomV1Pdu(ev) => &ev.origin_server_ts, Pdu::RoomV1Pdu(ev) => &ev.origin_server_ts,
Pdu::RoomV3Pdu(ev) => &ev.origin_server_ts, Pdu::RoomV3Pdu(ev) => &ev.origin_server_ts,

View File

@ -2,10 +2,10 @@ use std::{
cmp::Reverse, cmp::Reverse,
collections::{BTreeMap, BTreeSet, BinaryHeap}, collections::{BTreeMap, BTreeSet, BinaryHeap},
sync::Arc, sync::Arc,
time::SystemTime,
}; };
use maplit::btreeset; use maplit::btreeset;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
room::{ room::{
member::{MemberEventContent, MembershipState}, member::{MemberEventContent, MembershipState},
@ -288,7 +288,7 @@ impl StateResolution {
key_fn: F, key_fn: F,
) -> Vec<EventId> ) -> Vec<EventId>
where where
F: Fn(&EventId) -> (i64, SystemTime, EventId), F: Fn(&EventId) -> (i64, MilliSecondsSinceUnixEpoch, EventId),
{ {
info!("starting lexicographical topological sort"); info!("starting lexicographical topological sort");
// NOTE: an event that has no incoming edges happened most recently, // NOTE: an event that has no incoming edges happened most recently,

View File

@ -1,6 +1,7 @@
use std::{collections::BTreeMap, time::SystemTime}; use std::collections::BTreeMap;
use js_int::UInt; use js_int::UInt;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{pdu::EventHash, EventType}; use ruma_events::{pdu::EventHash, EventType};
use ruma_identifiers::{EventId, RoomId, ServerName, ServerSigningKeyId, UserId}; use ruma_identifiers::{EventId, RoomId, ServerName, ServerSigningKeyId, UserId};
use serde_json::value::Value as JsonValue; use serde_json::value::Value as JsonValue;
@ -17,7 +18,7 @@ pub trait Event {
fn sender(&self) -> &UserId; fn sender(&self) -> &UserId;
/// The time of creation on the originating server. /// The time of creation on the originating server.
fn origin_server_ts(&self) -> SystemTime; fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch;
/// The kind of event. /// The kind of event.
fn kind(&self) -> EventType; fn kind(&self) -> EventType;

View File

@ -1,6 +1,8 @@
use std::{sync::Arc, time::UNIX_EPOCH}; use std::sync::Arc;
use js_int::uint;
use maplit::btreemap; use maplit::btreemap;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{room::join_rules::JoinRule, EventType}; use ruma_events::{room::join_rules::JoinRule, EventType};
use ruma_identifiers::{EventId, RoomVersionId}; use ruma_identifiers::{EventId, RoomVersionId};
use ruma_state_res::{EventMap, StateMap, StateResolution}; use ruma_state_res::{EventMap, StateMap, StateResolution};
@ -276,8 +278,9 @@ fn test_lexicographical_sort() {
event_id("p") => vec![event_id("o")], event_id("p") => vec![event_id("o")],
}; };
let res = let res = StateResolution::lexicographical_topological_sort(&graph, |id| {
StateResolution::lexicographical_topological_sort(&graph, |id| (0, UNIX_EPOCH, id.clone())); (0, MilliSecondsSinceUnixEpoch(uint!(0)), id.clone())
});
assert_eq!( assert_eq!(
vec!["o", "l", "n", "m", "p"], vec!["o", "l", "n", "m", "p"],

View File

@ -2,13 +2,13 @@
use std::{ use std::{
collections::{BTreeMap, BTreeSet}, collections::{BTreeMap, BTreeSet},
convert::TryFrom, convert::{TryFrom, TryInto},
sync::{Arc, Once}, sync::{Arc, Once},
time::{Duration, UNIX_EPOCH},
}; };
use js_int::uint; use js_int::uint;
use maplit::btreemap; use maplit::btreemap;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
pdu::{EventHash, Pdu, RoomV3Pdu}, pdu::{EventHash, Pdu, RoomV3Pdu},
room::{ room::{
@ -77,9 +77,9 @@ pub fn do_check(
// resolve the current state and add it to the state_at_event map then continue // resolve the current state and add it to the state_at_event map then continue
// on in "time" // on in "time"
for node in for node in StateResolution::lexicographical_topological_sort(&graph, |id| {
StateResolution::lexicographical_topological_sort(&graph, |id| (0, UNIX_EPOCH, id.clone())) (0, MilliSecondsSinceUnixEpoch(uint!(0)), id.clone())
{ }) {
let fake_event = fake_event_map.get(&node).unwrap(); let fake_event = fake_event_map.get(&node).unwrap();
let event_id = fake_event.event_id().clone(); let event_id = fake_event.event_id().clone();
@ -340,7 +340,7 @@ pub fn to_init_pdu_event(
rest: Pdu::RoomV3Pdu(RoomV3Pdu { rest: Pdu::RoomV3Pdu(RoomV3Pdu {
room_id: room_id(), room_id: room_id(),
sender, sender,
origin_server_ts: UNIX_EPOCH + Duration::from_secs(ts), origin_server_ts: MilliSecondsSinceUnixEpoch(ts.try_into().unwrap()),
state_key, state_key,
kind: ev_type, kind: ev_type,
content, content,
@ -385,7 +385,7 @@ where
rest: Pdu::RoomV3Pdu(RoomV3Pdu { rest: Pdu::RoomV3Pdu(RoomV3Pdu {
room_id: room_id(), room_id: room_id(),
sender, sender,
origin_server_ts: UNIX_EPOCH + Duration::from_secs(ts), origin_server_ts: MilliSecondsSinceUnixEpoch(ts.try_into().unwrap()),
state_key, state_key,
kind: ev_type, kind: ev_type,
content, content,
@ -497,10 +497,11 @@ pub fn INITIAL_EDGES() -> Vec<EventId> {
} }
pub mod event { pub mod event {
use std::{collections::BTreeMap, time::SystemTime}; use std::collections::BTreeMap;
use js_int::UInt; use js_int::UInt;
use ruma_events::{ use ruma_events::{
exports::ruma_common::MilliSecondsSinceUnixEpoch,
pdu::{EventHash, Pdu}, pdu::{EventHash, Pdu},
room::member::{MemberEventContent, MembershipState}, room::member::{MemberEventContent, MembershipState},
EventType, EventType,
@ -532,7 +533,7 @@ pub mod event {
fn content(&self) -> serde_json::Value { fn content(&self) -> serde_json::Value {
self.content() self.content()
} }
fn origin_server_ts(&self) -> SystemTime { fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch {
*self.origin_server_ts() *self.origin_server_ts()
} }
@ -623,7 +624,7 @@ pub mod event {
Pdu::RoomV3Pdu(ev) => serde_json::from_value(ev.content.clone()), Pdu::RoomV3Pdu(ev) => serde_json::from_value(ev.content.clone()),
} }
} }
pub fn origin_server_ts(&self) -> &SystemTime { pub fn origin_server_ts(&self) -> &MilliSecondsSinceUnixEpoch {
match &self.rest { match &self.rest {
Pdu::RoomV1Pdu(ev) => &ev.origin_server_ts, Pdu::RoomV1Pdu(ev) => &ev.origin_server_ts,
Pdu::RoomV3Pdu(ev) => &ev.origin_server_ts, Pdu::RoomV3Pdu(ev) => &ev.origin_server_ts,