Change timestamp types from UInt to SystemTime
This commit is contained in:
parent
5768737cbe
commit
dc0a9f88ba
@ -14,8 +14,9 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
js_int = { version = "0.1.4", features = ["serde"] }
|
||||
ruma-identifiers = "0.15.1"
|
||||
ruma-events-macros = { path = "ruma-events-macros", version = "=0.3.0" }
|
||||
ruma-identifiers = "0.15.1"
|
||||
ruma-serde = "0.1.0"
|
||||
serde = { version = "1.0.106", features = ["derive"] }
|
||||
serde_json = "1.0.51"
|
||||
|
||||
|
@ -134,9 +134,8 @@ impl ToTokens for RumaEvent {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this event was
|
||||
/// sent.
|
||||
fn origin_server_ts(&self) -> js_int::UInt {
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
fn origin_server_ts(&self) -> std::time::SystemTime {
|
||||
self.origin_server_ts
|
||||
}
|
||||
|
||||
@ -284,9 +283,9 @@ fn populate_room_event_fields(content_name: Ident, fields: Vec<Field>) -> Vec<Fi
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: ruma_identifiers::EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: js_int::UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: std::time::SystemTime,
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
@ -1,6 +1,7 @@
|
||||
//! Types for the *m.key.verification.request* event.
|
||||
|
||||
use js_int::UInt;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ruma_events_macros::ruma_event;
|
||||
use ruma_identifiers::DeviceId;
|
||||
|
||||
@ -25,11 +26,12 @@ ruma_event! {
|
||||
/// The verification methods supported by the sender.
|
||||
pub methods: Vec<VerificationMethod>,
|
||||
|
||||
/// The POSIX timestamp in milliseconds for when the request was made.
|
||||
/// The time in milliseconds for when the request was made.
|
||||
///
|
||||
/// 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.
|
||||
pub timestamp: UInt,
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub timestamp: SystemTime,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
45
src/lib.rs
45
src/lib.rs
@ -118,9 +118,9 @@
|
||||
use std::{
|
||||
error::Error,
|
||||
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{
|
||||
de::{MapAccess, Visitor},
|
||||
@ -381,9 +381,8 @@ pub trait RoomEvent: Event {
|
||||
/// The unique identifier for the event.
|
||||
fn event_id(&self) -> &EventId;
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this event was
|
||||
/// sent.
|
||||
fn origin_server_ts(&self) -> UInt;
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
fn origin_server_ts(&self) -> SystemTime;
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
///
|
||||
@ -458,6 +457,8 @@ mod custom {
|
||||
}
|
||||
|
||||
mod custom_room {
|
||||
use std::time::SystemTime;
|
||||
|
||||
use super::{Event, EventType, RoomEvent};
|
||||
|
||||
use ruma_events_macros::FromRaw;
|
||||
@ -474,9 +475,9 @@ mod custom_room {
|
||||
/// The custom type of the event.
|
||||
#[serde(rename = "type")]
|
||||
pub event_type: String,
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: js_int::UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
/// The unique identifier for the room associated with this event.
|
||||
pub room_id: Option<ruma_identifiers::RoomId>,
|
||||
/// The unique identifier for the user who sent this event.
|
||||
@ -507,9 +508,8 @@ mod custom_room {
|
||||
fn event_id(&self) -> &ruma_identifiers::EventId {
|
||||
&self.event_id
|
||||
}
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this event was
|
||||
/// sent.
|
||||
fn origin_server_ts(&self) -> js_int::UInt {
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
fn origin_server_ts(&self) -> SystemTime {
|
||||
self.origin_server_ts
|
||||
}
|
||||
/// The unique identifier for the room associated with this event.
|
||||
@ -542,9 +542,9 @@ mod custom_room {
|
||||
/// The custom type of the event.
|
||||
#[serde(rename = "type")]
|
||||
pub event_type: String,
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: js_int::UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
/// The unique identifier for the room associated with this event.
|
||||
pub room_id: Option<ruma_identifiers::RoomId>,
|
||||
/// The unique identifier for the user who sent this event.
|
||||
@ -557,6 +557,8 @@ mod custom_room {
|
||||
}
|
||||
|
||||
mod custom_state {
|
||||
use std::time::SystemTime;
|
||||
|
||||
use super::{Event, EventType, RoomEvent, StateEvent};
|
||||
|
||||
use ruma_events_macros::FromRaw;
|
||||
@ -573,9 +575,9 @@ mod custom_state {
|
||||
/// The custom type of the event.
|
||||
#[serde(rename = "type")]
|
||||
pub event_type: String,
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: js_int::UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
/// The previous content for this state key, if any.
|
||||
pub prev_content: Option<CustomStateEventContent>,
|
||||
/// The unique identifier for the room associated with this event.
|
||||
@ -610,9 +612,8 @@ mod custom_state {
|
||||
fn event_id(&self) -> &ruma_identifiers::EventId {
|
||||
&self.event_id
|
||||
}
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this event was
|
||||
/// sent.
|
||||
fn origin_server_ts(&self) -> js_int::UInt {
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
fn origin_server_ts(&self) -> SystemTime {
|
||||
self.origin_server_ts
|
||||
}
|
||||
/// The unique identifier for the room associated with this event.
|
||||
@ -656,9 +657,9 @@ mod custom_state {
|
||||
/// The custom type of the event.
|
||||
#[serde(rename = "type")]
|
||||
pub event_type: String,
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: js_int::UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
/// The previous content for this state key, if any.
|
||||
pub prev_content: Option<CustomStateEventContent>,
|
||||
/// The unique identifier for the room associated with this event.
|
||||
|
@ -53,9 +53,8 @@ macro_rules! impl_room_event {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this event was
|
||||
/// sent.
|
||||
fn origin_server_ts(&self) -> UInt {
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
fn origin_server_ts(&self) -> ::std::time::SystemTime {
|
||||
self.origin_server_ts
|
||||
}
|
||||
|
||||
@ -63,17 +62,17 @@ macro_rules! impl_room_event {
|
||||
///
|
||||
/// This can be `None` if the event came from a context where there is
|
||||
/// no ambiguity which room it belongs to, like a `/sync` response for example.
|
||||
fn room_id(&self) -> Option<&RoomId> {
|
||||
fn room_id(&self) -> Option<&::ruma_identifiers::RoomId> {
|
||||
self.room_id.as_ref()
|
||||
}
|
||||
|
||||
/// The unique identifier for the user who sent this event.
|
||||
fn sender(&self) -> &UserId {
|
||||
fn sender(&self) -> &::ruma_identifiers::UserId {
|
||||
&self.sender
|
||||
}
|
||||
|
||||
/// Additional key-value pairs not signed by the homeserver.
|
||||
fn unsigned(&self) -> &serde_json::Map<String, serde_json::Value> {
|
||||
fn unsigned(&self) -> &::serde_json::Map<String, ::serde_json::Value> {
|
||||
&self.unsigned
|
||||
}
|
||||
}
|
||||
@ -100,7 +99,7 @@ macro_rules! impl_state_event {
|
||||
|
||||
macro_rules! impl_from_for_enum {
|
||||
($self_ty:ident, $inner_ty:ty, $variant:ident) => {
|
||||
impl From<$inner_ty> for $self_ty {
|
||||
impl ::std::convert::From<$inner_ty> for $self_ty {
|
||||
fn from(event: $inner_ty) -> Self {
|
||||
$self_ty::$variant(event)
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
//! Types for the *m.receipt* event.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, time::SystemTime};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_events_macros::ruma_event;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -44,8 +43,13 @@ pub struct Receipts {
|
||||
pub type UserReceipts = HashMap<UserId, Receipt>;
|
||||
|
||||
/// An acknowledgement of an event.
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Receipt {
|
||||
/// The timestamp (milliseconds since the Unix epoch) when the receipt was sent.
|
||||
pub ts: Option<UInt>,
|
||||
/// The time when the receipt was sent.
|
||||
#[serde(
|
||||
with = "ruma_serde::time::opt_ms_since_unix_epoch",
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub ts: Option<SystemTime>,
|
||||
}
|
||||
|
@ -1,8 +1,15 @@
|
||||
//! Types for the *m.room.canonical_alias* event.
|
||||
|
||||
use js_int::UInt;
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use ruma_identifiers::{EventId, RoomAliasId, RoomId, UserId};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||
use serde::{
|
||||
ser::{Error, SerializeStruct},
|
||||
Deserialize, Serialize, Serializer,
|
||||
};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::{util::empty_string_as_none, Event, EventType, FromRaw};
|
||||
@ -16,9 +23,8 @@ pub struct CanonicalAliasEvent {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
pub prev_content: Option<CanonicalAliasEventContent>,
|
||||
@ -93,7 +99,15 @@ impl Serialize for CanonicalAliasEvent {
|
||||
|
||||
state.serialize_field("content", &self.content)?;
|
||||
state.serialize_field("event_id", &self.event_id)?;
|
||||
state.serialize_field("origin_server_ts", &self.origin_server_ts)?;
|
||||
|
||||
let origin_server_ts = js_int::UInt::try_from(
|
||||
self.origin_server_ts
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_millis(),
|
||||
)
|
||||
.map_err(S::Error::custom)?;
|
||||
state.serialize_field("origin_server_ts", &origin_server_ts)?;
|
||||
|
||||
if self.prev_content.is_some() {
|
||||
state.serialize_field("prev_content", &self.prev_content)?;
|
||||
@ -133,9 +147,9 @@ pub(crate) mod raw {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
pub prev_content: Option<CanonicalAliasEventContent>,
|
||||
@ -170,9 +184,11 @@ pub(crate) mod raw {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::convert::TryFrom;
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
time::{Duration, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomAliasId, UserId};
|
||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value, Map};
|
||||
|
||||
@ -186,7 +202,7 @@ mod tests {
|
||||
alias: Some(RoomAliasId::try_from("#somewhere:localhost").unwrap()),
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::try_from(1).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: None,
|
||||
room_id: None,
|
||||
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! Types for the *m.room.encrypted* event.
|
||||
use std::collections::HashMap;
|
||||
|
||||
use std::{collections::HashMap, time::SystemTime};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{DeviceId, EventId, RoomId, UserId};
|
||||
@ -21,9 +22,9 @@ pub struct EncryptedEvent {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -121,9 +122,9 @@ pub(crate) mod raw {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
pub room_id: Option<RoomId>,
|
||||
|
@ -221,9 +221,11 @@ impl MemberEvent {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::convert::TryFrom;
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
time::{Duration, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde_json::{json, Map};
|
||||
|
||||
@ -241,7 +243,7 @@ mod tests {
|
||||
third_party_invite: None,
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::new(1).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
room_id: Some(RoomId::try_from("!n8f893n9:example.com").unwrap()),
|
||||
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||
state_key: "example.com".to_string(),
|
||||
@ -273,7 +275,7 @@ mod tests {
|
||||
third_party_invite: None,
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::new(1).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
room_id: Some(RoomId::try_from("!n8f893n9:example.com").unwrap()),
|
||||
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||
state_key: "example.com".to_string(),
|
||||
@ -329,7 +331,7 @@ mod tests {
|
||||
}),
|
||||
},
|
||||
event_id: EventId::try_from("$143273582443PhrSn:example.org").unwrap(),
|
||||
origin_server_ts: UInt::new(233).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(233),
|
||||
room_id: Some(RoomId::try_from("!jEsUZKDJdhlrceRyVU:example.org").unwrap()),
|
||||
sender: UserId::try_from("@alice:example.org").unwrap(),
|
||||
state_key: "@alice:example.org".to_string(),
|
||||
@ -384,7 +386,7 @@ mod tests {
|
||||
third_party_invite: None,
|
||||
},
|
||||
event_id: EventId::try_from("$143273582443PhrSn:example.org").unwrap(),
|
||||
origin_server_ts: UInt::new(233).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(233),
|
||||
room_id: Some(RoomId::try_from("!jEsUZKDJdhlrceRyVU:example.org").unwrap()),
|
||||
sender: UserId::try_from("@alice:example.org").unwrap(),
|
||||
state_key: "@alice:example.org".to_string(),
|
||||
|
@ -1,5 +1,7 @@
|
||||
//! Types for the *m.room.message* event.
|
||||
|
||||
use std::time::SystemTime;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
@ -20,9 +22,9 @@ pub struct MessageEvent {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -149,9 +151,9 @@ pub(crate) mod raw {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The unique identifier for the room associated with this event.
|
||||
pub room_id: Option<RoomId>,
|
||||
|
@ -1,6 +1,7 @@
|
||||
//! Types for the *m.room.name* event.
|
||||
|
||||
use js_int::UInt;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
@ -17,9 +18,9 @@ pub struct NameEvent {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -117,9 +118,9 @@ pub(crate) mod raw {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
pub prev_content: Option<NameEventContent>,
|
||||
@ -152,9 +153,12 @@ pub(crate) mod raw {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{convert::TryFrom, iter::FromIterator};
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
iter::FromIterator,
|
||||
time::{Duration, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value, Map};
|
||||
|
||||
@ -169,7 +173,7 @@ mod tests {
|
||||
name: Some("The room name".to_string()),
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::try_from(1).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: None,
|
||||
room_id: None,
|
||||
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||
@ -199,7 +203,7 @@ mod tests {
|
||||
name: Some("The room name".to_string()),
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::try_from(1).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: Some(NameEventContent {
|
||||
name: Some("The old name".to_string()),
|
||||
}),
|
||||
|
@ -17,9 +17,8 @@ ruma_event! {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::convert::TryFrom;
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde_json::{to_string, Map};
|
||||
|
||||
@ -38,7 +37,7 @@ mod tests {
|
||||
let event = PinnedEventsEvent {
|
||||
content: content.clone(),
|
||||
event_id: EventId::new("example.com").unwrap(),
|
||||
origin_server_ts: UInt::try_from(1_432_804_485_886u64).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1_432_804_485_886u64),
|
||||
prev_content: None,
|
||||
room_id: Some(RoomId::new("example.com").unwrap()),
|
||||
sender: UserId::new("example.com").unwrap(),
|
||||
|
@ -1,8 +1,8 @@
|
||||
//! Types for the *m.room.power_levels* event.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, time::SystemTime};
|
||||
|
||||
use js_int::{Int, UInt};
|
||||
use js_int::Int;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
@ -19,9 +19,9 @@ pub struct PowerLevelsEvent {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -146,9 +146,9 @@ pub(crate) mod raw {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
pub prev_content: Option<PowerLevelsEventContent>,
|
||||
@ -262,9 +262,13 @@ fn is_power_level_zero(l: &Int) -> bool {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{collections::HashMap, convert::TryFrom};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
convert::TryFrom,
|
||||
time::{Duration, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use js_int::{Int, UInt};
|
||||
use js_int::Int;
|
||||
use maplit::hashmap;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde_json::{json, to_value as to_json_value, Map};
|
||||
@ -292,7 +296,7 @@ mod tests {
|
||||
notifications: NotificationPowerLevels::default(),
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::from(1u32),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: None,
|
||||
room_id: None,
|
||||
unsigned: Map::new(),
|
||||
@ -336,7 +340,7 @@ mod tests {
|
||||
},
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::from(1u32),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: Some(PowerLevelsEventContent {
|
||||
// Make just one field different so we at least know they're two different objects.
|
||||
ban: Int::from(42),
|
||||
|
@ -1,6 +1,7 @@
|
||||
//! Types for the *m.room.server_acl* event.
|
||||
|
||||
use js_int::UInt;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
@ -17,9 +18,9 @@ pub struct ServerAclEvent {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -116,9 +117,9 @@ pub(crate) mod raw {
|
||||
/// The unique identifier for the event.
|
||||
pub event_id: EventId,
|
||||
|
||||
/// Timestamp (milliseconds since the UNIX epoch) on originating homeserver when this
|
||||
/// event was sent.
|
||||
pub origin_server_ts: UInt,
|
||||
/// Time on originating homeserver when this event was sent.
|
||||
#[serde(with = "ruma_serde::time::ms_since_unix_epoch")]
|
||||
pub origin_server_ts: SystemTime,
|
||||
|
||||
/// The previous content for this state key, if any.
|
||||
pub prev_content: Option<ServerAclEventContent>,
|
||||
|
@ -256,9 +256,10 @@ mod raw {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use js_int::UInt;
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
time::{Duration, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use ruma_identifiers::{RoomId, UserId};
|
||||
use serde_json::{from_value as from_json_value, json};
|
||||
@ -647,7 +648,7 @@ mod tests {
|
||||
assert_eq!(event.content.methods, &[VerificationMethod::MSasV1]);
|
||||
assert_eq!(
|
||||
event.content.timestamp,
|
||||
UInt::new(1_559_598_944_869).unwrap()
|
||||
UNIX_EPOCH + Duration::from_millis(1_559_598_944_869)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
use std::{collections::HashMap, convert::TryFrom};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
convert::TryFrom,
|
||||
time::{Duration, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_events::util::serde_json_eq_try_from_raw;
|
||||
use ruma_events_macros::ruma_event;
|
||||
use ruma_identifiers::{EventId, RoomAliasId, RoomId, UserId};
|
||||
@ -29,7 +32,7 @@ mod common_case {
|
||||
aliases: Vec::with_capacity(0),
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::try_from(1).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: None,
|
||||
room_id: None,
|
||||
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||
@ -56,7 +59,7 @@ mod common_case {
|
||||
aliases: vec![RoomAliasId::try_from("#room:example.org").unwrap()],
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::try_from(1).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: Some(AliasesEventContent {
|
||||
aliases: Vec::with_capacity(0),
|
||||
}),
|
||||
@ -89,7 +92,7 @@ mod common_case {
|
||||
aliases: vec![RoomAliasId::try_from("#room:example.org").unwrap()],
|
||||
},
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::try_from(1).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
prev_content: Some(AliasesEventContent {
|
||||
aliases: Vec::with_capacity(0),
|
||||
}),
|
||||
@ -144,7 +147,7 @@ mod extra_fields {
|
||||
content: RedactionEventContent { reason: None },
|
||||
redacts: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
origin_server_ts: UInt::try_from(1).unwrap(),
|
||||
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||
room_id: Some(RoomId::try_from("!n8f893n9:example.com").unwrap()),
|
||||
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||
unsigned: serde_json::from_str(r#"{"foo":"bar"}"#).unwrap(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user