diff --git a/ruma-appservice-api/src/v1/thirdparty.rs b/ruma-appservice-api/src/v1/thirdparty.rs index 16e40245..8bc39466 100644 --- a/ruma-appservice-api/src/v1/thirdparty.rs +++ b/ruma-appservice-api/src/v1/thirdparty.rs @@ -5,69 +5,3 @@ pub mod get_location_for_room_alias; pub mod get_protocol; pub mod get_user_for_protocol; pub mod get_user_for_user_id; - -use std::collections::BTreeMap; - -use ruma_identifiers::{RoomAliasId, UserId}; - -use serde::{Deserialize, Serialize}; - -/// Metadata about a third party protocol. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct Protocol { - /// Fields which may be used to identify a third party user. - pub user_fields: Vec, - /// Fields which may be used to identify a third party location. - pub location_fields: Vec, - /// A content URI representing an icon for the third party protocol. - pub icon: String, - /// The type definitions for the fields defined in `user_fields` and `location_fields`. - pub field_types: BTreeMap, - /// A list of objects representing independent instances of configuration. - pub instances: Vec, -} - -/// Metadata about an instance of a third party protocol. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct ProtocolInstance { - /// A human-readable description for the protocol, such as the name. - pub desc: String, - /// An optional content URI representing the protocol. - #[serde(skip_serializing_if = "Option::is_none")] - pub icon: Option, - /// Preset values for `fields` the client may use to search by. - pub fields: BTreeMap, - /// A unique identifier across all instances. - pub network_id: String, -} - -/// A type definition for a field used to identify third party users or locations. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct FieldType { - /// A regular expression for validation of a field's value. - pub regexp: String, - /// A placeholder serving as a valid example of the field value. - pub placeholder: String, -} - -/// A third party network location. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct Location { - /// An alias for a matrix room. - pub alias: RoomAliasId, - /// The protocol ID that the third party location is a part of. - pub protocol: String, - /// Information used to identify this third party location. - pub fields: BTreeMap, -} - -/// A third party network user. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct User { - /// A matrix user ID representing a third party user. - pub userid: UserId, - /// The protocol ID that the third party user is a part of. - pub protocol: String, - /// Information used to identify this third party user. - pub fields: BTreeMap, -} diff --git a/ruma-appservice-api/src/v1/thirdparty/get_location_for_protocol.rs b/ruma-appservice-api/src/v1/thirdparty/get_location_for_protocol.rs index a1624e1b..818a2018 100644 --- a/ruma-appservice-api/src/v1/thirdparty/get_location_for_protocol.rs +++ b/ruma-appservice-api/src/v1/thirdparty/get_location_for_protocol.rs @@ -3,8 +3,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; - -use super::Location; +use ruma_common::thirdparty::Location; ruma_api! { metadata: { diff --git a/ruma-appservice-api/src/v1/thirdparty/get_location_for_room_alias.rs b/ruma-appservice-api/src/v1/thirdparty/get_location_for_room_alias.rs index 8cf6752c..bdcd0beb 100644 --- a/ruma-appservice-api/src/v1/thirdparty/get_location_for_room_alias.rs +++ b/ruma-appservice-api/src/v1/thirdparty/get_location_for_room_alias.rs @@ -1,10 +1,9 @@ //! [GET /_matrix/app/v1/thirdparty/location](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-thirdparty-location) use ruma_api::ruma_api; +use ruma_common::thirdparty::Location; use ruma_identifiers::RoomAliasId; -use super::Location; - ruma_api! { metadata: { description: "Retrieve an array of third party network locations from a Matrix room alias.", diff --git a/ruma-appservice-api/src/v1/thirdparty/get_protocol.rs b/ruma-appservice-api/src/v1/thirdparty/get_protocol.rs index 509c9c58..ae105910 100644 --- a/ruma-appservice-api/src/v1/thirdparty/get_protocol.rs +++ b/ruma-appservice-api/src/v1/thirdparty/get_protocol.rs @@ -1,8 +1,7 @@ //! [GET /_matrix/app/v1/thirdparty/protocol/{protocol}](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-thirdparty-protocol-protocol) use ruma_api::ruma_api; - -use super::Protocol; +use ruma_common::thirdparty::Protocol; ruma_api! { metadata: { diff --git a/ruma-appservice-api/src/v1/thirdparty/get_user_for_protocol.rs b/ruma-appservice-api/src/v1/thirdparty/get_user_for_protocol.rs index 782200f0..202a4b04 100644 --- a/ruma-appservice-api/src/v1/thirdparty/get_user_for_protocol.rs +++ b/ruma-appservice-api/src/v1/thirdparty/get_user_for_protocol.rs @@ -3,8 +3,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; - -use super::User; +use ruma_common::thirdparty::User; ruma_api! { metadata: { diff --git a/ruma-appservice-api/src/v1/thirdparty/get_user_for_user_id.rs b/ruma-appservice-api/src/v1/thirdparty/get_user_for_user_id.rs index 7f145257..8b8c8b80 100644 --- a/ruma-appservice-api/src/v1/thirdparty/get_user_for_user_id.rs +++ b/ruma-appservice-api/src/v1/thirdparty/get_user_for_user_id.rs @@ -1,10 +1,9 @@ //! [GET /_matrix/app/v1/thirdparty/user](https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-thirdparty-user) use ruma_api::ruma_api; +use ruma_common::thirdparty::User; use ruma_identifiers::UserId; -use super::User; - ruma_api! { metadata: { description: "Retrieve an array of third party users from a Matrix User ID.", diff --git a/ruma-client-api/src/r0/account/delete_3pid.rs b/ruma-client-api/src/r0/account/delete_3pid.rs index f35e4997..3ea33efc 100644 --- a/ruma-client-api/src/r0/account/delete_3pid.rs +++ b/ruma-client-api/src/r0/account/delete_3pid.rs @@ -1,9 +1,9 @@ //! [POST /_matrix/client/r0/account/3pid/delete](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-delete) use ruma_api::ruma_api; +use ruma_common::thirdparty::Medium; use super::ThirdPartyIdRemovalStatus; -use crate::r0::thirdparty::Medium; ruma_api! { metadata: { diff --git a/ruma-client-api/src/r0/account/unbind_3pid.rs b/ruma-client-api/src/r0/account/unbind_3pid.rs index 92c00a5e..b3c73b18 100644 --- a/ruma-client-api/src/r0/account/unbind_3pid.rs +++ b/ruma-client-api/src/r0/account/unbind_3pid.rs @@ -1,9 +1,9 @@ //! [POST /_matrix/client/r0/account/3pid/unbind](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-unbind) use ruma_api::ruma_api; +use ruma_common::thirdparty::Medium; use super::ThirdPartyIdRemovalStatus; -use crate::r0::thirdparty::Medium; ruma_api! { metadata: { diff --git a/ruma-client-api/src/r0/contact/get_contacts.rs b/ruma-client-api/src/r0/contact/get_contacts.rs index 4e5c3600..792f69d7 100644 --- a/ruma-client-api/src/r0/contact/get_contacts.rs +++ b/ruma-client-api/src/r0/contact/get_contacts.rs @@ -3,10 +3,9 @@ use std::time::SystemTime; use ruma_api::ruma_api; +use ruma_common::thirdparty::Medium; use serde::{Deserialize, Serialize}; -use crate::r0::thirdparty::Medium; - ruma_api! { metadata: { description: "Get a list of 3rd party contacts associated with the user's account.", diff --git a/ruma-client-api/src/r0/membership.rs b/ruma-client-api/src/r0/membership.rs index 85dc443d..47e5f429 100644 --- a/ruma-client-api/src/r0/membership.rs +++ b/ruma-client-api/src/r0/membership.rs @@ -14,10 +14,9 @@ pub mod unban_user; use std::collections::BTreeMap; -use serde::{Deserialize, Serialize}; - -use crate::r0::thirdparty::Medium; +use ruma_common::thirdparty::Medium; use ruma_identifiers::{ServerKeyId, ServerName}; +use serde::{Deserialize, Serialize}; /// A signature of an `m.third_party_invite` token to prove that this user owns a third party /// identity which has been invited to the room. diff --git a/ruma-client-api/src/r0/membership/invite_user.rs b/ruma-client-api/src/r0/membership/invite_user.rs index 2380c459..d70623c0 100644 --- a/ruma-client-api/src/r0/membership/invite_user.rs +++ b/ruma-client-api/src/r0/membership/invite_user.rs @@ -53,11 +53,13 @@ pub enum InvitationRecipient { #[cfg(test)] mod tests { + use ruma_common::thirdparty::Medium; use ruma_identifiers::user_id; use serde_json::{from_value as from_json_value, json}; use super::InvitationRecipient; - use crate::r0::{membership::Invite3pid, thirdparty::Medium}; + use crate::r0::membership::Invite3pid; + #[test] fn deserialize_invite_by_user_id() { let incoming = diff --git a/ruma-client-api/src/r0/session/login.rs b/ruma-client-api/src/r0/session/login.rs index 623a5763..191c97b5 100644 --- a/ruma-client-api/src/r0/session/login.rs +++ b/ruma-client-api/src/r0/session/login.rs @@ -1,11 +1,10 @@ //! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-login) use ruma_api::ruma_api; +use ruma_common::thirdparty::Medium; use ruma_identifiers::{DeviceId, ServerName, UserId}; use serde::{Deserialize, Serialize}; -use crate::r0::thirdparty::Medium; - ruma_api! { metadata: { description: "Login to the homeserver.", diff --git a/ruma-client-api/src/r0/session/login/user_serde.rs b/ruma-client-api/src/r0/session/login/user_serde.rs index ee32d546..efdefa08 100644 --- a/ruma-client-api/src/r0/session/login/user_serde.rs +++ b/ruma-client-api/src/r0/session/login/user_serde.rs @@ -1,10 +1,9 @@ //! Helper module for the Serialize / Deserialize impl's for the User struct //! in the parent module. +use ruma_common::thirdparty::Medium; use serde::{Deserialize, Serialize}; -use super::Medium; - // The following three structs could just be used in place of the one in the parent module, but // that one is arguably much easier to deal with. #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] diff --git a/ruma-client-api/src/r0/thirdparty.rs b/ruma-client-api/src/r0/thirdparty.rs index 91f890e2..9d5b8963 100644 --- a/ruma-client-api/src/r0/thirdparty.rs +++ b/ruma-client-api/src/r0/thirdparty.rs @@ -6,92 +6,3 @@ pub mod get_protocol; pub mod get_protocols; pub mod get_user_for_protocol; pub mod get_user_for_user_id; - -use std::collections::BTreeMap; - -use ruma_identifiers::{RoomAliasId, UserId}; - -use serde::{Deserialize, Serialize}; - -/// Metadata about a third party protocol. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct Protocol { - /// Fields which may be used to identify a third party user. - pub user_fields: Vec, - - /// Fields which may be used to identify a third party location. - pub location_fields: Vec, - - /// A content URI representing an icon for the third party protocol. - pub icon: String, - - /// The type definitions for the fields defined in `user_fields` and `location_fields`. - pub field_types: BTreeMap, - - /// A list of objects representing independent instances of configuration. - pub instances: Vec, -} - -/// Metadata about an instance of a third party protocol. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct ProtocolInstance { - /// A human-readable description for the protocol, such as the name. - pub desc: String, - - /// An optional content URI representing the protocol. - #[serde(skip_serializing_if = "Option::is_none")] - pub icon: Option, - - /// Preset values for `fields` the client may use to search by. - pub fields: BTreeMap, - - /// A unique identifier across all instances. - pub network_id: String, -} - -/// A type definition for a field used to identify third party users or locations. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct FieldType { - /// A regular expression for validation of a field's value. - pub regexp: String, - - /// A placeholder serving as a valid example of the field value. - pub placeholder: String, -} - -/// A third party network location. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct Location { - /// An alias for a matrix room. - pub alias: RoomAliasId, - - /// The protocol ID that the third party location is a part of. - pub protocol: String, - - /// Information used to identify this third party location. - pub fields: BTreeMap, -} - -/// A third party network user. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct User { - /// A matrix user ID representing a third party user. - pub userid: UserId, - - /// The protocol ID that the third party user is a part of. - pub protocol: String, - - /// Information used to identify this third party user. - pub fields: BTreeMap, -} - -/// The medium of a third party identifier. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] -#[serde(rename_all = "lowercase")] -pub enum Medium { - /// Email address identifier - Email, - - /// Phone number identifier - MSISDN, -} diff --git a/ruma-client-api/src/r0/thirdparty/get_location_for_protocol.rs b/ruma-client-api/src/r0/thirdparty/get_location_for_protocol.rs index f624c140..d5356a02 100644 --- a/ruma-client-api/src/r0/thirdparty/get_location_for_protocol.rs +++ b/ruma-client-api/src/r0/thirdparty/get_location_for_protocol.rs @@ -3,8 +3,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; - -use super::Location; +use ruma_common::thirdparty::Location; ruma_api! { metadata: { diff --git a/ruma-client-api/src/r0/thirdparty/get_location_for_room_alias.rs b/ruma-client-api/src/r0/thirdparty/get_location_for_room_alias.rs index 7b88a7d6..7ec7d1a1 100644 --- a/ruma-client-api/src/r0/thirdparty/get_location_for_room_alias.rs +++ b/ruma-client-api/src/r0/thirdparty/get_location_for_room_alias.rs @@ -1,10 +1,9 @@ //! [GET /_matrix/client/r0/thirdparty/location](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-location) use ruma_api::ruma_api; +use ruma_common::thirdparty::Location; use ruma_identifiers::RoomAliasId; -use super::Location; - ruma_api! { metadata: { description: "Retrieve an array of third party network locations from a Matrix room alias.", diff --git a/ruma-client-api/src/r0/thirdparty/get_protocol.rs b/ruma-client-api/src/r0/thirdparty/get_protocol.rs index 3b3ee33d..5d759d6b 100644 --- a/ruma-client-api/src/r0/thirdparty/get_protocol.rs +++ b/ruma-client-api/src/r0/thirdparty/get_protocol.rs @@ -1,8 +1,7 @@ //! [GET /_matrix/client/r0/thirdparty/protocol/{protocol}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-protocol-protocol) use ruma_api::ruma_api; - -use super::Protocol; +use ruma_common::thirdparty::Protocol; ruma_api! { metadata: { diff --git a/ruma-client-api/src/r0/thirdparty/get_protocols.rs b/ruma-client-api/src/r0/thirdparty/get_protocols.rs index b006cc38..d7764aae 100644 --- a/ruma-client-api/src/r0/thirdparty/get_protocols.rs +++ b/ruma-client-api/src/r0/thirdparty/get_protocols.rs @@ -3,8 +3,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; - -use super::Protocol; +use ruma_common::thirdparty::Protocol; ruma_api! { metadata: { diff --git a/ruma-client-api/src/r0/thirdparty/get_user_for_protocol.rs b/ruma-client-api/src/r0/thirdparty/get_user_for_protocol.rs index 02e125c9..123828b7 100644 --- a/ruma-client-api/src/r0/thirdparty/get_user_for_protocol.rs +++ b/ruma-client-api/src/r0/thirdparty/get_user_for_protocol.rs @@ -3,8 +3,7 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; - -use super::User; +use ruma_common::thirdparty::User; ruma_api! { metadata: { diff --git a/ruma-client-api/src/r0/thirdparty/get_user_for_user_id.rs b/ruma-client-api/src/r0/thirdparty/get_user_for_user_id.rs index 52aeca2d..fe1e4b88 100644 --- a/ruma-client-api/src/r0/thirdparty/get_user_for_user_id.rs +++ b/ruma-client-api/src/r0/thirdparty/get_user_for_user_id.rs @@ -1,10 +1,9 @@ //! [GET /_matrix/client/r0/thirdparty/user](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-thirdparty-user) use ruma_api::ruma_api; +use ruma_common::thirdparty::User; use ruma_identifiers::UserId; -use super::User; - ruma_api! { metadata: { description: "Retrieve an array of third party users from a Matrix User ID.", diff --git a/ruma-common/Cargo.toml b/ruma-common/Cargo.toml index 8e769986..8f5dd9b0 100644 --- a/ruma-common/Cargo.toml +++ b/ruma-common/Cargo.toml @@ -12,6 +12,7 @@ edition = "2018" [dependencies] js_int = { version = "0.1.9", features = ["serde"] } +ruma-identifiers = { version = "0.17.4", path = "../ruma-identifiers" } ruma-serde = { version = "0.2.3", path = "../ruma-serde" } serde = { version = "1.0.114", features = ["derive"] } serde_json = { version = "1.0.57", features = ["raw_value"] } diff --git a/ruma-common/src/lib.rs b/ruma-common/src/lib.rs index 73e4467a..3f738d0a 100644 --- a/ruma-common/src/lib.rs +++ b/ruma-common/src/lib.rs @@ -5,5 +5,6 @@ pub mod presence; pub mod push; mod raw; +pub mod thirdparty; pub use self::raw::Raw; diff --git a/ruma-common/src/thirdparty.rs b/ruma-common/src/thirdparty.rs new file mode 100644 index 00000000..da88c3ae --- /dev/null +++ b/ruma-common/src/thirdparty.rs @@ -0,0 +1,92 @@ +//! Common types for the [third party networks module][thirdparty] +//! +//! [thirdparty]: https://matrix.org/docs/spec/client_server/r0.6.1#id153 + +use std::collections::BTreeMap; + +use ruma_identifiers::{RoomAliasId, UserId}; + +use serde::{Deserialize, Serialize}; + +/// Metadata about a third party protocol. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Protocol { + /// Fields which may be used to identify a third party user. + pub user_fields: Vec, + + /// Fields which may be used to identify a third party location. + pub location_fields: Vec, + + /// A content URI representing an icon for the third party protocol. + pub icon: String, + + /// The type definitions for the fields defined in `user_fields` and `location_fields`. + pub field_types: BTreeMap, + + /// A list of objects representing independent instances of configuration. + pub instances: Vec, +} + +/// Metadata about an instance of a third party protocol. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ProtocolInstance { + /// A human-readable description for the protocol, such as the name. + pub desc: String, + + /// An optional content URI representing the protocol. + #[serde(skip_serializing_if = "Option::is_none")] + pub icon: Option, + + /// Preset values for `fields` the client may use to search by. + pub fields: BTreeMap, + + /// A unique identifier across all instances. + pub network_id: String, +} + +/// A type definition for a field used to identify third party users or locations. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct FieldType { + /// A regular expression for validation of a field's value. + pub regexp: String, + + /// A placeholder serving as a valid example of the field value. + pub placeholder: String, +} + +/// A third party network location. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Location { + /// An alias for a matrix room. + pub alias: RoomAliasId, + + /// The protocol ID that the third party location is a part of. + pub protocol: String, + + /// Information used to identify this third party location. + pub fields: BTreeMap, +} + +/// A third party network user. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct User { + /// A matrix user ID representing a third party user. + pub userid: UserId, + + /// The protocol ID that the third party user is a part of. + pub protocol: String, + + /// Information used to identify this third party user. + pub fields: BTreeMap, +} + +/// The medium of a third party identifier. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum Medium { + /// Email address identifier + Email, + + /// Phone number identifier + MSISDN, +}