client-api: Update config and contact endpoints to the new API standards
This commit is contained in:
		
							parent
							
								
									cf9b83495c
								
							
						
					
					
						commit
						d1f409bcb6
					
				| @ -15,16 +15,18 @@ ruma_api! { | |||||||
|         requires_authentication: true, |         requires_authentication: true, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[non_exhaustive] | ||||||
|     request: { |     request: { | ||||||
|         /// User ID of user for whom to retrieve data.
 |         /// User ID of user for whom to retrieve data.
 | ||||||
|         #[ruma_api(path)] |         #[ruma_api(path)] | ||||||
|         pub user_id: UserId, |         pub user_id: &'a UserId, | ||||||
| 
 | 
 | ||||||
|         /// Type of data to retrieve.
 |         /// Type of data to retrieve.
 | ||||||
|         #[ruma_api(path)] |         #[ruma_api(path)] | ||||||
|         pub event_type: String, |         pub event_type: &'a str, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[non_exhaustive] | ||||||
|     response: { |     response: { | ||||||
|         /// Account data content for the given type.
 |         /// Account data content for the given type.
 | ||||||
|         #[ruma_api(body)] |         #[ruma_api(body)] | ||||||
| @ -33,3 +35,17 @@ ruma_api! { | |||||||
| 
 | 
 | ||||||
|     error: crate::Error |     error: crate::Error | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | impl<'a> Request<'a> { | ||||||
|  |     /// Creates a new `Request` with the given user ID and event type.
 | ||||||
|  |     pub fn new(user_id: &'a UserId, event_type: &'a str) -> Self { | ||||||
|  |         Self { user_id, event_type } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Response { | ||||||
|  |     /// Creates a new `Response` with the given account data.
 | ||||||
|  |     pub fn new(account_data: Raw<AnyBasicEvent>) -> Self { | ||||||
|  |         Self { account_data } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
| @ -15,20 +15,22 @@ ruma_api! { | |||||||
|         requires_authentication: true, |         requires_authentication: true, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[non_exhaustive] | ||||||
|     request: { |     request: { | ||||||
|         /// User ID of user for whom to retrieve data.
 |         /// User ID of user for whom to retrieve data.
 | ||||||
|         #[ruma_api(path)] |         #[ruma_api(path)] | ||||||
|         pub user_id: UserId, |         pub user_id: &'a UserId, | ||||||
| 
 | 
 | ||||||
|         /// Room ID for which to retrieve data.
 |         /// Room ID for which to retrieve data.
 | ||||||
|         #[ruma_api(path)] |         #[ruma_api(path)] | ||||||
|         pub room_id: RoomId, |         pub room_id: &'a RoomId, | ||||||
| 
 | 
 | ||||||
|         /// Type of data to retrieve.
 |         /// Type of data to retrieve.
 | ||||||
|         #[ruma_api(path)] |         #[ruma_api(path)] | ||||||
|         pub event_type: String, |         pub event_type: &'a str, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[non_exhaustive] | ||||||
|     response: { |     response: { | ||||||
|         /// Account data content for the given type.
 |         /// Account data content for the given type.
 | ||||||
|         #[ruma_api(body)] |         #[ruma_api(body)] | ||||||
| @ -37,3 +39,17 @@ ruma_api! { | |||||||
| 
 | 
 | ||||||
|     error: crate::Error |     error: crate::Error | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | impl<'a> Request<'a> { | ||||||
|  |     /// Creates a new `Request` with the given user ID, room ID and event type.
 | ||||||
|  |     pub fn new(user_id: &'a UserId, room_id: &'a RoomId, event_type: &'a str) -> Self { | ||||||
|  |         Self { user_id, room_id, event_type } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Response { | ||||||
|  |     /// Creates a new `Response` with the given account data.
 | ||||||
|  |     pub fn new(account_data: Raw<AnyBasicEvent>) -> Self { | ||||||
|  |         Self { account_data } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
| @ -14,6 +14,7 @@ ruma_api! { | |||||||
|         requires_authentication: true, |         requires_authentication: true, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[non_exhaustive] | ||||||
|     request: { |     request: { | ||||||
|         /// Arbitrary JSON to store as config data.
 |         /// Arbitrary JSON to store as config data.
 | ||||||
|         ///
 |         ///
 | ||||||
| @ -25,16 +26,32 @@ ruma_api! { | |||||||
|         ///
 |         ///
 | ||||||
|         /// Custom types should be namespaced to avoid clashes.
 |         /// Custom types should be namespaced to avoid clashes.
 | ||||||
|         #[ruma_api(path)] |         #[ruma_api(path)] | ||||||
|         pub event_type: String, |         pub event_type: &'a str, | ||||||
| 
 | 
 | ||||||
|         /// The ID of the user to set account_data for.
 |         /// The ID of the user to set account_data for.
 | ||||||
|         ///
 |         ///
 | ||||||
|         /// The access token must be authorized to make requests for this user ID.
 |         /// The access token must be authorized to make requests for this user ID.
 | ||||||
|         #[ruma_api(path)] |         #[ruma_api(path)] | ||||||
|         pub user_id: UserId, |         pub user_id: &'a UserId, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[derive(Default)] | ||||||
|  |     #[non_exhaustive] | ||||||
|     response: {} |     response: {} | ||||||
| 
 | 
 | ||||||
|     error: crate::Error |     error: crate::Error | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | impl<'a> Request<'a> { | ||||||
|  |     /// Creates a new `Request` with the given data, event type and user ID.
 | ||||||
|  |     pub fn new(data: Box<RawJsonValue>, event_type: &'a str, user_id: &'a UserId) -> Self { | ||||||
|  |         Self { data, event_type, user_id } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Response { | ||||||
|  |     /// Creates an empty `Response`.
 | ||||||
|  |     pub fn new() -> Self { | ||||||
|  |         Self | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
| @ -14,10 +14,11 @@ ruma_api! { | |||||||
|         requires_authentication: true, |         requires_authentication: true, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[non_exhaustive] | ||||||
|     request: { |     request: { | ||||||
|         /// Arbitrary JSON to store as config data.
 |         /// Arbitrary JSON to store as config data.
 | ||||||
|         ///
 |         ///
 | ||||||
|         /// To create a `Box<RawJsonValue>`, use `serde_json::value::to_raw_value`.
 |         /// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`.
 | ||||||
|         #[ruma_api(body)] |         #[ruma_api(body)] | ||||||
|         pub data: Box<RawJsonValue>, |         pub data: Box<RawJsonValue>, | ||||||
| 
 | 
 | ||||||
| @ -25,20 +26,41 @@ ruma_api! { | |||||||
|         ///
 |         ///
 | ||||||
|         /// Custom types should be namespaced to avoid clashes.
 |         /// Custom types should be namespaced to avoid clashes.
 | ||||||
|         #[ruma_api(path)] |         #[ruma_api(path)] | ||||||
|         pub event_type: String, |         pub event_type: &'a str, | ||||||
| 
 | 
 | ||||||
|         /// The ID of the room to set account_data on.
 |         /// The ID of the room to set account_data on.
 | ||||||
|         #[ruma_api(path)] |         #[ruma_api(path)] | ||||||
|         pub room_id: RoomId, |         pub room_id: &'a RoomId, | ||||||
| 
 | 
 | ||||||
|         /// The ID of the user to set account_data for.
 |         /// The ID of the user to set account_data for.
 | ||||||
|         ///
 |         ///
 | ||||||
|         /// The access token must be authorized to make requests for this user ID.
 |         /// The access token must be authorized to make requests for this user ID.
 | ||||||
|         #[ruma_api(path)] |         #[ruma_api(path)] | ||||||
|         pub user_id: UserId, |         pub user_id: &'a UserId, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[derive(Default)] | ||||||
|  |     #[non_exhaustive] | ||||||
|     response: {} |     response: {} | ||||||
| 
 | 
 | ||||||
|     error: crate::Error |     error: crate::Error | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | impl<'a> Request<'a> { | ||||||
|  |     /// Creates a new `Request` with the given data, event type, room ID and user ID.
 | ||||||
|  |     pub fn new( | ||||||
|  |         data: Box<RawJsonValue>, | ||||||
|  |         event_type: &'a str, | ||||||
|  |         room_id: &'a RoomId, | ||||||
|  |         user_id: &'a UserId, | ||||||
|  |     ) -> Self { | ||||||
|  |         Self { data, event_type, room_id, user_id } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Response { | ||||||
|  |     /// Creates an empty `Response`.
 | ||||||
|  |     pub fn new() -> Self { | ||||||
|  |         Self | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
| @ -16,8 +16,11 @@ ruma_api! { | |||||||
|         requires_authentication: true, |         requires_authentication: true, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[derive(Default)] | ||||||
|  |     #[non_exhaustive] | ||||||
|     request: {} |     request: {} | ||||||
| 
 | 
 | ||||||
|  |     #[non_exhaustive] | ||||||
|     response: { |     response: { | ||||||
|         /// A list of third party identifiers the homeserver has associated with the user's
 |         /// A list of third party identifiers the homeserver has associated with the user's
 | ||||||
|         /// account.
 |         /// account.
 | ||||||
| @ -28,8 +31,26 @@ ruma_api! { | |||||||
|     error: crate::Error |     error: crate::Error | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl Request { | ||||||
|  |     /// Creates an empty `Request`.
 | ||||||
|  |     pub fn new() -> Self { | ||||||
|  |         Self | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Response { | ||||||
|  |     /// Creates a new `Response` with the given third party identifiers.
 | ||||||
|  |     pub fn new(threepids: Vec<ThirdPartyIdentifier>) -> Self { | ||||||
|  |         Self { threepids } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /// An identifier external to Matrix.
 | /// An identifier external to Matrix.
 | ||||||
|  | ///
 | ||||||
|  | /// To create an instance of this type, first create a `ThirdPartyIdentifierInit` and convert it to
 | ||||||
|  | /// this type using `ThirdPartyIdentifier::Init` / `.into()`.
 | ||||||
| #[derive(Clone, Debug, Deserialize, Serialize)] | #[derive(Clone, Debug, Deserialize, Serialize)] | ||||||
|  | #[non_exhaustive] | ||||||
| #[cfg_attr(test, derive(PartialEq))] | #[cfg_attr(test, derive(PartialEq))] | ||||||
| pub struct ThirdPartyIdentifier { | pub struct ThirdPartyIdentifier { | ||||||
|     /// The third party identifier address.
 |     /// The third party identifier address.
 | ||||||
| @ -47,6 +68,32 @@ pub struct ThirdPartyIdentifier { | |||||||
|     pub added_at: SystemTime, |     pub added_at: SystemTime, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /// Initial set of fields of `ThirdPartyIdentifier`.
 | ||||||
|  | ///
 | ||||||
|  | /// This struct will not be updated even if additional fields are added to `ThirdPartyIdentifier`
 | ||||||
|  | /// in a new (non-breaking) release of the Matrix specification.
 | ||||||
|  | #[derive(Debug)] | ||||||
|  | pub struct ThirdPartyIdentifierInit { | ||||||
|  |     /// The third party identifier address.
 | ||||||
|  |     pub address: String, | ||||||
|  | 
 | ||||||
|  |     /// The medium of third party identifier.
 | ||||||
|  |     pub medium: Medium, | ||||||
|  | 
 | ||||||
|  |     /// The time when the identifier was validated by the identity server.
 | ||||||
|  |     pub validated_at: SystemTime, | ||||||
|  | 
 | ||||||
|  |     /// The time when the homeserver associated the third party identifier with the user.
 | ||||||
|  |     pub added_at: SystemTime, | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl From<ThirdPartyIdentifierInit> for ThirdPartyIdentifier { | ||||||
|  |     fn from(init: ThirdPartyIdentifierInit) -> Self { | ||||||
|  |         let ThirdPartyIdentifierInit { address, medium, validated_at, added_at } = init; | ||||||
|  |         ThirdPartyIdentifier { address, medium, validated_at, added_at } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
| mod tests { | mod tests { | ||||||
|     use std::time::{Duration, UNIX_EPOCH}; |     use std::time::{Duration, UNIX_EPOCH}; | ||||||
|  | |||||||
| @ -13,35 +13,59 @@ ruma_api! { | |||||||
|         requires_authentication: false, |         requires_authentication: false, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[non_exhaustive] | ||||||
|     request: { |     request: { | ||||||
|         /// Client-generated secret string used to protect this session.
 |         /// Client-generated secret string used to protect this session.
 | ||||||
|         pub client_secret: String, |         pub client_secret: &'a str, | ||||||
| 
 | 
 | ||||||
|         /// The email address.
 |         /// The email address.
 | ||||||
|         pub email: String, |         pub email: &'a str, | ||||||
| 
 |  | ||||||
|         /// A URL for the identity server to redirect the user to after
 |  | ||||||
|         /// validation is completed.
 |  | ||||||
|         #[serde(skip_serializing_if = "Option::is_none")] |  | ||||||
|         pub next_link: Option<String>, |  | ||||||
| 
 | 
 | ||||||
|         /// Used to distinguish protocol level retries from requests to re-send
 |         /// Used to distinguish protocol level retries from requests to re-send
 | ||||||
|         /// the email.
 |         /// the email.
 | ||||||
|         pub send_attempt: UInt, |         pub send_attempt: UInt, | ||||||
| 
 | 
 | ||||||
|  |         /// A URL for the identity server to redirect the user to after
 | ||||||
|  |         /// validation is completed.
 | ||||||
|  |         #[serde(skip_serializing_if = "Option::is_none")] | ||||||
|  |         pub next_link: Option<&'a str>, | ||||||
|  | 
 | ||||||
|         /// The identity server to send the onward request to as a hostname with
 |         /// The identity server to send the onward request to as a hostname with
 | ||||||
|         /// an appended colon and port number if the port is not the default.
 |         /// an appended colon and port number if the port is not the default.
 | ||||||
|         #[serde(skip_serializing_if = "Option::is_none")] |         #[serde(skip_serializing_if = "Option::is_none")] | ||||||
|         pub id_server: Option<String>, |         pub id_server: Option<&'a str>, | ||||||
| 
 | 
 | ||||||
|         /// An access token previously registered with the identity server.
 |         /// An access token previously registered with the identity server.
 | ||||||
|         ///
 |         ///
 | ||||||
|         /// Required if an `id_server` is supplied.
 |         /// Required if an `id_server` is supplied.
 | ||||||
|         #[serde(skip_serializing_if = "Option::is_none")] |         #[serde(skip_serializing_if = "Option::is_none")] | ||||||
|         pub id_access_token: Option<String>, |         pub id_access_token: Option<&'a str>, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[derive(Default)] | ||||||
|  |     #[non_exhaustive] | ||||||
|     response: {} |     response: {} | ||||||
| 
 | 
 | ||||||
|     error: crate::Error |     error: crate::Error | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | impl<'a> Request<'a> { | ||||||
|  |     /// Creates a new `Request` with the given client secret, email and send-attempt counter.
 | ||||||
|  |     pub fn new(client_secret: &'a str, email: &'a str, send_attempt: UInt) -> Self { | ||||||
|  |         Self { | ||||||
|  |             client_secret, | ||||||
|  |             email, | ||||||
|  |             send_attempt, | ||||||
|  |             next_link: None, | ||||||
|  |             id_server: None, | ||||||
|  |             id_access_token: None, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Response { | ||||||
|  |     /// Creates an empty `Response`.
 | ||||||
|  |     pub fn new() -> Self { | ||||||
|  |         Self | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user