diff --git a/ruma-client-api/src/r0/push/delete_pushrule.rs b/ruma-client-api/src/r0/push/delete_pushrule.rs index 61d95f79..fc7deec4 100644 --- a/ruma-client-api/src/r0/push/delete_pushrule.rs +++ b/ruma-client-api/src/r0/push/delete_pushrule.rs @@ -14,10 +14,11 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The scope to delete from. 'global' to specify global rules. #[ruma_api(path)] - pub scope: String, + pub scope: &'a str, /// The kind of rule #[ruma_api(path)] @@ -25,10 +26,26 @@ ruma_api! { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: String, + pub rule_id: &'a str, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: {} error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given scope, kind and rule ID. + pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self { + Self { scope, kind, rule_id } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} diff --git a/ruma-client-api/src/r0/push/get_notifications.rs b/ruma-client-api/src/r0/push/get_notifications.rs index 3b69dec6..d6b30115 100644 --- a/ruma-client-api/src/r0/push/get_notifications.rs +++ b/ruma-client-api/src/r0/push/get_notifications.rs @@ -19,11 +19,13 @@ ruma_api! { requires_authentication: true, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// Pagination token given to retrieve the next set of events. #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] - pub from: Option, + pub from: Option<&'a str>, /// Limit on the number of events to return in this request. #[ruma_api(query)] @@ -34,9 +36,10 @@ ruma_api! { /// where the notification had the 'highlight' tweak set. #[ruma_api(query)] #[serde(skip_serializing_if = "Option::is_none")] - pub only: Option + pub only: Option<&'a str> } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// The token to supply in the from param of the next /notifications request in order /// to request more events. If this is absent, there are no more results. @@ -51,8 +54,23 @@ ruma_api! { error: crate::Error } -/// Represents a notification +impl<'a> Request<'a> { + /// Creates an empty `Request`. + pub fn new() -> Self { + Default::default() + } +} + +impl Response { + /// Creates a new `Response` with the given notifications. + pub fn new(notifications: Vec>) -> Self { + Self { next_token: None, notifications } + } +} + +/// Represents a notification. #[derive(Clone, Debug, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Notification { /// The actions to perform when the conditions for this rule are met. pub actions: Vec, @@ -71,7 +89,21 @@ pub struct Notification { /// The ID of the room in which the event was posted. pub room_id: RoomId, - /// The time at which the event notification was sent, in milliseconds. + /// The time at which the event notification was sent. #[serde(with = "ruma_serde::time::ms_since_unix_epoch")] pub ts: SystemTime, } + +impl Notification { + /// Creates a new `Notification` with the given actions, event, read flag, room ID and + /// timestamp. + pub fn new( + actions: Vec, + event: Raw, + read: bool, + room_id: RoomId, + ts: SystemTime, + ) -> Self { + Self { actions, event, profile_tag: None, read, room_id, ts } + } +} diff --git a/ruma-client-api/src/r0/push/get_pushers.rs b/ruma-client-api/src/r0/push/get_pushers.rs index 12bace50..695d28e6 100644 --- a/ruma-client-api/src/r0/push/get_pushers.rs +++ b/ruma-client-api/src/r0/push/get_pushers.rs @@ -14,8 +14,11 @@ ruma_api! { requires_authentication: true, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: {} + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// An array containing the current pushers for the user. pub pushers: Vec @@ -23,3 +26,17 @@ ruma_api! { error: crate::Error } + +impl Request { + /// Creates an empty `Request`. + pub fn new() -> Self { + Self + } +} + +impl Response { + /// Creates a new `Response` with the given pushers. + pub fn new(pushers: Vec) -> Self { + Self { pushers } + } +} diff --git a/ruma-client-api/src/r0/push/get_pushrule.rs b/ruma-client-api/src/r0/push/get_pushrule.rs index defb5432..4cebdd60 100644 --- a/ruma-client-api/src/r0/push/get_pushrule.rs +++ b/ruma-client-api/src/r0/push/get_pushrule.rs @@ -15,20 +15,22 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The scope to fetch rules from. 'global' to specify global rules. #[ruma_api(path)] - pub scope: String, + pub scope: &'a str, - /// The kind of rule + /// The kind of rule. #[ruma_api(path)] pub kind: RuleKind, /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: String, + pub rule_id: &'a str, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// The specific push rule. #[ruma_api(body)] @@ -37,3 +39,17 @@ ruma_api! { error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given scope, rule kind and rule ID. + pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self { + Self { scope, kind, rule_id } + } +} + +impl Response { + /// Creates a new `Response` with the given rule. + pub fn new(rule: AnyPushRule) -> Self { + Self { rule } + } +} diff --git a/ruma-client-api/src/r0/push/get_pushrule_actions.rs b/ruma-client-api/src/r0/push/get_pushrule_actions.rs index 55e38a68..154982f9 100644 --- a/ruma-client-api/src/r0/push/get_pushrule_actions.rs +++ b/ruma-client-api/src/r0/push/get_pushrule_actions.rs @@ -15,10 +15,11 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The scope to fetch a rule from. 'global' to specify global rules. #[ruma_api(path)] - pub scope: String, + pub scope: &'a str, /// The kind of rule #[ruma_api(path)] @@ -26,9 +27,10 @@ ruma_api! { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: String, + pub rule_id: &'a str, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// The actions to perform for this rule. pub actions: Vec @@ -36,3 +38,17 @@ ruma_api! { error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given scope, kind and rule ID. + pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self { + Self { scope, kind, rule_id } + } +} + +impl Response { + /// Creates a new `Repsonse` with the given actions. + pub fn new(actions: Vec) -> Self { + Self { actions } + } +} diff --git a/ruma-client-api/src/r0/push/get_pushrule_enabled.rs b/ruma-client-api/src/r0/push/get_pushrule_enabled.rs index 61230db7..cb298ee2 100644 --- a/ruma-client-api/src/r0/push/get_pushrule_enabled.rs +++ b/ruma-client-api/src/r0/push/get_pushrule_enabled.rs @@ -14,10 +14,11 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The scope to fetch a rule from. 'global' to specify global rules. #[ruma_api(path)] - pub scope: String, + pub scope: &'a str, /// The kind of rule #[ruma_api(path)] @@ -25,13 +26,28 @@ ruma_api! { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: String, + pub rule_id: &'a str, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// Whether the push rule is enabled or not. - pub enabled: bool + pub enabled: bool, } error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given scope, rule kind and rule ID. + pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self { + Self { scope, kind, rule_id } + } +} + +impl Response { + /// Creates a new `Response` with the given enabled flag. + pub fn new(enabled: bool) -> Self { + Self { enabled } + } +} diff --git a/ruma-client-api/src/r0/push/get_pushrules_all.rs b/ruma-client-api/src/r0/push/get_pushrules_all.rs index 9e942d92..c273ca89 100644 --- a/ruma-client-api/src/r0/push/get_pushrules_all.rs +++ b/ruma-client-api/src/r0/push/get_pushrules_all.rs @@ -13,12 +13,29 @@ ruma_api! { requires_authentication: true, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: {} + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { - /// The global ruleset + /// The global ruleset. pub global: Ruleset, } error: crate::Error } + +impl Request { + /// Creates an empty `Request`. + pub fn new() -> Self { + Self + } +} + +impl Response { + /// Creates a new `Response` with the given global ruleset. + pub fn new(global: Ruleset) -> Self { + Self { global } + } +} diff --git a/ruma-client-api/src/r0/push/get_pushrules_global_scope.rs b/ruma-client-api/src/r0/push/get_pushrules_global_scope.rs index 430cb992..be5ebd8f 100644 --- a/ruma-client-api/src/r0/push/get_pushrules_global_scope.rs +++ b/ruma-client-api/src/r0/push/get_pushrules_global_scope.rs @@ -13,8 +13,11 @@ ruma_api! { requires_authentication: true, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: {} + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// The global ruleset. #[ruma_api(body)] @@ -23,3 +26,17 @@ ruma_api! { error: crate::Error } + +impl Request { + /// Creates an empty `Request`. + pub fn new() -> Self { + Self + } +} + +impl Response { + /// Creates a new `Response` with the given global ruleset. + pub fn new(global: Ruleset) -> Self { + Self { global } + } +} diff --git a/ruma-client-api/src/r0/push/set_pusher.rs b/ruma-client-api/src/r0/push/set_pusher.rs index 1987bf5a..147100a2 100644 --- a/ruma-client-api/src/r0/push/set_pusher.rs +++ b/ruma-client-api/src/r0/push/set_pusher.rs @@ -14,19 +14,36 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { - /// The pusher to configure + /// The pusher to configure. #[serde(flatten)] pub pusher: Pusher, /// Controls if another pusher with the same pushkey and app id should be created. - /// See the spec for details. - #[serde(default)] - pub append: bool - + /// + /// Defaults to `false`. See the spec for more details. + #[serde(default, skip_serializing_if = "ruma_serde::is_default")] + pub append: bool, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: {} error: crate::Error } + +impl Request { + /// Creates a new `Request` with the given pusher. + pub fn new(pusher: Pusher) -> Self { + Self { pusher, append: false } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} diff --git a/ruma-client-api/src/r0/push/set_pushrule.rs b/ruma-client-api/src/r0/push/set_pushrule.rs index 14b45b82..a7fb98e7 100644 --- a/ruma-client-api/src/r0/push/set_pushrule.rs +++ b/ruma-client-api/src/r0/push/set_pushrule.rs @@ -15,10 +15,11 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The scope to set the rule in. 'global' to specify global rules. #[ruma_api(path)] - pub scope: String, + pub scope: &'a str, /// The kind of rule #[ruma_api(path)] @@ -26,17 +27,17 @@ ruma_api! { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: String, + pub rule_id: &'a str, /// Use 'before' with a rule_id as its value to make the new rule the next-most important /// rule with respect to the given user defined rule. #[ruma_api(query)] - pub before: Option, + pub before: Option<&'a str>, /// This makes the new rule the next-less important rule relative to the given user defined /// rule. #[ruma_api(query)] - pub after: Option, + pub after: Option<&'a str>, /// The actions to perform when this rule is matched. pub actions: Vec, @@ -49,10 +50,35 @@ ruma_api! { /// The glob-style pattern to match against. Only applicable to content rules. #[serde(skip_serializing_if = "Option::is_none")] - pub pattern: Option, + pub pattern: Option<&'a str>, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: {} error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given scope, rule kind, rule ID and actions. + pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str, actions: Vec) -> Self { + Self { + scope, + kind, + rule_id, + before: None, + after: None, + actions, + conditions: Vec::new(), + pattern: None, + } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} diff --git a/ruma-client-api/src/r0/push/set_pushrule_actions.rs b/ruma-client-api/src/r0/push/set_pushrule_actions.rs index 31d07471..79f92eef 100644 --- a/ruma-client-api/src/r0/push/set_pushrule_actions.rs +++ b/ruma-client-api/src/r0/push/set_pushrule_actions.rs @@ -15,10 +15,11 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The scope to fetch a rule from. 'global' to specify global rules. #[ruma_api(path)] - pub scope: String, + pub scope: &'a str, /// The kind of rule #[ruma_api(path)] @@ -26,13 +27,29 @@ ruma_api! { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: String, + pub rule_id: &'a str, /// The actions to perform for this rule - pub actions: Vec + pub actions: Vec, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: {} error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given scope, rule kind, rule ID and actions. + pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str, actions: Vec) -> Self { + Self { scope, kind, rule_id, actions } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} diff --git a/ruma-client-api/src/r0/push/set_pushrule_enabled.rs b/ruma-client-api/src/r0/push/set_pushrule_enabled.rs index 51e1e435..5f827a81 100644 --- a/ruma-client-api/src/r0/push/set_pushrule_enabled.rs +++ b/ruma-client-api/src/r0/push/set_pushrule_enabled.rs @@ -14,10 +14,11 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The scope to fetch a rule from. 'global' to specify global rules. #[ruma_api(path)] - pub scope: String, + pub scope: &'a str, /// The kind of rule #[ruma_api(path)] @@ -25,13 +26,39 @@ ruma_api! { /// The identifier for the rule. #[ruma_api(path)] - pub rule_id: String, + pub rule_id: &'a str, /// Whether the push rule is enabled or not. - pub enabled: bool + pub enabled: bool, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: {} error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given scope, rule kind, rule ID and enabled flag. + pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str, enabled: bool) -> Self { + Self { scope, kind, rule_id, enabled } + } + + /// Creates a new `Request` to enable the given rule. + pub fn enable(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self { + Self::new(scope, kind, rule_id, true) + } + + /// Creates a new `Request` to disable the given rule. + pub fn disable(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self { + Self::new(scope, kind, rule_id, false) + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +}