Bring back ruma-events

Co-authored-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Jonas Platte 2023-08-24 14:40:23 +02:00
parent fec7d23cfd
commit 31331f3165
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
239 changed files with 1009 additions and 996 deletions

View File

@ -19,6 +19,7 @@ ruma-appservice-api = { version = "0.8.1", path = "crates/ruma-appservice-api" }
ruma-common = { version = "0.11.3", path = "crates/ruma-common" } ruma-common = { version = "0.11.3", path = "crates/ruma-common" }
ruma-client = { version = "0.11.0", path = "crates/ruma-client" } ruma-client = { version = "0.11.0", path = "crates/ruma-client" }
ruma-client-api = { version = "0.16.2", path = "crates/ruma-client-api" } ruma-client-api = { version = "0.16.2", path = "crates/ruma-client-api" }
ruma-events = { version = "0.26.0", path = "crates/ruma-events" }
ruma-federation-api = { version = "0.7.1", path = "crates/ruma-federation-api" } ruma-federation-api = { version = "0.7.1", path = "crates/ruma-federation-api" }
ruma-html = { version = "0.1.0", path = "crates/ruma-html" } ruma-html = { version = "0.1.0", path = "crates/ruma-html" }
ruma-identifiers-validation = { version = "0.9.1", path = "crates/ruma-identifiers-validation" } ruma-identifiers-validation = { version = "0.9.1", path = "crates/ruma-identifiers-validation" }

View File

@ -24,7 +24,8 @@ unstable-msc3202 = []
[dependencies] [dependencies]
js_int = { workspace = true, features = ["serde"] } js_int = { workspace = true, features = ["serde"] }
ruma-common = { workspace = true, features = ["api", "events"] } ruma-common = { workspace = true, features = ["api"] }
ruma-events = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }

View File

@ -17,24 +17,23 @@ pub mod v1 {
#[cfg(any(feature = "unstable-msc2409", feature = "unstable-msc3202"))] #[cfg(any(feature = "unstable-msc2409", feature = "unstable-msc3202"))]
use js_int::UInt; use js_int::UInt;
#[cfg(feature = "unstable-msc2409")]
use ruma_common::events::AnyToDeviceEvent;
#[cfg(any(feature = "unstable-msc2409", feature = "unstable-msc3202"))] #[cfg(any(feature = "unstable-msc2409", feature = "unstable-msc3202"))]
use ruma_common::OwnedUserId; use ruma_common::OwnedUserId;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::AnyTimelineEvent,
metadata, metadata,
serde::Raw, serde::Raw,
OwnedTransactionId, OwnedTransactionId,
}; };
#[cfg(feature = "unstable-msc2409")] #[cfg(feature = "unstable-msc2409")]
use ruma_common::{ use ruma_common::{
events::receipt::Receipt, presence::PresenceState, serde::from_raw_json_value, presence::PresenceState, serde::from_raw_json_value, OwnedEventId, OwnedRoomId,
OwnedEventId, OwnedRoomId,
}; };
#[cfg(feature = "unstable-msc3202")] #[cfg(feature = "unstable-msc3202")]
use ruma_common::{DeviceKeyAlgorithm, OwnedDeviceId}; use ruma_common::{DeviceKeyAlgorithm, OwnedDeviceId};
use ruma_events::AnyTimelineEvent;
#[cfg(feature = "unstable-msc2409")]
use ruma_events::{receipt::Receipt, AnyToDeviceEvent};
#[cfg(feature = "unstable-msc2409")] #[cfg(feature = "unstable-msc2409")]
use serde::Deserializer; use serde::Deserializer;
#[cfg(any(feature = "unstable-msc2409", feature = "unstable-msc3202"))] #[cfg(any(feature = "unstable-msc2409", feature = "unstable-msc3202"))]

View File

@ -102,7 +102,7 @@ Improvements:
* Add `ErrorKind::{UnableToAuthorizeJoin, UnableToGrantJoin}` encountered for restricted rooms * Add `ErrorKind::{UnableToAuthorizeJoin, UnableToGrantJoin}` encountered for restricted rooms
* Add support for timestamp massaging (MSC3316) * Add support for timestamp massaging (MSC3316)
* Add support for querying relating events (MSC2675) * Add support for querying relating events (MSC2675)
* Move `filter::RelationType` to `ruma_common::events::relations` * Move `filter::RelationType` to `ruma_events::relations`
* Add unstable support for discovering an OpenID Connect server (MSC2965) * Add unstable support for discovering an OpenID Connect server (MSC2965)
* Add `SpaceRoomJoinRule::KnockRestricted` (MSC3787) * Add `SpaceRoomJoinRule::KnockRestricted` (MSC3787)
* Add unstable support for private read receipts (MSC2285) * Add unstable support for private read receipts (MSC2285)

View File

@ -54,7 +54,8 @@ http = { workspace = true }
js_int = { workspace = true, features = ["serde"] } js_int = { workspace = true, features = ["serde"] }
js_option = "0.1.1" js_option = "0.1.1"
maplit = { workspace = true } maplit = { workspace = true }
ruma-common = { workspace = true, features = ["api", "events"] } ruma-common = { workspace = true, features = ["api"] }
ruma-events = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_html_form = { workspace = true } serde_html_form = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }

View File

@ -9,11 +9,11 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{AnyGlobalAccountDataEventContent, GlobalAccountDataEventType},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedUserId, OwnedUserId,
}; };
use ruma_events::{AnyGlobalAccountDataEventContent, GlobalAccountDataEventType};
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,
@ -47,7 +47,7 @@ pub mod v3 {
/// types with a variable suffix (like [`SecretStorageKeyEventContent`]) to /// types with a variable suffix (like [`SecretStorageKeyEventContent`]) to
/// deserialize it. /// deserialize it.
/// ///
/// [`SecretStorageKeyEventContent`]: ruma_common::events::secret_storage::key::SecretStorageKeyEventContent /// [`SecretStorageKeyEventContent`]: ruma_events::secret_storage::key::SecretStorageKeyEventContent
#[ruma_api(body)] #[ruma_api(body)]
pub account_data: Raw<AnyGlobalAccountDataEventContent>, pub account_data: Raw<AnyGlobalAccountDataEventContent>,
} }

View File

@ -9,11 +9,11 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{AnyRoomAccountDataEventContent, RoomAccountDataEventType},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedRoomId, OwnedUserId, OwnedRoomId, OwnedUserId,
}; };
use ruma_events::{AnyRoomAccountDataEventContent, RoomAccountDataEventType};
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,

View File

@ -9,14 +9,13 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{
AnyGlobalAccountDataEventContent, GlobalAccountDataEventContent,
GlobalAccountDataEventType,
},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedUserId, OwnedUserId,
}; };
use ruma_events::{
AnyGlobalAccountDataEventContent, GlobalAccountDataEventContent, GlobalAccountDataEventType,
};
use serde_json::value::to_raw_value as to_raw_json_value; use serde_json::value::to_raw_value as to_raw_json_value;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {

View File

@ -9,13 +9,13 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{
AnyRoomAccountDataEventContent, RoomAccountDataEventContent, RoomAccountDataEventType,
},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedRoomId, OwnedUserId, OwnedRoomId, OwnedUserId,
}; };
use ruma_events::{
AnyRoomAccountDataEventContent, RoomAccountDataEventContent, RoomAccountDataEventType,
};
use serde_json::value::to_raw_value as to_raw_json_value; use serde_json::value::to_raw_value as to_raw_json_value;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {

View File

@ -10,11 +10,11 @@ pub mod v3 {
use js_int::{uint, UInt}; use js_int::{uint, UInt};
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{AnyStateEvent, AnyTimelineEvent},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedEventId, OwnedRoomId, OwnedEventId, OwnedRoomId,
}; };
use ruma_events::{AnyStateEvent, AnyTimelineEvent};
use crate::filter::RoomEventFilter; use crate::filter::RoomEventFilter;

View File

@ -9,11 +9,11 @@ pub mod unstable {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::AnyToDeviceEvent,
metadata, metadata,
serde::Raw, serde::Raw,
OwnedDeviceId, OwnedDeviceId,
}; };
use ruma_events::AnyToDeviceEvent;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: POST, method: POST,

View File

@ -9,11 +9,11 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::room::member::RoomMemberEvent,
metadata, metadata,
serde::{Raw, StringEnum}, serde::{Raw, StringEnum},
OwnedRoomId, OwnedRoomId,
}; };
use ruma_events::room::member::RoomMemberEvent;
use crate::PrivOwnedStr; use crate::PrivOwnedStr;

View File

@ -10,11 +10,11 @@ pub mod v3 {
use js_int::{uint, UInt}; use js_int::{uint, UInt};
use ruma_common::{ use ruma_common::{
api::{request, response, Direction, Metadata}, api::{request, response, Direction, Metadata},
events::{AnyStateEvent, AnyTimelineEvent},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedRoomId, OwnedRoomId,
}; };
use ruma_events::{AnyStateEvent, AnyTimelineEvent};
use crate::filter::RoomEventFilter; use crate::filter::RoomEventFilter;

View File

@ -9,11 +9,11 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{AnyMessageLikeEventContent, MessageLikeEventContent, MessageLikeEventType},
metadata, metadata,
serde::Raw, serde::Raw,
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedTransactionId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedTransactionId,
}; };
use ruma_events::{AnyMessageLikeEventContent, MessageLikeEventContent, MessageLikeEventType};
use serde_json::value::to_raw_value as to_raw_json_value; use serde_json::value::to_raw_value as to_raw_json_value;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {

View File

@ -10,12 +10,12 @@ pub mod v3 {
use js_int::UInt; use js_int::UInt;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::AnySyncTimelineEvent,
metadata, metadata,
push::Action, push::Action,
serde::Raw, serde::Raw,
MilliSecondsSinceUnixEpoch, OwnedRoomId, MilliSecondsSinceUnixEpoch, OwnedRoomId,
}; };
use ruma_events::AnySyncTimelineEvent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {

View File

@ -9,11 +9,11 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::receipt::ReceiptThread,
metadata, metadata,
serde::{OrdAsRefStr, PartialEqAsRefStr, PartialOrdAsRefStr, StringEnum}, serde::{OrdAsRefStr, PartialEqAsRefStr, PartialOrdAsRefStr, StringEnum},
OwnedEventId, OwnedRoomId, OwnedEventId, OwnedRoomId,
}; };
use ruma_events::receipt::ReceiptThread;
use crate::PrivOwnedStr; use crate::PrivOwnedStr;

View File

@ -10,11 +10,11 @@ pub mod v1 {
use js_int::UInt; use js_int::UInt;
use ruma_common::{ use ruma_common::{
api::{request, response, Direction, Metadata}, api::{request, response, Direction, Metadata},
events::AnyMessageLikeEvent,
metadata, metadata,
serde::Raw, serde::Raw,
OwnedEventId, OwnedRoomId, OwnedEventId, OwnedRoomId,
}; };
use ruma_events::AnyMessageLikeEvent;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,

View File

@ -11,11 +11,11 @@ pub mod v1 {
use js_int::UInt; use js_int::UInt;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{relation::RelationType, AnyMessageLikeEvent},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedEventId, OwnedRoomId, OwnedEventId, OwnedRoomId,
}; };
use ruma_events::{relation::RelationType, AnyMessageLikeEvent};
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,

View File

@ -11,11 +11,11 @@ pub mod v1 {
use js_int::UInt; use js_int::UInt;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{relation::RelationType, AnyMessageLikeEvent, TimelineEventType},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedEventId, OwnedRoomId, OwnedEventId, OwnedRoomId,
}; };
use ruma_events::{relation::RelationType, AnyMessageLikeEvent, TimelineEventType};
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,

View File

@ -10,18 +10,18 @@ pub mod v3 {
use assign::assign; use assign::assign;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{
room::{
create::{PreviousRoom, RoomCreateEventContent},
power_levels::RoomPowerLevelsEventContent,
},
AnyInitialStateEvent,
},
metadata, metadata,
room::RoomType, room::RoomType,
serde::{Raw, StringEnum}, serde::{Raw, StringEnum},
OwnedRoomId, OwnedUserId, RoomVersionId, OwnedRoomId, OwnedUserId, RoomVersionId,
}; };
use ruma_events::{
room::{
create::{PreviousRoom, RoomCreateEventContent},
power_levels::RoomPowerLevelsEventContent,
},
AnyInitialStateEvent,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{membership::Invite3pid, room::Visibility, PrivOwnedStr}; use crate::{membership::Invite3pid, room::Visibility, PrivOwnedStr};

View File

@ -9,11 +9,11 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::AnyTimelineEvent,
metadata, metadata,
serde::Raw, serde::Raw,
OwnedEventId, OwnedRoomId, OwnedEventId, OwnedRoomId,
}; };
use ruma_events::AnyTimelineEvent;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,

View File

@ -12,11 +12,11 @@ pub mod v3 {
use js_int::{uint, UInt}; use js_int::{uint, UInt};
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{AnyStateEvent, AnyTimelineEvent},
metadata, metadata,
serde::{Raw, StringEnum}, serde::{Raw, StringEnum},
OwnedEventId, OwnedMxcUri, OwnedRoomId, OwnedUserId, OwnedEventId, OwnedMxcUri, OwnedRoomId, OwnedUserId,
}; };
use ruma_events::{AnyStateEvent, AnyTimelineEvent};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{filter::RoomEventFilter, PrivOwnedStr}; use crate::{filter::RoomEventFilter, PrivOwnedStr};

View File

@ -6,9 +6,10 @@
use js_int::UInt; use js_int::UInt;
use ruma_common::{ use ruma_common::{
events::space::child::HierarchySpaceChildEvent, room::RoomType, serde::Raw, room::RoomType, serde::Raw, space::SpaceRoomJoinRule, OwnedMxcUri, OwnedRoomAliasId,
space::SpaceRoomJoinRule, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedRoomId,
}; };
use ruma_events::space::child::HierarchySpaceChildEvent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub mod get_hierarchy; pub mod get_hierarchy;

View File

@ -9,11 +9,11 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::AnyStateEvent,
metadata, metadata,
serde::Raw, serde::Raw,
OwnedRoomId, OwnedRoomId,
}; };
use ruma_events::AnyStateEvent;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,

View File

@ -9,11 +9,11 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{response, Metadata}, api::{response, Metadata},
events::{AnyStateEventContent, StateEventType},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedRoomId, OwnedRoomId,
}; };
use ruma_events::{AnyStateEventContent, StateEventType};
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,

View File

@ -11,11 +11,11 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{response, Metadata}, api::{response, Metadata},
events::{AnyStateEventContent, StateEventContent, StateEventType},
metadata, metadata,
serde::Raw, serde::Raw,
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId,
}; };
use ruma_events::{AnyStateEventContent, StateEventContent, StateEventType};
use serde_json::value::to_raw_value as to_raw_json_value; use serde_json::value::to_raw_value as to_raw_json_value;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
@ -209,9 +209,9 @@ pub mod v3 {
fn serialize() { fn serialize() {
use ruma_common::{ use ruma_common::{
api::{MatrixVersion, OutgoingRequest as _, SendAccessToken}, api::{MatrixVersion, OutgoingRequest as _, SendAccessToken},
events::{room::name::RoomNameEventContent, EmptyStateKey},
owned_room_id, owned_room_id,
}; };
use ruma_events::{room::name::RoomNameEventContent, EmptyStateKey};
// This used to panic in make_endpoint_url because of a mismatch in the path parameter count // This used to panic in make_endpoint_url because of a mismatch in the path parameter count
let req = Request::new( let req = Request::new(

View File

@ -7,16 +7,16 @@ use std::{collections::BTreeMap, time::Duration};
use js_int::UInt; use js_int::UInt;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{
presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncStateEvent, AnySyncTimelineEvent,
AnyToDeviceEvent,
},
metadata, metadata,
presence::PresenceState, presence::PresenceState,
serde::Raw, serde::Raw,
DeviceKeyAlgorithm, OwnedEventId, OwnedRoomId, DeviceKeyAlgorithm, OwnedEventId, OwnedRoomId,
}; };
use ruma_events::{
presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncStateEvent, AnySyncTimelineEvent,
AnyToDeviceEvent,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{DeviceLists, UnreadNotificationsCount}; use super::{DeviceLists, UnreadNotificationsCount};

View File

@ -9,15 +9,15 @@ use std::{collections::BTreeMap, time::Duration};
use js_int::UInt; use js_int::UInt;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{
receipt::SyncReceiptEvent, typing::SyncTypingEvent, AnyGlobalAccountDataEvent,
AnyRoomAccountDataEvent, AnyStrippedStateEvent, AnySyncStateEvent, AnySyncTimelineEvent,
AnyToDeviceEvent, StateEventType, TimelineEventType,
},
metadata, metadata,
serde::{duration::opt_ms, Raw}, serde::{duration::opt_ms, Raw},
DeviceKeyAlgorithm, MilliSecondsSinceUnixEpoch, OwnedMxcUri, OwnedRoomId, DeviceKeyAlgorithm, MilliSecondsSinceUnixEpoch, OwnedMxcUri, OwnedRoomId,
}; };
use ruma_events::{
receipt::SyncReceiptEvent, typing::SyncTypingEvent, AnyGlobalAccountDataEvent,
AnyRoomAccountDataEvent, AnyStrippedStateEvent, AnySyncStateEvent, AnySyncTimelineEvent,
AnyToDeviceEvent, StateEventType, TimelineEventType,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{DeviceLists, UnreadNotificationsCount}; use super::{DeviceLists, UnreadNotificationsCount};

View File

@ -9,9 +9,9 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::tag::TagInfo,
metadata, OwnedRoomId, OwnedUserId, metadata, OwnedRoomId, OwnedUserId,
}; };
use ruma_events::tag::TagInfo;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: PUT, method: PUT,

View File

@ -9,9 +9,9 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::tag::Tags,
metadata, OwnedRoomId, OwnedUserId, metadata, OwnedRoomId, OwnedUserId,
}; };
use ruma_events::tag::Tags;
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: GET, method: GET,
@ -59,10 +59,8 @@ pub mod v3 {
#[cfg(all(test, feature = "server"))] #[cfg(all(test, feature = "server"))]
mod server_tests { mod server_tests {
use assign::assign; use assign::assign;
use ruma_common::{ use ruma_common::api::OutgoingResponse;
api::OutgoingResponse, use ruma_events::tag::{TagInfo, Tags};
events::tag::{TagInfo, Tags},
};
use serde_json::json; use serde_json::json;
use super::Response; use super::Response;

View File

@ -10,11 +10,11 @@ pub mod v1 {
use js_int::UInt; use js_int::UInt;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::AnyTimelineEvent,
metadata, metadata,
serde::{Raw, StringEnum}, serde::{Raw, StringEnum},
OwnedRoomId, OwnedRoomId,
}; };
use ruma_events::AnyTimelineEvent;
use crate::PrivOwnedStr; use crate::PrivOwnedStr;

View File

@ -11,12 +11,12 @@ pub mod v3 {
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{AnyToDeviceEventContent, ToDeviceEventType},
metadata, metadata,
serde::Raw, serde::Raw,
to_device::DeviceIdOrAllDevices, to_device::DeviceIdOrAllDevices,
OwnedTransactionId, OwnedUserId, OwnedTransactionId, OwnedUserId,
}; };
use ruma_events::{AnyToDeviceEventContent, ToDeviceEventType};
const METADATA: Metadata = metadata! { const METADATA: Metadata = metadata! {
method: PUT, method: PUT,

View File

@ -43,6 +43,9 @@ Breaking changes:
- In Markdown, soft line breaks are transformed into hard line breaks when compiled into HTML. - In Markdown, soft line breaks are transformed into hard line breaks when compiled into HTML.
- Move the HTML functions in `events::room::message::sanitize` to the ruma-html crate - Move the HTML functions in `events::room::message::sanitize` to the ruma-html crate
- The `unstable-sanitize` cargo feature was renamed to `html` - The `unstable-sanitize` cargo feature was renamed to `html`
- Removed the `events` module, it is once again its own crate (`ruma-events`)
- Removed `From` and `TryFrom` implementations for `RedactedBecause` in favor of named constructors
(`from_json` and `from_raw_event`)
Improvements: Improvements:

View File

@ -23,31 +23,13 @@ server = []
api = ["dep:http", "dep:konst"] api = ["dep:http", "dep:konst"]
canonical-json = [] canonical-json = []
events = []
html = ["dep:ruma-html"]
js = ["dep:js-sys", "getrandom?/js", "uuid?/js"] js = ["dep:js-sys", "getrandom?/js", "uuid?/js"]
markdown = ["pulldown-cmark"]
rand = ["dep:rand", "dep:uuid"] rand = ["dep:rand", "dep:uuid"]
unstable-exhaustive-types = [] unstable-exhaustive-types = []
unstable-msc1767 = []
unstable-msc2448 = []
unstable-msc2747 = []
unstable-msc2870 = [] unstable-msc2870 = []
unstable-msc3245 = ["unstable-msc3246"] unstable-msc3381 = []
unstable-msc3246 = ["unstable-msc3927"]
unstable-msc3381 = ["unstable-msc1767"]
unstable-msc3488 = ["unstable-msc1767"]
unstable-msc3551 = ["unstable-msc3956"]
unstable-msc3552 = ["unstable-msc3551"]
unstable-msc3553 = ["unstable-msc3552"]
unstable-msc3554 = ["unstable-msc1767"]
unstable-msc3927 = ["unstable-msc3551"]
unstable-msc3931 = [] unstable-msc3931 = []
unstable-msc3932 = ["unstable-msc3931"] unstable-msc3932 = ["unstable-msc3931"]
unstable-msc3954 = ["unstable-msc1767"]
unstable-msc3955 = ["unstable-msc1767"]
unstable-msc3956 = ["unstable-msc1767"]
unstable-pdu = []
unstable-unspecified = [] unstable-unspecified = []
# Don't validate the version part in `KeyId`. # Don't validate the version part in `KeyId`.
@ -69,9 +51,6 @@ compat-null = []
# mandatory. Deserialization will yield a default value like an empty string. # mandatory. Deserialization will yield a default value like an empty string.
compat-optional = [] compat-optional = []
# Allow TagInfo to contain a stringified floating-point value for the `order` field.
compat-tag-info = []
[dependencies] [dependencies]
base64 = { workspace = true } base64 = { workspace = true }
bytes = "1.0.1" bytes = "1.0.1"
@ -80,13 +59,10 @@ getrandom = { version = "0.2.6", optional = true }
http = { workspace = true, optional = true } http = { workspace = true, optional = true }
indexmap = { version = "2.0.0", features = ["serde"] } indexmap = { version = "2.0.0", features = ["serde"] }
js_int = { workspace = true, features = ["serde"] } js_int = { workspace = true, features = ["serde"] }
js_option = "0.1.0"
konst = { version = "0.3.5", default-features = false, features = ["cmp", "iter", "parsing"], optional = true } konst = { version = "0.3.5", default-features = false, features = ["cmp", "iter", "parsing"], optional = true }
percent-encoding = "2.1.0" percent-encoding = "2.1.0"
pulldown-cmark = { version = "0.9.1", default-features = false, optional = true }
rand = { version = "0.8.3", optional = true } rand = { version = "0.8.3", optional = true }
regex = { version = "1.5.6", default-features = false, features = ["std", "perf"] } regex = { version = "1.5.6", default-features = false, features = ["std", "perf"] }
ruma-html = { workspace = true, optional = true }
ruma-identifiers-validation = { workspace = true } ruma-identifiers-validation = { workspace = true }
ruma-macros = { workspace = true } ruma-macros = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
@ -98,20 +74,11 @@ url = "2.2.2"
uuid = { version = "1.0.0", optional = true, features = ["v4"] } uuid = { version = "1.0.0", optional = true, features = ["v4"] }
wildmatch = "2.0.0" wildmatch = "2.0.0"
# dev-dependencies can't be optional, so this is a regular dependency
criterion = { workspace = true, optional = true }
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
js-sys = { version = "0.3", optional = true } js-sys = { version = "0.3", optional = true }
[dev-dependencies] [dev-dependencies]
assert_matches2 = { workspace = true } assert_matches2 = { workspace = true }
assign = { workspace = true } assign = { workspace = true }
http = { workspace = true }
maplit = { workspace = true } maplit = { workspace = true }
trybuild = "1.0.71" trybuild = "1.0.71"
[[bench]]
name = "event_deserialize"
harness = false
required-features = ["criterion", "events"]

View File

@ -8,15 +8,7 @@ use serde_json::Value as JsonValue;
mod value; mod value;
pub use self::value::{CanonicalJsonObject, CanonicalJsonValue}; pub use self::value::{CanonicalJsonObject, CanonicalJsonValue};
use crate::RoomVersionId; use crate::{serde::Raw, RoomVersionId};
#[cfg(feature = "events")]
use crate::{
events::room::redaction::{
OriginalRoomRedactionEvent, OriginalSyncRoomRedactionEvent, RoomRedactionEvent,
SyncRoomRedactionEvent,
},
serde::Raw,
};
/// The set of possible errors when serializing to canonical JSON. /// The set of possible errors when serializing to canonical JSON.
#[cfg(feature = "canonical-json")] #[cfg(feature = "canonical-json")]
@ -124,52 +116,25 @@ pub fn to_canonical_value<T: Serialize>(
} }
/// The value to put in `unsigned.redacted_because`. /// The value to put in `unsigned.redacted_because`.
///
/// See `From` implementations for ways to create an instance of this type.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct RedactedBecause(CanonicalJsonObject); pub struct RedactedBecause(CanonicalJsonObject);
impl From<CanonicalJsonObject> for RedactedBecause { impl RedactedBecause {
fn from(obj: CanonicalJsonObject) -> Self { /// Create a `RedactedBecause` from an arbitrary JSON object.
pub fn from_json(obj: CanonicalJsonObject) -> Self {
Self(obj) Self(obj)
} }
}
#[cfg(feature = "events")] /// Create a `RedactedBecause` from a redaction event.
impl TryFrom<&Raw<OriginalRoomRedactionEvent>> for RedactedBecause { ///
type Error = serde_json::Error; /// Fails if the raw event is not valid canonical JSON.
pub fn from_raw_event(ev: &Raw<impl RedactionEvent>) -> serde_json::Result<Self> {
fn try_from(value: &Raw<OriginalRoomRedactionEvent>) -> Result<Self, Self::Error> { ev.deserialize_as().map(Self)
value.deserialize_as().map(Self)
} }
} }
#[cfg(feature = "events")] /// Marker trait for redaction events.
impl TryFrom<&Raw<OriginalSyncRoomRedactionEvent>> for RedactedBecause { pub trait RedactionEvent {}
type Error = serde_json::Error;
fn try_from(value: &Raw<OriginalSyncRoomRedactionEvent>) -> Result<Self, Self::Error> {
value.deserialize_as().map(Self)
}
}
#[cfg(feature = "events")]
impl TryFrom<&Raw<RoomRedactionEvent>> for RedactedBecause {
type Error = serde_json::Error;
fn try_from(value: &Raw<RoomRedactionEvent>) -> Result<Self, Self::Error> {
value.deserialize_as().map(Self)
}
}
#[cfg(feature = "events")]
impl TryFrom<&Raw<SyncRoomRedactionEvent>> for RedactedBecause {
type Error = serde_json::Error;
fn try_from(value: &Raw<SyncRoomRedactionEvent>) -> Result<Self, Self::Error> {
value.deserialize_as().map(Self)
}
}
/// Redacts an event using the rules specified in the Matrix client-server specification. /// Redacts an event using the rules specified in the Matrix client-server specification.
/// ///

View File

@ -24,8 +24,6 @@ pub mod authentication;
pub mod canonical_json; pub mod canonical_json;
pub mod directory; pub mod directory;
pub mod encryption; pub mod encryption;
#[cfg(feature = "events")]
pub mod events;
mod identifiers; mod identifiers;
mod percent_encode; mod percent_encode;
pub mod power_levels; pub mod power_levels;

View File

@ -31,8 +31,8 @@ impl NotificationPowerLevels {
} }
} }
#[cfg(feature = "events")] /// Whether all fields have their default values.
pub(crate) fn is_default(&self) -> bool { pub fn is_default(&self) -> bool {
self.room == default_power_level() self.room == default_power_level()
} }
} }

View File

@ -8,9 +8,9 @@ use crate::PrivOwnedStr;
/// The rule used for users wishing to join a room. /// The rule used for users wishing to join a room.
/// ///
/// In contrast to the regular [`JoinRule`](crate::events::room::join_rules::JoinRule), this /// In contrast to the regular `JoinRule` in `ruma_events`, this enum does not hold the conditions
/// enum does not hold the conditions for joining restricted rooms. Instead, the server is assumed /// for joining restricted rooms. Instead, the server is assumed to only return rooms the user is
/// to only return rooms the user is allowed to join in a space hierarchy listing response. /// allowed to join in a space hierarchy listing response.
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))] #[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, Default, PartialEq, Eq, StringEnum)] #[derive(Clone, Default, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")] #[ruma_enum(rename_all = "snake_case")]
@ -29,15 +29,14 @@ pub enum SpaceRoomJoinRule {
Private, Private,
/// Users can join the room if they are invited, or if they meet any of the conditions /// Users can join the room if they are invited, or if they meet any of the conditions
/// described in a set of [`AllowRule`](crate::events::room::join_rules::AllowRule)s. /// described in a set of allow rules.
/// ///
/// These rules are not made available as part of a space hierarchy listing response and can /// These rules are not made available as part of a space hierarchy listing response and can
/// only be seen by users inside the room. /// only be seen by users inside the room.
Restricted, Restricted,
/// Users can join the room if they are invited, or if they meet any of the conditions /// Users can join the room if they are invited, or if they meet any of the conditions
/// described in a set of [`AllowRule`](crate::events::room::join_rules::AllowRule)s, or /// described in a set of allow rules, or they can request an invite to the room.
/// they can request an invite to the room.
KnockRestricted, KnockRestricted,
/// Anyone can join the room without any prior action. /// Anyone can join the room without any prior action.

View File

@ -1,11 +1,9 @@
#![allow(clippy::exhaustive_structs)] #![allow(clippy::exhaustive_structs)]
#[cfg(feature = "events")]
pub mod some_endpoint { pub mod some_endpoint {
use http::header::CONTENT_TYPE; use http::header::CONTENT_TYPE;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{tag::TagEvent, AnyTimelineEvent},
metadata, metadata,
serde::Raw, serde::Raw,
OwnedUserId, OwnedUserId,
@ -55,11 +53,14 @@ pub mod some_endpoint {
pub optional_flag: Option<bool>, pub optional_flag: Option<bool>,
// Use `Raw` instead of the actual event to allow additional fields to be sent... // Use `Raw` instead of the actual event to allow additional fields to be sent...
pub event: Raw<TagEvent>, pub event: Raw<Event>,
// ... and to allow unknown events when the endpoint deals with event collections. // ... and to allow unknown events when the endpoint deals with event collections.
pub list_of_events: Vec<Raw<AnyTimelineEvent>>, pub list_of_events: Vec<Raw<Event>>,
} }
// Dummy type to avoid circular dev-dependency that rust-analyzer doesn't like
pub struct Event {}
} }
pub mod newtype_body_endpoint { pub mod newtype_body_endpoint {

View File

@ -1,7 +1,6 @@
use http::header::CONTENT_TYPE; use http::header::CONTENT_TYPE;
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
events::{tag::TagEvent, AnyTimelineEvent},
metadata, metadata,
serde::Raw, serde::Raw,
}; };
@ -54,12 +53,15 @@ pub struct Response {
pub optional_flag: Option<bool>, pub optional_flag: Option<bool>,
// Use `Raw` instead of the actual event to allow additional fields to be sent... // Use `Raw` instead of the actual event to allow additional fields to be sent...
pub event: Raw<TagEvent>, pub event: Raw<Event>,
// ... and to allow unknown events when the endpoint deals with event collections. // ... and to allow unknown events when the endpoint deals with event collections.
pub list_of_events: Vec<Raw<AnyTimelineEvent>>, pub list_of_events: Vec<Raw<Event>>,
} }
// Dummy type to avoid circular dev-dependency that rust-analyzer doesn't like
pub struct Event {}
fn main() { fn main() {
use ruma_common::api::MatrixVersion; use ruma_common::api::MatrixVersion;

View File

@ -1,11 +0,0 @@
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.pass("tests/events/ui/01-content-sanity-check.rs");
t.compile_fail("tests/events/ui/02-no-event-type.rs");
t.compile_fail("tests/events/ui/03-invalid-event-type.rs");
t.pass("tests/events/ui/10-content-wildcard.rs");
t.pass("tests/events/ui/11-content-without-relation-sanity-check.rs");
t.compile_fail("tests/events/ui/12-no-relates_to.rs");
t.pass("tests/events/ui/13-private-event-content-type.rs");
}

View File

@ -1,5 +0,0 @@
error[E0433]: failed to resolve: could not find `not` in `events`
--> tests/events/ui/08-enum-invalid-path.rs:6:35
|
6 | "m.not.a.path" => events::not::a::path,
| ^^^ could not find `not` in `events`

View File

@ -1,4 +1,3 @@
mod api; mod api;
mod events;
mod identifiers; mod identifiers;
mod serde; mod serde;

View File

@ -0,0 +1,81 @@
[package]
name = "ruma-events"
version = "0.26.0"
description = "Serializable types for the events in the Matrix specification."
homepage = "https://www.ruma.io/"
keywords = ["matrix", "chat", "messaging", "ruma"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/ruma/ruma"
edition = "2021"
rust-version = { workspace = true }
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[features]
canonical-json = ["ruma-common/canonical-json"]
html = ["dep:ruma-html"]
markdown = ["pulldown-cmark"]
unstable-exhaustive-types = []
unstable-msc1767 = []
unstable-msc2448 = []
unstable-msc2747 = []
unstable-msc3245 = ["unstable-msc3246"]
unstable-msc3246 = ["unstable-msc3927"]
unstable-msc3381 = ["unstable-msc1767"]
unstable-msc3488 = ["unstable-msc1767"]
unstable-msc3551 = ["unstable-msc3956"]
unstable-msc3552 = ["unstable-msc3551"]
unstable-msc3553 = ["unstable-msc3552"]
unstable-msc3554 = ["unstable-msc1767"]
unstable-msc3927 = ["unstable-msc3551"]
unstable-msc3954 = ["unstable-msc1767"]
unstable-msc3955 = ["unstable-msc1767"]
unstable-msc3956 = ["unstable-msc1767"]
unstable-pdu = []
# Allow some mandatory fields to be missing, defaulting them to an empty string
# in deserialization.
compat-empty-string-null = []
# Allow certain fields to be absent even though the spec marks them as
# mandatory. Deserialization will yield a default value like an empty string.
compat-optional = []
# Allow TagInfo to contain a stringified floating-point value for the `order` field.
compat-tag-info = []
[dependencies]
indexmap = { version = "2.0.0", features = ["serde"] }
js_int = { workspace = true, features = ["serde"] }
js_option = "0.1.0"
percent-encoding = "2.1.0"
pulldown-cmark = { version = "0.9.1", default-features = false, optional = true }
regex = { version = "1.5.6", default-features = false, features = ["std", "perf"] }
ruma-common = { workspace = true }
ruma-html = { workspace = true, optional = true }
ruma-identifiers-validation = { workspace = true }
ruma-macros = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true, features = ["raw_value"] }
thiserror = { workspace = true }
tracing = { workspace = true, features = ["attributes"] }
url = "2.2.2"
wildmatch = "2.0.0"
# dev-dependencies can't be optional, so this is a regular dependency
criterion = { workspace = true, optional = true }
[dev-dependencies]
assert_matches2 = { workspace = true }
assign = { workspace = true }
http = { workspace = true }
maplit = { workspace = true }
trybuild = "1.0.71"
[[bench]]
name = "event_deserialize"
harness = false
required-features = ["criterion"]

View File

@ -0,0 +1,8 @@
# ruma-events
[![crates.io page](https://img.shields.io/crates/v/ruma-events.svg)](https://crates.io/crates/ruma-events)
[![docs.rs page](https://docs.rs/ruma-events/badge.svg)](https://docs.rs/ruma-events/)
![license: MIT](https://img.shields.io/crates/l/ruma-events.svg)
Serializable types for the events in the [Matrix](https://matrix.org/) specification that can be
shared by client and server code.

View File

@ -7,12 +7,10 @@
#![allow(unused_imports, dead_code)] #![allow(unused_imports, dead_code)]
use criterion::{criterion_group, criterion_main, Criterion}; use criterion::{criterion_group, criterion_main, Criterion};
use ruma_common::{ use ruma_common::serde::Raw;
events::{ use ruma_events::{
room::power_levels::RoomPowerLevelsEventContent, AnyStateEvent, AnyTimelineEvent, room::power_levels::RoomPowerLevelsEventContent, AnyStateEvent, AnyTimelineEvent,
OriginalStateEvent, OriginalStateEvent,
},
serde::Raw,
}; };
use serde_json::json; use serde_json::json;

View File

@ -1,3 +1,4 @@
use ruma_common::RoomVersionId;
use serde::Serialize; use serde::Serialize;
use serde_json::value::RawValue as RawJsonValue; use serde_json::value::RawValue as RawJsonValue;
@ -9,7 +10,6 @@ use super::{
RoomAccountDataEventType, StateEventContent, StateEventType, StaticStateEventContent, RoomAccountDataEventType, StateEventContent, StateEventType, StaticStateEventContent,
ToDeviceEventContent, ToDeviceEventType, ToDeviceEventContent, ToDeviceEventType,
}; };
use crate::RoomVersionId;
macro_rules! custom_event_content { macro_rules! custom_event_content {
($i:ident, $evt:ident) => { ($i:ident, $evt:ident) => {

View File

@ -48,7 +48,7 @@ pub struct AudioEventContent {
#[cfg(feature = "unstable-msc3955")] #[cfg(feature = "unstable-msc3955")]
#[serde( #[serde(
default, default,
skip_serializing_if = "crate::serde::is_default", skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated" rename = "org.matrix.msc1767.automated"
)] )]
pub automated: bool, pub automated: bool,
@ -57,7 +57,7 @@ pub struct AudioEventContent {
#[serde( #[serde(
flatten, flatten,
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
deserialize_with = "crate::events::room::message::relation_serde::deserialize_relation" deserialize_with = "crate::room::message::relation_serde::deserialize_relation"
)] )]
pub relates_to: Option<Relation<AudioEventContentWithoutRelation>>, pub relates_to: Option<Relation<AudioEventContentWithoutRelation>>,
} }

View File

@ -2,13 +2,13 @@
//! //!
//! [`m.call.answer`]: https://spec.matrix.org/latest/client-server-api/#mcallanswer //! [`m.call.answer`]: https://spec.matrix.org/latest/client-server-api/#mcallanswer
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-msc2747")] #[cfg(feature = "unstable-msc2747")]
use super::CallCapabilities; use super::CallCapabilities;
use super::SessionDescription; use super::SessionDescription;
use crate::{OwnedVoipId, VoipVersionId};
/// The content of an `m.call.answer` event. /// The content of an `m.call.answer` event.
/// ///

View File

@ -3,11 +3,10 @@
//! [`m.call.candidates`]: https://spec.matrix.org/latest/client-server-api/#mcallcandidates //! [`m.call.candidates`]: https://spec.matrix.org/latest/client-server-api/#mcallcandidates
use js_int::UInt; use js_int::UInt;
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{OwnedVoipId, VoipVersionId};
/// The content of an `m.call.candidates` event. /// The content of an `m.call.candidates` event.
/// ///
/// This event is sent by callers after sending an invite and by the callee after answering. Its /// This event is sent by callers after sending an invite and by the callee after answering. Its

View File

@ -2,10 +2,11 @@
//! //!
//! [`m.call.hangup`]: https://spec.matrix.org/latest/client-server-api/#mcallhangup //! [`m.call.hangup`]: https://spec.matrix.org/latest/client-server-api/#mcallhangup
use ruma_common::{serde::StringEnum, OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{serde::StringEnum, OwnedVoipId, PrivOwnedStr, VoipVersionId}; use crate::PrivOwnedStr;
/// The content of an `m.call.hangup` event. /// The content of an `m.call.hangup` event.
/// ///

View File

@ -3,13 +3,13 @@
//! [`m.call.invite`]: https://spec.matrix.org/latest/client-server-api/#mcallinvite //! [`m.call.invite`]: https://spec.matrix.org/latest/client-server-api/#mcallinvite
use js_int::UInt; use js_int::UInt;
use ruma_common::{OwnedUserId, OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-msc2747")] #[cfg(feature = "unstable-msc2747")]
use super::CallCapabilities; use super::CallCapabilities;
use super::SessionDescription; use super::SessionDescription;
use crate::{OwnedUserId, OwnedVoipId, VoipVersionId};
/// The content of an `m.call.invite` event. /// The content of an `m.call.invite` event.
/// ///

View File

@ -3,11 +3,11 @@
//! [`m.call.negotiate`]: https://spec.matrix.org/latest/client-server-api/#mcallnegotiate //! [`m.call.negotiate`]: https://spec.matrix.org/latest/client-server-api/#mcallnegotiate
use js_int::UInt; use js_int::UInt;
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::SessionDescription; use super::SessionDescription;
use crate::{OwnedVoipId, VoipVersionId};
/// **Added in VoIP version 1.** The content of an `m.call.negotiate` event. /// **Added in VoIP version 1.** The content of an `m.call.negotiate` event.
/// ///

View File

@ -2,11 +2,10 @@
//! //!
//! [`m.call.reject`]: https://spec.matrix.org/latest/client-server-api/#mcallreject //! [`m.call.reject`]: https://spec.matrix.org/latest/client-server-api/#mcallreject
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{OwnedVoipId, VoipVersionId};
/// **Added in VoIP version 1.** The content of an `m.call.reject` event. /// **Added in VoIP version 1.** The content of an `m.call.reject` event.
/// ///
/// Starting from VoIP version 1, this event is sent by the callee to reject an invite. /// Starting from VoIP version 1, this event is sent by the callee to reject an invite.

View File

@ -2,11 +2,10 @@
//! //!
//! [`m.call.select_answer`]: https://spec.matrix.org/latest/client-server-api/#mcallselect_answer //! [`m.call.select_answer`]: https://spec.matrix.org/latest/client-server-api/#mcallselect_answer
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{OwnedVoipId, VoipVersionId};
/// **Added in VoIP version 1.** The content of an `m.call.select_answer` event. /// **Added in VoIP version 1.** The content of an `m.call.select_answer` event.
/// ///
/// This event is sent by the caller when it has chosen an answer. /// This event is sent by the caller when it has chosen an answer.

View File

@ -1,5 +1,6 @@
use std::fmt; use std::fmt;
use ruma_common::serde::{CanBeEmpty, Raw};
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
use serde_json::{from_str as from_json_str, value::RawValue as RawJsonValue}; use serde_json::{from_str as from_json_str, value::RawValue as RawJsonValue};
@ -7,7 +8,6 @@ use super::{
EphemeralRoomEventType, GlobalAccountDataEventType, MessageLikeEventType, EphemeralRoomEventType, GlobalAccountDataEventType, MessageLikeEventType,
RoomAccountDataEventType, StateEventType, ToDeviceEventType, RoomAccountDataEventType, StateEventType, ToDeviceEventType,
}; };
use crate::serde::{CanBeEmpty, Raw};
/// The base trait that all event content types implement. /// The base trait that all event content types implement.
/// ///
@ -22,13 +22,17 @@ pub trait EventContent: Sized + Serialize {
fn event_type(&self) -> Self::EventType; fn event_type(&self) -> Self::EventType;
} }
impl<T> Raw<T> pub trait RawExt<T: EventContentFromType> {
/// Try to deserialize the JSON as an event's content with the given event type.
fn deserialize_with_type(&self, event_type: T::EventType) -> serde_json::Result<T>;
}
impl<T> RawExt<T> for Raw<T>
where where
T: EventContentFromType, T: EventContentFromType,
T::EventType: fmt::Display, T::EventType: fmt::Display,
{ {
/// Try to deserialize the JSON as an event's content with the given event type. fn deserialize_with_type(&self, event_type: T::EventType) -> serde_json::Result<T> {
pub fn deserialize_with_type(&self, event_type: T::EventType) -> serde_json::Result<T> {
T::from_parts(&event_type.to_string(), self.json()) T::from_parts(&event_type.to_string(), self.json())
} }
} }

View File

@ -7,11 +7,10 @@ use std::{
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
}; };
use ruma_common::{OwnedRoomId, OwnedUserId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{OwnedRoomId, OwnedUserId};
/// The content of an `m.direct` event. /// The content of an `m.direct` event.
/// ///
/// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that particular /// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that particular
@ -59,18 +58,18 @@ impl FromIterator<(OwnedUserId, Vec<OwnedRoomId>)> for DirectEventContent {
mod tests { mod tests {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use ruma_common::{owned_room_id, owned_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};
use super::{DirectEvent, DirectEventContent}; use super::{DirectEvent, DirectEventContent};
use crate::{room_id, user_id};
#[test] #[test]
fn serialization() { fn serialization() {
let mut content = DirectEventContent(BTreeMap::new()); let mut content = DirectEventContent(BTreeMap::new());
let alice = user_id!("@alice:ruma.io"); let alice = owned_user_id!("@alice:ruma.io");
let rooms = vec![room_id!("!1:ruma.io").to_owned()]; let rooms = vec![owned_room_id!("!1:ruma.io")];
content.insert(alice.to_owned(), rooms.clone()); content.insert(alice.clone(), rooms.clone());
let json_data = json!({ let json_data = json!({
alice: rooms, alice: rooms,
@ -81,8 +80,8 @@ mod tests {
#[test] #[test]
fn deserialization() { fn deserialization() {
let alice = user_id!("@alice:ruma.io").to_owned(); let alice = owned_user_id!("@alice:ruma.io");
let rooms = vec![room_id!("!1:ruma.io").to_owned(), room_id!("!2:ruma.io").to_owned()]; let rooms = vec![owned_room_id!("!1:ruma.io"), owned_room_id!("!2:ruma.io")];
let json_data = json!({ let json_data = json!({
"content": { "content": {

View File

@ -2,7 +2,7 @@
This function requires an [`OriginalRoomMessageEvent`] since it creates a permalink to This function requires an [`OriginalRoomMessageEvent`] since it creates a permalink to
the previous message, for which the room ID is required. If you want to reply to an the previous message, for which the room ID is required. If you want to reply to an
[`OriginalSyncRoomMessageEvent`], you have to convert it first by calling [`OriginalSyncRoomMessageEvent`], you have to convert it first by calling
[`.into_full_event()`][crate::events::OriginalSyncMessageLikeEvent::into_full_event]. [`.into_full_event()`][crate::OriginalSyncMessageLikeEvent::into_full_event].
If the message was edited, the previous message should be the original message that was edited, If the message was edited, the previous message should be the original message that was edited,
with the content of its replacement, to allow the fallback to be accurate at the time it is added. with the content of its replacement, to allow the fallback to be accurate at the time it is added.

View File

@ -0,0 +1,5 @@
<!-- Keep this comment so the content is always included as a new paragraph -->
This type can hold an arbitrary string. To build this with a custom value, convert it from a
string with `::from()` / `.into()`. To check for values that are not available as a
documented variant here, use its string representation, obtained through
[`.as_str()`](Self::as_str()).

View File

@ -29,7 +29,7 @@ pub struct EmoteEventContent {
#[cfg(feature = "unstable-msc3955")] #[cfg(feature = "unstable-msc3955")]
#[serde( #[serde(
default, default,
skip_serializing_if = "crate::serde::is_default", skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated" rename = "org.matrix.msc1767.automated"
)] )]
pub automated: bool, pub automated: bool,
@ -38,7 +38,7 @@ pub struct EmoteEventContent {
#[serde( #[serde(
flatten, flatten,
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
deserialize_with = "crate::events::room::message::relation_serde::deserialize_relation" deserialize_with = "crate::room::message::relation_serde::deserialize_relation"
)] )]
pub relates_to: Option<Relation<EmoteEventContentWithoutRelation>>, pub relates_to: Option<Relation<EmoteEventContentWithoutRelation>>,
} }

View File

@ -1,12 +1,12 @@
use ruma_common::{
serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, RoomId,
TransactionId, UserId,
};
use ruma_macros::{event_enum, EventEnumFromEvent}; use ruma_macros::{event_enum, EventEnumFromEvent};
use serde::{de, Deserialize}; use serde::{de, Deserialize};
use serde_json::value::RawValue as RawJsonValue; use serde_json::value::RawValue as RawJsonValue;
use super::room::encrypted; use super::room::encrypted;
use crate::{
serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, RoomId,
TransactionId, UserId,
};
event_enum! { event_enum! {
/// Any global account data event. /// Any global account data event.

View File

@ -5,6 +5,7 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use js_int::UInt; use js_int::UInt;
use ruma_common::{serde::Base64, OwnedMxcUri};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -12,7 +13,6 @@ use super::{
message::TextContentBlock, message::TextContentBlock,
room::{message::Relation, EncryptedFile, JsonWebKey}, room::{message::Relation, EncryptedFile, JsonWebKey},
}; };
use crate::{serde::Base64, OwnedMxcUri};
/// The payload for an extensible file message. /// The payload for an extensible file message.
/// ///
@ -41,7 +41,7 @@ pub struct FileEventContent {
#[cfg(feature = "unstable-msc3955")] #[cfg(feature = "unstable-msc3955")]
#[serde( #[serde(
default, default,
skip_serializing_if = "crate::serde::is_default", skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated" rename = "org.matrix.msc1767.automated"
)] )]
pub automated: bool, pub automated: bool,
@ -50,7 +50,7 @@ pub struct FileEventContent {
#[serde( #[serde(
flatten, flatten,
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
deserialize_with = "crate::events::room::message::relation_serde::deserialize_relation" deserialize_with = "crate::room::message::relation_serde::deserialize_relation"
)] )]
pub relates_to: Option<Relation<FileEventContentWithoutRelation>>, pub relates_to: Option<Relation<FileEventContentWithoutRelation>>,
} }

View File

@ -2,11 +2,10 @@
//! //!
//! [`m.forwarded_room_key`]: https://spec.matrix.org/latest/client-server-api/#mforwarded_room_key //! [`m.forwarded_room_key`]: https://spec.matrix.org/latest/client-server-api/#mforwarded_room_key
use ruma_common::{EventEncryptionAlgorithm, OwnedRoomId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{EventEncryptionAlgorithm, OwnedRoomId};
/// The content of an `m.forwarded_room_key` event. /// The content of an `m.forwarded_room_key` event.
/// ///
/// To create an instance of this type, first create a `ToDeviceForwardedRoomKeyEventContentInit` /// To create an instance of this type, first create a `ToDeviceForwardedRoomKeyEventContentInit`

View File

@ -2,11 +2,10 @@
//! //!
//! [`m.fully_read`]: https://spec.matrix.org/latest/client-server-api/#mfully_read //! [`m.fully_read`]: https://spec.matrix.org/latest/client-server-api/#mfully_read
use ruma_common::OwnedEventId;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::OwnedEventId;
/// The content of an `m.fully_read` event. /// The content of an `m.fully_read` event.
/// ///
/// The current location of the user's read marker in a room. /// The current location of the user's read marker in a room.

View File

@ -4,11 +4,10 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use ruma_common::OwnedUserId;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::OwnedUserId;
/// The content of an `m.ignored_user_list` event. /// The content of an `m.ignored_user_list` event.
/// ///
/// A list of users to ignore. /// A list of users to ignore.
@ -52,10 +51,11 @@ impl IgnoredUser {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use ruma_common::{owned_user_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};
use super::IgnoredUserListEventContent; use super::IgnoredUserListEventContent;
use crate::{events::AnyGlobalAccountDataEvent, owned_user_id, user_id}; use crate::AnyGlobalAccountDataEvent;
#[test] #[test]
fn serialization() { fn serialization() {

View File

@ -5,6 +5,7 @@
use std::ops::Deref; use std::ops::Deref;
use js_int::UInt; use js_int::UInt;
use ruma_common::OwnedMxcUri;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -13,7 +14,6 @@ use super::{
message::TextContentBlock, message::TextContentBlock,
room::message::Relation, room::message::Relation,
}; };
use crate::OwnedMxcUri;
/// The payload for an extensible image message. /// The payload for an extensible image message.
/// ///
@ -62,7 +62,7 @@ pub struct ImageEventContent {
#[cfg(feature = "unstable-msc3955")] #[cfg(feature = "unstable-msc3955")]
#[serde( #[serde(
default, default,
skip_serializing_if = "crate::serde::is_default", skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated" rename = "org.matrix.msc1767.automated"
)] )]
pub automated: bool, pub automated: bool,
@ -71,7 +71,7 @@ pub struct ImageEventContent {
#[serde( #[serde(
flatten, flatten,
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
deserialize_with = "crate::events::room::message::relation_serde::deserialize_relation" deserialize_with = "crate::room::message::relation_serde::deserialize_relation"
)] )]
pub relates_to: Option<Relation<ImageEventContentWithoutRelation>>, pub relates_to: Option<Relation<ImageEventContentWithoutRelation>>,
} }
@ -124,7 +124,7 @@ pub struct ImageDetailsContentBlock {
#[serde( #[serde(
rename = "org.matrix.msc1767.sticker", rename = "org.matrix.msc1767.sticker",
default, default,
skip_serializing_if = "crate::serde::is_default" skip_serializing_if = "ruma_common::serde::is_default"
)] )]
pub sticker: bool, pub sticker: bool,
} }

