Use thirdparty network types into ruma_common
This commit is contained in:
parent
daf37063aa
commit
da78e215f8
@ -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<String>,
|
||||
/// Fields which may be used to identify a third party location.
|
||||
pub location_fields: Vec<String>,
|
||||
/// 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<String, FieldType>,
|
||||
/// A list of objects representing independent instances of configuration.
|
||||
pub instances: Vec<ProtocolInstance>,
|
||||
}
|
||||
|
||||
/// 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<String>,
|
||||
/// Preset values for `fields` the client may use to search by.
|
||||
pub fields: BTreeMap<String, String>,
|
||||
/// 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<String, String>,
|
||||
}
|
||||
|
||||
/// 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<String, String>,
|
||||
}
|
||||
|
@ -3,8 +3,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use super::Location;
|
||||
use ruma_common::thirdparty::Location;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
|
@ -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.",
|
||||
|
@ -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: {
|
||||
|
@ -3,8 +3,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use super::User;
|
||||
use ruma_common::thirdparty::User;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
|
@ -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.",
|
||||
|
@ -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: {
|
||||
|
@ -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: {
|
||||
|
@ -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.",
|
||||
|
@ -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.
|
||||
|
@ -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 =
|
||||
|
@ -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.",
|
||||
|
@ -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)]
|
||||
|
@ -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<String>,
|
||||
|
||||
/// Fields which may be used to identify a third party location.
|
||||
pub location_fields: Vec<String>,
|
||||
|
||||
/// 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<String, FieldType>,
|
||||
|
||||
/// A list of objects representing independent instances of configuration.
|
||||
pub instances: Vec<ProtocolInstance>,
|
||||
}
|
||||
|
||||
/// 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<String>,
|
||||
|
||||
/// Preset values for `fields` the client may use to search by.
|
||||
pub fields: BTreeMap<String, String>,
|
||||
|
||||
/// 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<String, String>,
|
||||
}
|
||||
|
||||
/// 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<String, String>,
|
||||
}
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
@ -3,8 +3,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use super::Location;
|
||||
use ruma_common::thirdparty::Location;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
|
@ -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.",
|
||||
|
@ -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: {
|
||||
|
@ -3,8 +3,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use super::Protocol;
|
||||
use ruma_common::thirdparty::Protocol;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
|
@ -3,8 +3,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
use super::User;
|
||||
use ruma_common::thirdparty::User;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
|
@ -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.",
|
||||
|
@ -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"] }
|
||||
|
@ -5,5 +5,6 @@
|
||||
pub mod presence;
|
||||
pub mod push;
|
||||
mod raw;
|
||||
pub mod thirdparty;
|
||||
|
||||
pub use self::raw::Raw;
|
||||
|
92
ruma-common/src/thirdparty.rs
Normal file
92
ruma-common/src/thirdparty.rs
Normal file
@ -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<String>,
|
||||
|
||||
/// Fields which may be used to identify a third party location.
|
||||
pub location_fields: Vec<String>,
|
||||
|
||||
/// 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<String, FieldType>,
|
||||
|
||||
/// A list of objects representing independent instances of configuration.
|
||||
pub instances: Vec<ProtocolInstance>,
|
||||
}
|
||||
|
||||
/// 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<String>,
|
||||
|
||||
/// Preset values for `fields` the client may use to search by.
|
||||
pub fields: BTreeMap<String, String>,
|
||||
|
||||
/// 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<String, String>,
|
||||
}
|
||||
|
||||
/// 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<String, String>,
|
||||
}
|
||||
|
||||
/// 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,
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user