federation-api: Add lots of non_exhaustive attributes, other minor fixes
This commit is contained in:
parent
fbeae794c1
commit
64c5159f04
@ -2,7 +2,9 @@
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::directory::{Filter, PublicRoomsChunk, RoomNetwork};
|
||||
use ruma_common::directory::{
|
||||
Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork,
|
||||
};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -14,6 +16,8 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The server to fetch the public room lists from.
|
||||
///
|
||||
@ -32,26 +36,45 @@ ruma_api! {
|
||||
|
||||
/// Filter to apply to the results.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub filter: Option<Filter>,
|
||||
pub filter: Option<Filter<'a>>,
|
||||
|
||||
/// Network to fetch the public room lists from.
|
||||
#[serde(flatten, skip_serializing_if = "ruma_serde::is_default")]
|
||||
pub room_network: RoomNetwork,
|
||||
pub room_network: RoomNetwork<'a>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// A paginated chunk of public rooms.
|
||||
pub chunk: Vec<PublicRoomsChunk>,
|
||||
|
||||
/// A pagination token for the response.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub next_batch: Option<String>,
|
||||
|
||||
/// A pagination token that allows fetching previous results.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prev_batch: Option<String>,
|
||||
|
||||
/// An estimate on the total number of public rooms, if the server has an estimate.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub total_room_count_estimate: Option<UInt>,
|
||||
}
|
||||
|
||||
error: crate::Error
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
js_int = { version = "0.1.9", features = ["serde"] }
|
||||
ruma-api = { version = "=0.17.0-alpha.1", path = "../ruma-api" }
|
||||
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"] }
|
||||
|
@ -3,6 +3,7 @@
|
||||
use std::fmt;
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::Outgoing;
|
||||
use ruma_identifiers::{RoomAliasId, RoomId};
|
||||
use serde::{
|
||||
de::{Error, MapAccess, Visitor},
|
||||
@ -95,15 +96,15 @@ impl From<PublicRoomsChunkInit> for PublicRoomsChunk {
|
||||
}
|
||||
|
||||
/// A filter for public rooms lists
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Default, Outgoing, Serialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct Filter {
|
||||
pub struct Filter<'a> {
|
||||
/// A string to search for in the room metadata, e.g. name, topic, canonical alias etc.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub generic_search_term: Option<String>,
|
||||
pub generic_search_term: Option<&'a str>,
|
||||
}
|
||||
|
||||
impl Filter {
|
||||
impl<'a> Filter<'a> {
|
||||
/// Creates an empty `Filter`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
@ -112,9 +113,10 @@ impl Filter {
|
||||
|
||||
/// Information about which networks/protocols from application services on the
|
||||
/// homeserver from which to request rooms.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Outgoing)]
|
||||
#[non_exhaustive]
|
||||
pub enum RoomNetwork {
|
||||
#[incoming_derive(Clone, PartialEq, Eq, !Deserialize)]
|
||||
pub enum RoomNetwork<'a> {
|
||||
/// Return rooms from the Matrix network.
|
||||
Matrix,
|
||||
|
||||
@ -122,16 +124,16 @@ pub enum RoomNetwork {
|
||||
All,
|
||||
|
||||
/// Return rooms from a specific third party network/protocol.
|
||||
ThirdParty(String),
|
||||
ThirdParty(&'a str),
|
||||
}
|
||||
|
||||
impl Default for RoomNetwork {
|
||||
impl<'a> Default for RoomNetwork<'a> {
|
||||
fn default() -> Self {
|
||||
RoomNetwork::Matrix
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for RoomNetwork {
|
||||
impl<'a> Serialize for RoomNetwork<'a> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
@ -154,7 +156,7 @@ impl Serialize for RoomNetwork {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for RoomNetwork {
|
||||
impl<'de> Deserialize<'de> for IncomingRoomNetwork {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
@ -165,7 +167,7 @@ impl<'de> Deserialize<'de> for RoomNetwork {
|
||||
|
||||
struct RoomNetworkVisitor;
|
||||
impl<'de> Visitor<'de> for RoomNetworkVisitor {
|
||||
type Value = RoomNetwork;
|
||||
type Value = IncomingRoomNetwork;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("Network selection")
|
||||
@ -194,7 +196,7 @@ impl<'de> Visitor<'de> for RoomNetworkVisitor {
|
||||
|
||||
if include_all_networks {
|
||||
if third_party_instance_id.is_none() {
|
||||
Ok(RoomNetwork::All)
|
||||
Ok(IncomingRoomNetwork::All)
|
||||
} else {
|
||||
Err(M::Error::custom(
|
||||
"`include_all_networks = true` and `third_party_instance_id` are mutually exclusive.",
|
||||
@ -202,8 +204,8 @@ impl<'de> Visitor<'de> for RoomNetworkVisitor {
|
||||
}
|
||||
} else {
|
||||
Ok(match third_party_instance_id {
|
||||
Some(network) => RoomNetwork::ThirdParty(network),
|
||||
None => RoomNetwork::Matrix,
|
||||
Some(network) => IncomingRoomNetwork::ThirdParty(network),
|
||||
None => IncomingRoomNetwork::Matrix,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -213,7 +215,7 @@ impl<'de> Visitor<'de> for RoomNetworkVisitor {
|
||||
mod tests {
|
||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||
|
||||
use super::RoomNetwork;
|
||||
use super::{IncomingRoomNetwork, RoomNetwork};
|
||||
|
||||
#[test]
|
||||
fn test_serialize_matrix_network_only() {
|
||||
@ -224,7 +226,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_deserialize_matrix_network_only() {
|
||||
let json = json!({ "include_all_networks": false });
|
||||
assert_eq!(from_json_value::<RoomNetwork>(json).unwrap(), RoomNetwork::Matrix);
|
||||
assert_eq!(
|
||||
from_json_value::<IncomingRoomNetwork>(json).unwrap(),
|
||||
IncomingRoomNetwork::Matrix
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -236,7 +241,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_deserialize_empty_network_is_default() {
|
||||
let json = json!({});
|
||||
assert_eq!(from_json_value::<RoomNetwork>(json).unwrap(), RoomNetwork::default());
|
||||
assert_eq!(
|
||||
from_json_value::<IncomingRoomNetwork>(json).unwrap(),
|
||||
IncomingRoomNetwork::Matrix
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -248,21 +256,21 @@ mod tests {
|
||||
#[test]
|
||||
fn test_deserialize_include_all_networks() {
|
||||
let json = json!({ "include_all_networks": true });
|
||||
assert_eq!(from_json_value::<RoomNetwork>(json).unwrap(), RoomNetwork::All);
|
||||
assert_eq!(from_json_value::<IncomingRoomNetwork>(json).unwrap(), IncomingRoomNetwork::All);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_third_party_network() {
|
||||
let json = json!({ "third_party_instance_id": "freenode" });
|
||||
assert_eq!(to_json_value(RoomNetwork::ThirdParty("freenode".into())).unwrap(), json);
|
||||
assert_eq!(to_json_value(RoomNetwork::ThirdParty("freenode")).unwrap(), json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_third_party_network() {
|
||||
let json = json!({ "third_party_instance_id": "freenode" });
|
||||
assert_eq!(
|
||||
from_json_value::<RoomNetwork>(json).unwrap(),
|
||||
RoomNetwork::ThirdParty("freenode".into())
|
||||
from_json_value::<IncomingRoomNetwork>(json).unwrap(),
|
||||
IncomingRoomNetwork::ThirdParty("freenode".into())
|
||||
);
|
||||
}
|
||||
|
||||
@ -270,7 +278,7 @@ mod tests {
|
||||
fn test_deserialize_include_all_networks_and_third_party_exclusivity() {
|
||||
let json = json!({ "include_all_networks": true, "third_party_instance_id": "freenode" });
|
||||
assert_eq!(
|
||||
from_json_value::<RoomNetwork>(json).unwrap_err().to_string().as_str(),
|
||||
from_json_value::<IncomingRoomNetwork>(json).unwrap_err().to_string().as_str(),
|
||||
"`include_all_networks = true` and `third_party_instance_id` are mutually exclusive."
|
||||
);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::directory::{PublicRoomsChunk, RoomNetwork};
|
||||
use ruma_common::directory::{IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -14,6 +14,8 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// Limit for the number of results to return.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -28,9 +30,11 @@ ruma_api! {
|
||||
/// Network to fetch the public room lists from.
|
||||
#[serde(flatten, skip_serializing_if = "ruma_serde::is_default")]
|
||||
#[ruma_api(query)]
|
||||
pub room_network: RoomNetwork,
|
||||
pub room_network: RoomNetwork<'a>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// A paginated chunk of public rooms.
|
||||
pub chunk: Vec<PublicRoomsChunk>,
|
||||
@ -47,3 +51,17 @@ ruma_api! {
|
||||
pub total_room_count_estimate: Option<UInt>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_common::directory::{Filter, PublicRoomsChunk, RoomNetwork};
|
||||
use ruma_common::directory::{
|
||||
Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork,
|
||||
};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -14,6 +16,8 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// Limit for the number of results to return.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -25,13 +29,15 @@ ruma_api! {
|
||||
|
||||
/// Filter to apply to the results.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub filter: Option<Filter>,
|
||||
pub filter: Option<Filter<'a>>,
|
||||
|
||||
/// Network to fetch the public room lists from.
|
||||
#[serde(flatten, skip_serializing_if = "ruma_serde::is_default")]
|
||||
pub room_network: RoomNetwork,
|
||||
pub room_network: RoomNetwork<'a>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// A paginated chunk of public rooms.
|
||||
pub chunk: Vec<PublicRoomsChunk>,
|
||||
@ -46,3 +52,17 @@ ruma_api! {
|
||||
pub total_room_count_estimate: Option<UInt>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates an empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
//! [GET /.well-known/matrix/server](https://matrix.org/docs/spec/server_server/r0.1.3#get-well-known-matrix-server)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::ServerNameBox;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -12,11 +13,28 @@ ruma_api! {
|
||||
requires_authentication: false,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
request: {}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// The server name to delegate server-server communciations to, with optional port.
|
||||
#[serde(rename = "m.homeserver")]
|
||||
pub homeserver: String,
|
||||
pub homeserver: ServerNameBox,
|
||||
}
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates an empty `Request`.
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given homeserver.
|
||||
pub fn new(homeserver: ServerNameBox) -> Self {
|
||||
Self { homeserver }
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,8 @@ ruma_api! {
|
||||
}
|
||||
|
||||
/// The query criteria.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct QueryCriteria {
|
||||
/// A millisecond POSIX timestamp in milliseconds indicating when the
|
||||
/// returned certificates will need to be valid until to be useful to the
|
||||
@ -63,3 +64,10 @@ pub struct QueryCriteria {
|
||||
)]
|
||||
pub minimum_valid_until_ts: Option<SystemTime>,
|
||||
}
|
||||
|
||||
impl QueryCriteria {
|
||||
/// Creates empty `QueryCriteria`.
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,12 @@ ruma_api! {
|
||||
requires_authentication: false,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
request: {}
|
||||
|
||||
#[derive(Default)]
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// Information about the homeserver implementation
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
@ -17,17 +17,33 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The keys to be claimed.
|
||||
one_time_keys: OneTimeKeyClaims,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// One-time keys for the queried devices
|
||||
one_time_keys: OneTimeKeys,
|
||||
}
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given one time key claims.
|
||||
pub fn new(one_time_keys: OneTimeKeyClaims) -> Self {
|
||||
Self { one_time_keys }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given one time keys.
|
||||
pub fn new(one_time_keys: OneTimeKeys) -> Self {
|
||||
Self { one_time_keys }
|
||||
}
|
||||
}
|
||||
|
||||
/// A claim for one time keys
|
||||
pub type OneTimeKeyClaims = BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeyAlgorithm>>;
|
||||
|
||||
@ -43,17 +59,3 @@ pub struct KeyObject {
|
||||
/// Signature of the key object.
|
||||
signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given one time key claims.
|
||||
pub fn new(one_time_keys: OneTimeKeyClaims) -> Self {
|
||||
Self { one_time_keys }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given one time keys.
|
||||
pub fn new(one_time_keys: OneTimeKeys) -> Self {
|
||||
Self { one_time_keys }
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,14 @@ ruma_api! {
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
request: {
|
||||
/// The keys to be downloaded. Gives all keys for a given user if the list of device ids is
|
||||
/// empty.
|
||||
device_keys: BTreeMap<UserId, Vec<DeviceIdBox>>,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
response: {
|
||||
/// Keys from the queried devices.
|
||||
device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>,
|
||||
|
@ -20,10 +20,11 @@ ruma_api! {
|
||||
request: {
|
||||
/// The room ID that is about to be joined.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: RoomId,
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The user ID the join event will be for.
|
||||
#[ruma_api(path)]
|
||||
pub event_id: EventId,
|
||||
pub event_id: &'a EventId,
|
||||
|
||||
/// PDU type without event and room IDs.
|
||||
#[ruma_api(body)]
|
||||
|
@ -21,6 +21,7 @@ ruma_api! {
|
||||
/// The room ID that is about to be joined.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: RoomId,
|
||||
|
||||
/// The user ID the join event will be for.
|
||||
#[ruma_api(path)]
|
||||
pub event_id: EventId,
|
||||
|
@ -18,19 +18,22 @@ ruma_api! {
|
||||
request: {
|
||||
/// The room ID that is about to be joined.
|
||||
#[ruma_api(path)]
|
||||
pub room_id: RoomId,
|
||||
pub room_id: &'a RoomId,
|
||||
|
||||
/// The user ID the join event will be for.
|
||||
#[ruma_api(path)]
|
||||
pub user_id: UserId,
|
||||
#[ruma_api(query)]
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
/// The room versions the sending server has support for. Defaults to 1.
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub ver: Vec<RoomVersionId>,
|
||||
#[ruma_api(query)]
|
||||
#[serde(skip_serializing_if = "<[_]>::is_empty")]
|
||||
pub ver: &'a [RoomVersionId],
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The version of the room where the server is trying to join.
|
||||
pub room_version: Option<RoomVersionId>,
|
||||
|
||||
/// An unsigned template event.
|
||||
pub event: Raw<Pdu>,
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ ruma_api! {
|
||||
request: {
|
||||
/// The OpenID access token to get information about the owner for.
|
||||
#[ruma_api(query)]
|
||||
pub access_token: String,
|
||||
pub access_token: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! [GET /_matrix/federation/v1/query/directory](https://matrix.org/docs/spec/server_server/r0.1.3#get-matrix-federation-v1-query-directory)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
use ruma_identifiers::RoomId;
|
||||
use ruma_identifiers::{RoomAliasId, RoomId};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -16,12 +16,13 @@ ruma_api! {
|
||||
request: {
|
||||
/// Room alias to query.
|
||||
#[ruma_api(query)]
|
||||
pub room_alias: String,
|
||||
pub room_alias: &'a RoomAliasId,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Room ID mapped to queried alias.
|
||||
pub room_id: RoomId,
|
||||
|
||||
/// An array of server names that are likely to hold the given room.
|
||||
pub servers: Vec<String>,
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ ruma_api! {
|
||||
pub struct Edu {
|
||||
/// Type of the ephemeral message.
|
||||
pub edu_type: String,
|
||||
|
||||
/// Content of ephemeral message
|
||||
pub content: JsonValue,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user