View File

@ -9,7 +9,9 @@
use std::time::Duration; use std::time::Duration;
use crate::{serde::StringEnum, PrivOwnedStr}; use ruma_common::serde::StringEnum;
use crate::PrivOwnedStr;
pub mod accept; pub mod accept;
pub mod cancel; pub mod cancel;

View File

@ -4,6 +4,7 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use ruma_common::{serde::Base64, OwnedTransactionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
@ -11,7 +12,7 @@ use serde_json::Value as JsonValue;
use super::{ use super::{
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString, HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString,
}; };
use crate::{events::relation::Reference, serde::Base64, OwnedTransactionId}; use crate::relation::Reference;
/// The content of a to-device `m.key.verification.accept` event. /// The content of a to-device `m.key.verification.accept` event.
/// ///
@ -164,6 +165,7 @@ mod tests {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use ruma_common::{event_id, serde::Base64};
use serde_json::{ use serde_json::{
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue, from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
}; };
@ -173,11 +175,7 @@ mod tests {
MessageAuthenticationCode, SasV1Content, ShortAuthenticationString, MessageAuthenticationCode, SasV1Content, ShortAuthenticationString,
ToDeviceKeyVerificationAcceptEventContent, _CustomContent, ToDeviceKeyVerificationAcceptEventContent, _CustomContent,
}; };
use crate::{ use crate::{relation::Reference, ToDeviceEvent};
event_id,
events::{relation::Reference, ToDeviceEvent},
serde::Base64,
};
#[test] #[test]
fn serialization() { fn serialization() {

View File

@ -2,10 +2,11 @@
//! //!
//! [`m.key.verification.cancel`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationcancel //! [`m.key.verification.cancel`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationcancel
use ruma_common::{serde::StringEnum, OwnedTransactionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{events::relation::Reference, serde::StringEnum, OwnedTransactionId, PrivOwnedStr}; use crate::{relation::Reference, PrivOwnedStr};
/// The content of a to-device `m.key.verification.cancel` event. /// The content of a to-device `m.key.verification.cancel` event.
/// ///

View File

@ -2,10 +2,11 @@
//! //!
//! [`m.key.verification.done`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationdone //! [`m.key.verification.done`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationdone
use ruma_common::OwnedTransactionId;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{events::relation::Reference, OwnedTransactionId}; use crate::relation::Reference;
/// The content of a to-device `m.m.key.verification.done` event. /// The content of a to-device `m.m.key.verification.done` event.
/// ///
@ -48,10 +49,11 @@ impl KeyVerificationDoneEventContent {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ruma_common::owned_event_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};
use super::KeyVerificationDoneEventContent; use super::KeyVerificationDoneEventContent;
use crate::{events::relation::Reference, owned_event_id}; use crate::relation::Reference;
#[test] #[test]
fn serialization() { fn serialization() {

View File

@ -2,10 +2,11 @@
//! //!
//! [`m.key.verification.key`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationkey //! [`m.key.verification.key`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationkey
use ruma_common::{serde::Base64, OwnedTransactionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{events::relation::Reference, serde::Base64, OwnedTransactionId}; use crate::relation::Reference;
/// The content of a to-device `m.key.verification.key` event. /// The content of a to-device `m.key.verification.key` event.
/// ///

View File

@ -4,10 +4,11 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use ruma_common::{serde::Base64, OwnedTransactionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{events::relation::Reference, serde::Base64, OwnedTransactionId}; use crate::relation::Reference;
/// The content of a to-device `m.key.verification.` event. /// The content of a to-device `m.key.verification.` event.
/// ///

View File

@ -2,11 +2,12 @@
//! //!
//! [`m.key.verification.ready`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationready //! [`m.key.verification.ready`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationready
use ruma_common::{OwnedDeviceId, OwnedTransactionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::VerificationMethod; use super::VerificationMethod;
use crate::{events::relation::Reference, OwnedDeviceId, OwnedTransactionId}; use crate::relation::Reference;
/// The content of a to-device `m.m.key.verification.ready` event. /// The content of a to-device `m.m.key.verification.ready` event.
/// ///
@ -74,13 +75,11 @@ impl KeyVerificationReadyEventContent {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ruma_common::{owned_event_id, OwnedDeviceId};
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::{KeyVerificationReadyEventContent, ToDeviceKeyVerificationReadyEventContent}; use super::{KeyVerificationReadyEventContent, ToDeviceKeyVerificationReadyEventContent};
use crate::{ use crate::{key::verification::VerificationMethod, relation::Reference};
events::{key::verification::VerificationMethod, relation::Reference},
owned_event_id, OwnedDeviceId,
};
#[test] #[test]
fn serialization() { fn serialization() {

View File

@ -2,11 +2,11 @@
//! //!
//! [`m.key.verification.request`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationrequest //! [`m.key.verification.request`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationrequest
use ruma_common::{MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedTransactionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::VerificationMethod; use super::VerificationMethod;
use crate::{MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedTransactionId};
/// The content of an `m.key.verification.request` event. /// The content of an `m.key.verification.request` event.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]

View File

@ -4,6 +4,7 @@
use std::{collections::BTreeMap, fmt}; use std::{collections::BTreeMap, fmt};
use ruma_common::{serde::Base64, OwnedDeviceId, OwnedTransactionId};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
@ -11,7 +12,7 @@ use serde_json::Value as JsonValue;
use super::{ use super::{
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString, HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString,
}; };
use crate::{events::relation::Reference, serde::Base64, OwnedDeviceId, OwnedTransactionId}; use crate::relation::Reference;
/// The content of a to-device `m.key.verification.start` event. /// The content of a to-device `m.key.verification.start` event.
/// ///
@ -209,6 +210,7 @@ mod tests {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use assert_matches2::assert_matches; use assert_matches2::assert_matches;
use ruma_common::{event_id, serde::Base64};
use serde_json::{ use serde_json::{
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue, from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
}; };
@ -219,11 +221,7 @@ mod tests {
ShortAuthenticationString, StartMethod, ToDeviceKeyVerificationStartEventContent, ShortAuthenticationString, StartMethod, ToDeviceKeyVerificationStartEventContent,
_CustomContent, _CustomContent,
}; };
use crate::{ use crate::{relation::Reference, ToDeviceEvent};
event_id,
events::{relation::Reference, ToDeviceEvent},
serde::Base64,
};
#[test] #[test]
fn serialization() { fn serialization() {

View File

@ -1,5 +1,10 @@
#![allow(clippy::exhaustive_structs)] #![allow(clippy::exhaustive_structs)]
use ruma_common::{
serde::{from_raw_json_value, Raw},
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId,
RoomVersionId, UserId,
};
use ruma_macros::Event; use ruma_macros::Event;
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize}; use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize};
use serde_json::value::RawValue as RawJsonValue; use serde_json::value::RawValue as RawJsonValue;
@ -12,11 +17,6 @@ use super::{
RedactionDeHelper, RoomAccountDataEventContent, StateEventType, StaticStateEventContent, RedactionDeHelper, RoomAccountDataEventContent, StateEventType, StaticStateEventContent,
ToDeviceEventContent, ToDeviceEventContent,
}; };
use crate::{
serde::{from_raw_json_value, Raw},
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId,
RoomVersionId, UserId,
};
/// A global account data event. /// A global account data event.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]

View File

@ -24,7 +24,7 @@
//! specifies the state event's `type` and its `kind`. //! specifies the state event's `type` and its `kind`.
//! //!
//! ```rust //! ```rust
//! use ruma_common::events::macros::EventContent; //! use ruma_events::macros::EventContent;
//! use serde::{Deserialize, Serialize}; //! use serde::{Deserialize, Serialize};
//! //!
//! #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] //! #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
@ -41,10 +41,8 @@
//! [`OriginalSyncMessageLikeEvent`] struct but any [`OriginalMessageLikeEvent`] struct would work. //! [`OriginalSyncMessageLikeEvent`] struct but any [`OriginalMessageLikeEvent`] struct would work.
//! //!
//! ```rust //! ```rust
//! use ruma_common::{ //! use ruma_common::OwnedEventId;
//! events::{macros::EventContent, OriginalSyncMessageLikeEvent}, //! use ruma_events::{macros::EventContent, OriginalSyncMessageLikeEvent};
//! OwnedEventId,
//! };
//! use serde::{Deserialize, Serialize}; //! use serde::{Deserialize, Serialize};
//! //!
//! #[derive(Clone, Debug, Deserialize, Serialize)] //! #[derive(Clone, Debug, Deserialize, Serialize)]
@ -102,12 +100,11 @@
//! )); //! ));
//! ``` //! ```
use std::collections::BTreeSet; use std::{collections::BTreeSet, fmt};
use ruma_common::{EventEncryptionAlgorithm, OwnedUserId, RoomVersionId};
use serde::{de::IgnoredAny, Deserialize, Serialize, Serializer}; use serde::{de::IgnoredAny, Deserialize, Serialize, Serializer};
use crate::{EventEncryptionAlgorithm, OwnedUserId, RoomVersionId};
// Needs to be public for trybuild tests // Needs to be public for trybuild tests
#[doc(hidden)] #[doc(hidden)]
pub mod _custom; pub mod _custom;
@ -117,6 +114,20 @@ mod kinds;
mod state_key; mod state_key;
mod unsigned; mod unsigned;
// So event macros work inside this crate.
extern crate self as ruma_events;
/// Re-exports used by macro-generated code.
///
/// It is not considered part of this module's public API.
#[doc(hidden)]
pub mod exports {
pub use ruma_common;
pub use ruma_macros;
pub use serde;
pub use serde_json;
}
/// Re-export of all the derives needed to create your own event types. /// Re-export of all the derives needed to create your own event types.
pub mod macros { pub mod macros {
pub use ruma_macros::{Event, EventContent}; pub use ruma_macros::{Event, EventContent};
@ -240,7 +251,7 @@ pub struct Mentions {
/// Whether the whole room is mentioned. /// Whether the whole room is mentioned.
/// ///
/// Defaults to `false`. /// Defaults to `false`.
#[serde(default, skip_serializing_if = "crate::serde::is_default")] #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
pub room: bool, pub room: bool,
} }
@ -260,3 +271,16 @@ impl Mentions {
Self { room: true, ..Default::default() } Self { room: true, ..Default::default() }
} }
} }
// Wrapper around `Box<str>` that cannot be used in a meaningful way outside of
// this crate. Used for string enums because their `_Custom` variant can't be
// truly private (only `#[doc(hidden)]`).
#[doc(hidden)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PrivOwnedStr(Box<str>);
impl fmt::Debug for PrivOwnedStr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

View File

@ -8,8 +8,10 @@ use serde::{Deserialize, Serialize};
mod zoomlevel_serde; mod zoomlevel_serde;
use ruma_common::MilliSecondsSinceUnixEpoch;
use super::{message::TextContentBlock, room::message::Relation}; use super::{message::TextContentBlock, room::message::Relation};
use crate::{MilliSecondsSinceUnixEpoch, PrivOwnedStr}; use crate::PrivOwnedStr;
/// The payload for an extensible location message. /// The payload for an extensible location message.
/// ///
@ -42,7 +44,7 @@ pub struct LocationEventContent {
#[cfg(feature = "unstable-msc3955")] #[cfg(feature = "unstable-msc3955")]
#[serde( #[serde(
default, default,
skip_serializing_if = "crate::serde::is_default", skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated" rename = "org.matrix.msc1767.automated"
)] )]
pub automated: bool, pub automated: bool,
@ -51,7 +53,7 @@ pub struct LocationEventContent {
#[serde( #[serde(
flatten, flatten,
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
deserialize_with = "crate::events::room::message::relation_serde::deserialize_relation" deserialize_with = "crate::room::message::relation_serde::deserialize_relation"
)] )]
pub relates_to: Option<Relation<LocationEventContentWithoutRelation>>, pub relates_to: Option<Relation<LocationEventContentWithoutRelation>>,
} }

View File

@ -110,7 +110,7 @@ pub struct MessageEventContent {
#[cfg(feature = "unstable-msc3955")] #[cfg(feature = "unstable-msc3955")]
#[serde( #[serde(
default, default,
skip_serializing_if = "crate::serde::is_default", skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated" rename = "org.matrix.msc1767.automated"
)] )]
pub automated: bool, pub automated: bool,
@ -119,7 +119,7 @@ pub struct MessageEventContent {
#[serde( #[serde(
flatten, flatten,
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
deserialize_with = "crate::events::room::message::relation_serde::deserialize_relation" deserialize_with = "crate::room::message::relation_serde::deserialize_relation"
)] )]
pub relates_to: Option<Relation<MessageEventContentWithoutRelation>>, pub relates_to: Option<Relation<MessageEventContentWithoutRelation>>,
} }

View File

@ -10,7 +10,7 @@ use super::{TextContentBlock, TextRepresentation};
#[derive(Clone, Default, Serialize, Deserialize)] #[derive(Clone, Default, Serialize, Deserialize)]
#[serde(try_from = "MessageContentBlockSerDeHelper")] #[serde(try_from = "MessageContentBlockSerDeHelper")]
#[serde(into = "MessageContentBlockSerDeHelper")] #[serde(into = "MessageContentBlockSerDeHelper")]
pub(in crate::events) struct MessageContentBlock(Vec<TextRepresentation>); pub(crate) struct MessageContentBlock(Vec<TextRepresentation>);
impl From<MessageContentBlock> for TextContentBlock { impl From<MessageContentBlock> for TextContentBlock {
fn from(value: MessageContentBlock) -> Self { fn from(value: MessageContentBlock) -> Self {
@ -25,7 +25,7 @@ impl From<TextContentBlock> for MessageContentBlock {
} }
#[derive(Default, Serialize, Deserialize)] #[derive(Default, Serialize, Deserialize)]
pub(in crate::events) struct MessageContentBlockSerDeHelper { pub(crate) struct MessageContentBlockSerDeHelper {
/// Plain text short form. /// Plain text short form.
#[serde(rename = "org.matrix.msc1767.text", skip_serializing_if = "Option::is_none")] #[serde(rename = "org.matrix.msc1767.text", skip_serializing_if = "Option::is_none")]
text: Option<String>, text: Option<String>,

View File

@ -8,6 +8,10 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use js_int::UInt; use js_int::UInt;
use ruma_common::{
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName,
OwnedServerSigningKeyId, OwnedUserId,
};
use serde::{ use serde::{
de::{Error as _, IgnoredAny}, de::{Error as _, IgnoredAny},
Deserialize, Deserializer, Serialize, Deserialize, Deserializer, Serialize,
@ -15,10 +19,6 @@ use serde::{
use serde_json::{from_str as from_json_str, value::RawValue as RawJsonValue}; use serde_json::{from_str as from_json_str, value::RawValue as RawJsonValue};
use super::TimelineEventType; use super::TimelineEventType;
use crate::{
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedServerName,
OwnedServerSigningKeyId, OwnedUserId,
};
/// Enum for PDU schemas /// Enum for PDU schemas
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Serialize)]

View File

@ -1,8 +1,9 @@
//! Modules and types for events in the `m.policy.rule` namespace. //! Modules and types for events in the `m.policy.rule` namespace.
use ruma_common::serde::StringEnum;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{serde::StringEnum, PrivOwnedStr}; use crate::PrivOwnedStr;
pub mod room; pub mod room;
pub mod server; pub mod server;

View File

@ -6,7 +6,7 @@ use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{PolicyRuleEventContent, PossiblyRedactedPolicyRuleEventContent}; use super::{PolicyRuleEventContent, PossiblyRedactedPolicyRuleEventContent};
use crate::events::{EventContent, PossiblyRedactedStateEventContent, StateEventType}; use crate::{EventContent, PossiblyRedactedStateEventContent, StateEventType};
/// The content of an `m.policy.rule.room` event. /// The content of an `m.policy.rule.room` event.
/// ///
@ -37,13 +37,11 @@ impl PossiblyRedactedStateEventContent for PossiblyRedactedPolicyRuleRoomEventCo
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ruma_common::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};
use super::{OriginalPolicyRuleRoomEvent, PolicyRuleRoomEventContent}; use super::{OriginalPolicyRuleRoomEvent, PolicyRuleRoomEventContent};
use crate::{ use crate::policy::rule::{PolicyRuleEventContent, Recommendation};
events::policy::rule::{PolicyRuleEventContent, Recommendation},
serde::Raw,
};
#[test] #[test]
fn serialization() { fn serialization() {

View File

@ -6,7 +6,7 @@ use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{PolicyRuleEventContent, PossiblyRedactedPolicyRuleEventContent}; use super::{PolicyRuleEventContent, PossiblyRedactedPolicyRuleEventContent};
use crate::events::{EventContent, PossiblyRedactedStateEventContent, StateEventType}; use crate::{EventContent, PossiblyRedactedStateEventContent, StateEventType};
/// The content of an `m.policy.rule.server` event. /// The content of an `m.policy.rule.server` event.
/// ///

View File

@ -6,7 +6,7 @@ use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{PolicyRuleEventContent, PossiblyRedactedPolicyRuleEventContent}; use super::{PolicyRuleEventContent, PossiblyRedactedPolicyRuleEventContent};
use crate::events::{EventContent, PossiblyRedactedStateEventContent, StateEventType}; use crate::{EventContent, PossiblyRedactedStateEventContent, StateEventType};
/// The content of an `m.policy.rule.user` event. /// The content of an `m.policy.rule.user` event.
/// ///

View File

@ -11,9 +11,9 @@ use std::{
use indexmap::IndexMap; use indexmap::IndexMap;
use js_int::{uint, UInt}; use js_int::{uint, UInt};
use ruma_common::{MilliSecondsSinceUnixEpoch, UserId};
use self::{start::PollContentBlock, unstable_start::UnstablePollStartContentBlock}; use self::{start::PollContentBlock, unstable_start::UnstablePollStartContentBlock};
use crate::{MilliSecondsSinceUnixEpoch, UserId};
pub mod end; pub mod end;
pub mod response; pub mod response;

View File

@ -6,13 +6,11 @@ use std::{
}; };
use js_int::UInt; use js_int::UInt;
use ruma_common::OwnedEventId;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{ use crate::{message::TextContentBlock, relation::Reference};
events::{message::TextContentBlock, relation::Reference},
OwnedEventId,
};
/// The payload for a poll end event. /// The payload for a poll end event.
/// ///
@ -43,7 +41,7 @@ pub struct PollEndEventContent {
#[cfg(feature = "unstable-msc3955")] #[cfg(feature = "unstable-msc3955")]
#[serde( #[serde(
default, default,
skip_serializing_if = "crate::serde::is_default", skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated" rename = "org.matrix.msc1767.automated"
)] )]
pub automated: bool, pub automated: bool,

View File

@ -2,11 +2,12 @@
use std::{ops::Deref, vec}; use std::{ops::Deref, vec};
use ruma_common::OwnedEventId;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{start::PollContentBlock, validate_selections, PollResponseData}; use super::{start::PollContentBlock, validate_selections, PollResponseData};
use crate::{events::relation::Reference, OwnedEventId}; use crate::relation::Reference;
/// The payload for a poll response event. /// The payload for a poll response event.
/// ///
@ -29,7 +30,7 @@ pub struct PollResponseEventContent {
#[cfg(feature = "unstable-msc3955")] #[cfg(feature = "unstable-msc3955")]
#[serde( #[serde(
default, default,
skip_serializing_if = "crate::serde::is_default", skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated" rename = "org.matrix.msc1767.automated"
)] )]
pub automated: bool, pub automated: bool,

View File

@ -3,9 +3,12 @@
use std::ops::Deref; use std::ops::Deref;
use js_int::{uint, UInt}; use js_int::{uint, UInt};
use ruma_common::{serde::StringEnum, MilliSecondsSinceUnixEpoch};
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::PrivOwnedStr;
mod poll_answers_serde; mod poll_answers_serde;
use poll_answers_serde::PollAnswersDeHelper; use poll_answers_serde::PollAnswersDeHelper;
@ -15,11 +18,7 @@ use super::{
end::{PollEndEventContent, PollResultsContentBlock}, end::{PollEndEventContent, PollResultsContentBlock},
generate_poll_end_fallback_text, PollResponseData, generate_poll_end_fallback_text, PollResponseData,
}; };
use crate::{ use crate::{message::TextContentBlock, room::message::Relation};
events::{message::TextContentBlock, room::message::Relation},
serde::StringEnum,
MilliSecondsSinceUnixEpoch, PrivOwnedStr,
};
/// The payload for a poll start event. /// The payload for a poll start event.
/// ///
@ -46,7 +45,7 @@ pub struct PollStartEventContent {
#[serde( #[serde(
flatten, flatten,
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
deserialize_with = "crate::events::room::message::relation_serde::deserialize_relation" deserialize_with = "crate::room::message::relation_serde::deserialize_relation"
)] )]
pub relates_to: Option<Relation<PollStartEventContentWithoutRelation>>, pub relates_to: Option<Relation<PollStartEventContentWithoutRelation>>,
@ -54,7 +53,7 @@ pub struct PollStartEventContent {
#[cfg(feature = "unstable-msc3955")] #[cfg(feature = "unstable-msc3955")]
#[serde( #[serde(
default, default,
skip_serializing_if = "crate::serde::is_default", skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated" rename = "org.matrix.msc1767.automated"
)] )]
pub automated: bool, pub automated: bool,
@ -133,7 +132,7 @@ pub struct PollContentBlock {
pub question: PollQuestion, pub question: PollQuestion,
/// The kind of the poll. /// The kind of the poll.
#[serde(default, skip_serializing_if = "crate::serde::is_default")] #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
pub kind: PollKind, pub kind: PollKind,
/// The maximum number of responses a user is able to select. /// The maximum number of responses a user is able to select.

View File

@ -1,9 +1,10 @@
//! Types for the `org.matrix.msc3381.poll.end` event, the unstable version of `m.poll.end`. //! Types for the `org.matrix.msc3381.poll.end` event, the unstable version of `m.poll.end`.
use ruma_common::OwnedEventId;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{events::relation::Reference, OwnedEventId}; use crate::relation::Reference;
/// The payload for an unstable poll end event. /// The payload for an unstable poll end event.
/// ///

View File

@ -1,11 +1,12 @@
//! Types for the `org.matrix.msc3381.poll.response` event, the unstable version of //! Types for the `org.matrix.msc3381.poll.response` event, the unstable version of
//! `m.poll.response`. //! `m.poll.response`.
use ruma_common::OwnedEventId;
use ruma_macros::EventContent; use ruma_macros::EventContent;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{unstable_start::UnstablePollStartContentBlock, validate_selections, PollResponseData}; use super::{unstable_start::UnstablePollStartContentBlock, validate_selections, PollResponseData};
use crate::{events::relation::Reference, OwnedEventId}; use crate::relation::Reference;
/// The payload for an unstable poll response event. /// The payload for an unstable poll response event.
/// ///

Some files were not shown because too many files have changed in this diff Show More