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-client = { version = "0.11.0", path = "crates/ruma-client" }
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-html = { version = "0.1.0", path = "crates/ruma-html" }
ruma-identifiers-validation = { version = "0.9.1", path = "crates/ruma-identifiers-validation" }

View File

@ -24,7 +24,8 @@ unstable-msc3202 = []
[dependencies]
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_json = { workspace = true }

View File

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

View File

@ -102,7 +102,7 @@ Improvements:
* Add `ErrorKind::{UnableToAuthorizeJoin, UnableToGrantJoin}` encountered for restricted rooms
* Add support for timestamp massaging (MSC3316)
* 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 `SpaceRoomJoinRule::KnockRestricted` (MSC3787)
* Add unstable support for private read receipts (MSC2285)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,11 +11,11 @@ pub mod v3 {
use ruma_common::{
api::{response, Metadata},
events::{AnyStateEventContent, StateEventContent, StateEventType},
metadata,
serde::Raw,
MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId,
};
use ruma_events::{AnyStateEventContent, StateEventContent, StateEventType};
use serde_json::value::to_raw_value as to_raw_json_value;
const METADATA: Metadata = metadata! {
@ -209,9 +209,9 @@ pub mod v3 {
fn serialize() {
use ruma_common::{
api::{MatrixVersion, OutgoingRequest as _, SendAccessToken},
events::{room::name::RoomNameEventContent, EmptyStateKey},
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
let req = Request::new(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,12 +11,12 @@ pub mod v3 {
use ruma_common::{
api::{request, response, Metadata},
events::{AnyToDeviceEventContent, ToDeviceEventType},
metadata,
serde::Raw,
to_device::DeviceIdOrAllDevices,
OwnedTransactionId, OwnedUserId,
};
use ruma_events::{AnyToDeviceEventContent, ToDeviceEventType};
const METADATA: Metadata = metadata! {
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.
- Move the HTML functions in `events::room::message::sanitize` to the ruma-html crate
- 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:

View File

@ -23,31 +23,13 @@ server = []
api = ["dep:http", "dep:konst"]
canonical-json = []
events = []
html = ["dep:ruma-html"]
js = ["dep:js-sys", "getrandom?/js", "uuid?/js"]
markdown = ["pulldown-cmark"]
rand = ["dep:rand", "dep:uuid"]
unstable-exhaustive-types = []
unstable-msc1767 = []
unstable-msc2448 = []
unstable-msc2747 = []
unstable-msc2870 = []
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-msc3381 = []
unstable-msc3931 = []
unstable-msc3932 = ["unstable-msc3931"]
unstable-msc3954 = ["unstable-msc1767"]
unstable-msc3955 = ["unstable-msc1767"]
unstable-msc3956 = ["unstable-msc1767"]
unstable-pdu = []
unstable-unspecified = []
# 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.
compat-optional = []
# Allow TagInfo to contain a stringified floating-point value for the `order` field.
compat-tag-info = []
[dependencies]
base64 = { workspace = true }
bytes = "1.0.1"
@ -80,13 +59,10 @@ getrandom = { version = "0.2.6", optional = true }
http = { workspace = true, optional = true }
indexmap = { version = "2.0.0", 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 }
percent-encoding = "2.1.0"
pulldown-cmark = { version = "0.9.1", default-features = false, optional = true }
rand = { version = "0.8.3", optional = true }
regex = { version = "1.5.6", default-features = false, features = ["std", "perf"] }
ruma-html = { workspace = true, optional = true }
ruma-identifiers-validation = { workspace = true }
ruma-macros = { workspace = true }
serde = { workspace = true }
@ -98,20 +74,11 @@ url = "2.2.2"
uuid = { version = "1.0.0", optional = true, features = ["v4"] }
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]
js-sys = { version = "0.3", 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", "events"]

View File

@ -8,15 +8,7 @@ use serde_json::Value as JsonValue;
mod value;
pub use self::value::{CanonicalJsonObject, CanonicalJsonValue};
use crate::RoomVersionId;
#[cfg(feature = "events")]
use crate::{
events::room::redaction::{
OriginalRoomRedactionEvent, OriginalSyncRoomRedactionEvent, RoomRedactionEvent,
SyncRoomRedactionEvent,
},
serde::Raw,
};
use crate::{serde::Raw, RoomVersionId};
/// The set of possible errors when serializing to 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`.
///
/// See `From` implementations for ways to create an instance of this type.
#[derive(Clone, Debug)]
pub struct RedactedBecause(CanonicalJsonObject);
impl From<CanonicalJsonObject> for RedactedBecause {
fn from(obj: CanonicalJsonObject) -> Self {
impl RedactedBecause {
/// Create a `RedactedBecause` from an arbitrary JSON object.
pub fn from_json(obj: CanonicalJsonObject) -> Self {
Self(obj)
}
}
#[cfg(feature = "events")]
impl TryFrom<&Raw<OriginalRoomRedactionEvent>> for RedactedBecause {
type Error = serde_json::Error;
fn try_from(value: &Raw<OriginalRoomRedactionEvent>) -> Result<Self, Self::Error> {
value.deserialize_as().map(Self)
/// Create a `RedactedBecause` from a redaction event.
///
/// Fails if the raw event is not valid canonical JSON.
pub fn from_raw_event(ev: &Raw<impl RedactionEvent>) -> serde_json::Result<Self> {
ev.deserialize_as().map(Self)
}
}
#[cfg(feature = "events")]
impl TryFrom<&Raw<OriginalSyncRoomRedactionEvent>> for RedactedBecause {
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)
}
}
/// Marker trait for redaction events.
pub trait RedactionEvent {}
/// 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 directory;
pub mod encryption;
#[cfg(feature = "events")]
pub mod events;
mod identifiers;
mod percent_encode;
pub mod power_levels;

View File

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

View File

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

View File

@ -1,11 +1,9 @@
#![allow(clippy::exhaustive_structs)]
#[cfg(feature = "events")]
pub mod some_endpoint {
use http::header::CONTENT_TYPE;
use ruma_common::{
api::{request, response, Metadata},
events::{tag::TagEvent, AnyTimelineEvent},
metadata,
serde::Raw,
OwnedUserId,
@ -55,11 +53,14 @@ pub mod some_endpoint {
pub optional_flag: Option<bool>,
// 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.
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 {

View File

@ -1,7 +1,6 @@
use http::header::CONTENT_TYPE;
use ruma_common::{
api::{request, response, Metadata},
events::{tag::TagEvent, AnyTimelineEvent},
metadata,
serde::Raw,
};
@ -54,12 +53,15 @@ pub struct Response {
pub optional_flag: Option<bool>,
// 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.
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() {
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 events;
mod identifiers;
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)]
use criterion::{criterion_group, criterion_main, Criterion};
use ruma_common::{
events::{
use ruma_common::serde::Raw;
use ruma_events::{
room::power_levels::RoomPowerLevelsEventContent, AnyStateEvent, AnyTimelineEvent,
OriginalStateEvent,
},
serde::Raw,
};
use serde_json::json;

View File

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

View File

@ -48,7 +48,7 @@ pub struct AudioEventContent {
#[cfg(feature = "unstable-msc3955")]
#[serde(
default,
skip_serializing_if = "crate::serde::is_default",
skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated"
)]
pub automated: bool,
@ -57,7 +57,7 @@ pub struct AudioEventContent {
#[serde(
flatten,
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>>,
}

View File

@ -2,13 +2,13 @@
//!
//! [`m.call.answer`]: https://spec.matrix.org/latest/client-server-api/#mcallanswer
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-msc2747")]
use super::CallCapabilities;
use super::SessionDescription;
use crate::{OwnedVoipId, VoipVersionId};
/// 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
use js_int::UInt;
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::{OwnedVoipId, VoipVersionId};
/// 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

View File

@ -2,10 +2,11 @@
//!
//! [`m.call.hangup`]: https://spec.matrix.org/latest/client-server-api/#mcallhangup
use ruma_common::{serde::StringEnum, OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::{serde::StringEnum, OwnedVoipId, PrivOwnedStr, VoipVersionId};
use crate::PrivOwnedStr;
/// 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
use js_int::UInt;
use ruma_common::{OwnedUserId, OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-msc2747")]
use super::CallCapabilities;
use super::SessionDescription;
use crate::{OwnedUserId, OwnedVoipId, VoipVersionId};
/// 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
use js_int::UInt;
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::SessionDescription;
use crate::{OwnedVoipId, VoipVersionId};
/// **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
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::{OwnedVoipId, VoipVersionId};
/// **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.

View File

@ -2,11 +2,10 @@
//!
//! [`m.call.select_answer`]: https://spec.matrix.org/latest/client-server-api/#mcallselect_answer
use ruma_common::{OwnedVoipId, VoipVersionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::{OwnedVoipId, VoipVersionId};
/// **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.

View File

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

View File

@ -7,11 +7,10 @@ use std::{
ops::{Deref, DerefMut},
};
use ruma_common::{OwnedRoomId, OwnedUserId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::{OwnedRoomId, OwnedUserId};
/// 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
@ -59,18 +58,18 @@ impl FromIterator<(OwnedUserId, Vec<OwnedRoomId>)> for DirectEventContent {
mod tests {
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 super::{DirectEvent, DirectEventContent};
use crate::{room_id, user_id};
#[test]
fn serialization() {
let mut content = DirectEventContent(BTreeMap::new());
let alice = user_id!("@alice:ruma.io");
let rooms = vec![room_id!("!1:ruma.io").to_owned()];
let alice = owned_user_id!("@alice:ruma.io");
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!({
alice: rooms,
@ -81,8 +80,8 @@ mod tests {
#[test]
fn deserialization() {
let alice = user_id!("@alice:ruma.io").to_owned();
let rooms = vec![room_id!("!1:ruma.io").to_owned(), room_id!("!2:ruma.io").to_owned()];
let alice = owned_user_id!("@alice:ruma.io");
let rooms = vec![owned_room_id!("!1:ruma.io"), owned_room_id!("!2:ruma.io")];
let json_data = json!({
"content": {

View File

@ -2,7 +2,7 @@
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
[`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,
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")]
#[serde(
default,
skip_serializing_if = "crate::serde::is_default",
skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated"
)]
pub automated: bool,
@ -38,7 +38,7 @@ pub struct EmoteEventContent {
#[serde(
flatten,
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>>,
}

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 serde::{de, Deserialize};
use serde_json::value::RawValue as RawJsonValue;
use super::room::encrypted;
use crate::{
serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, RoomId,
TransactionId, UserId,
};
event_enum! {
/// Any global account data event.

View File

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

View File

@ -2,11 +2,10 @@
//!
//! [`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 serde::{Deserialize, Serialize};
use crate::{EventEncryptionAlgorithm, OwnedRoomId};
/// The content of an `m.forwarded_room_key` event.
///
/// 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
use ruma_common::OwnedEventId;
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::OwnedEventId;
/// The content of an `m.fully_read` event.
///
/// The current location of the user's read marker in a room.

View File

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

View File

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

View File

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

View File

@ -4,6 +4,7 @@
use std::collections::BTreeMap;
use ruma_common::{serde::Base64, OwnedTransactionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
@ -11,7 +12,7 @@ use serde_json::Value as JsonValue;
use super::{
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.
///
@ -164,6 +165,7 @@ mod tests {
use std::collections::BTreeMap;
use assert_matches2::assert_matches;
use ruma_common::{event_id, serde::Base64};
use serde_json::{
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,
ToDeviceKeyVerificationAcceptEventContent, _CustomContent,
};
use crate::{
event_id,
events::{relation::Reference, ToDeviceEvent},
serde::Base64,
};
use crate::{relation::Reference, ToDeviceEvent};
#[test]
fn serialization() {

View File

@ -2,10 +2,11 @@
//!
//! [`m.key.verification.cancel`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationcancel
use ruma_common::{serde::StringEnum, OwnedTransactionId};
use ruma_macros::EventContent;
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.
///

View File

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

View File

@ -2,10 +2,11 @@
//!
//! [`m.key.verification.key`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationkey
use ruma_common::{serde::Base64, OwnedTransactionId};
use ruma_macros::EventContent;
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.
///

View File

@ -4,10 +4,11 @@
use std::collections::BTreeMap;
use ruma_common::{serde::Base64, OwnedTransactionId};
use ruma_macros::EventContent;
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.
///

View File

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

View File

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

View File

@ -4,6 +4,7 @@
use std::{collections::BTreeMap, fmt};
use ruma_common::{serde::Base64, OwnedDeviceId, OwnedTransactionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
@ -11,7 +12,7 @@ use serde_json::Value as JsonValue;
use super::{
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.
///
@ -209,6 +210,7 @@ mod tests {
use std::collections::BTreeMap;
use assert_matches2::assert_matches;
use ruma_common::{event_id, serde::Base64};
use serde_json::{
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,
_CustomContent,
};
use crate::{
event_id,
events::{relation::Reference, ToDeviceEvent},
serde::Base64,
};
use crate::{relation::Reference, ToDeviceEvent};
#[test]
fn serialization() {

View File

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

View File

@ -24,7 +24,7 @@
//! specifies the state event's `type` and its `kind`.
//!
//! ```rust
//! use ruma_common::events::macros::EventContent;
//! use ruma_events::macros::EventContent;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
@ -41,10 +41,8 @@
//! [`OriginalSyncMessageLikeEvent`] struct but any [`OriginalMessageLikeEvent`] struct would work.
//!
//! ```rust
//! use ruma_common::{
//! events::{macros::EventContent, OriginalSyncMessageLikeEvent},
//! OwnedEventId,
//! };
//! use ruma_common::OwnedEventId;
//! use ruma_events::{macros::EventContent, OriginalSyncMessageLikeEvent};
//! use serde::{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 crate::{EventEncryptionAlgorithm, OwnedUserId, RoomVersionId};
// Needs to be public for trybuild tests
#[doc(hidden)]
pub mod _custom;
@ -117,6 +114,20 @@ mod kinds;
mod state_key;
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.
pub mod macros {
pub use ruma_macros::{Event, EventContent};
@ -240,7 +251,7 @@ pub struct Mentions {
/// Whether the whole room is mentioned.
///
/// 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,
}
@ -260,3 +271,16 @@ impl Mentions {
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;
use ruma_common::MilliSecondsSinceUnixEpoch;
use super::{message::TextContentBlock, room::message::Relation};
use crate::{MilliSecondsSinceUnixEpoch, PrivOwnedStr};
use crate::PrivOwnedStr;
/// The payload for an extensible location message.
///
@ -42,7 +44,7 @@ pub struct LocationEventContent {
#[cfg(feature = "unstable-msc3955")]
#[serde(
default,
skip_serializing_if = "crate::serde::is_default",
skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated"
)]
pub automated: bool,
@ -51,7 +53,7 @@ pub struct LocationEventContent {
#[serde(
flatten,
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>>,
}

View File

@ -110,7 +110,7 @@ pub struct MessageEventContent {
#[cfg(feature = "unstable-msc3955")]
#[serde(
default,
skip_serializing_if = "crate::serde::is_default",
skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated"
)]
pub automated: bool,
@ -119,7 +119,7 @@ pub struct MessageEventContent {
#[serde(
flatten,
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>>,
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,9 +3,12 @@
use std::ops::Deref;
use js_int::{uint, UInt};
use ruma_common::{serde::StringEnum, MilliSecondsSinceUnixEpoch};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::PrivOwnedStr;
mod poll_answers_serde;
use poll_answers_serde::PollAnswersDeHelper;
@ -15,11 +18,7 @@ use super::{
end::{PollEndEventContent, PollResultsContentBlock},
generate_poll_end_fallback_text, PollResponseData,
};
use crate::{
events::{message::TextContentBlock, room::message::Relation},
serde::StringEnum,
MilliSecondsSinceUnixEpoch, PrivOwnedStr,
};
use crate::{message::TextContentBlock, room::message::Relation};
/// The payload for a poll start event.
///
@ -46,7 +45,7 @@ pub struct PollStartEventContent {
#[serde(
flatten,
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>>,
@ -54,7 +53,7 @@ pub struct PollStartEventContent {
#[cfg(feature = "unstable-msc3955")]
#[serde(
default,
skip_serializing_if = "crate::serde::is_default",
skip_serializing_if = "ruma_common::serde::is_default",
rename = "org.matrix.msc1767.automated"
)]
pub automated: bool,
@ -133,7 +132,7 @@ pub struct PollContentBlock {
pub question: PollQuestion,
/// 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,
/// 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`.
use ruma_common::OwnedEventId;
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::{events::relation::Reference, OwnedEventId};
use crate::relation::Reference;
/// 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
//! `m.poll.response`.
use ruma_common::OwnedEventId;
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
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.
///

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