ruma_client_api/push/set_pusher.rs
1//! `POST /_matrix/client/*/pushers/set`
2//!
3//! This endpoint allows the creation, modification and deletion of pushers for this user ID.
4
5mod set_pusher_serde;
6
7pub mod v3 {
8 //! `/v3/` ([spec])
9 //!
10 //! [spec]: https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3pushersset
11
12 use ruma_common::{
13 api::{request, response, Metadata},
14 metadata,
15 };
16 use serde::Serialize;
17
18 use crate::push::{Pusher, PusherIds};
19
20 const METADATA: Metadata = metadata! {
21 method: POST,
22 rate_limited: true,
23 authentication: AccessToken,
24 history: {
25 1.0 => "/_matrix/client/r0/pushers/set",
26 1.1 => "/_matrix/client/v3/pushers/set",
27 }
28 };
29
30 /// Request type for the `set_pusher` endpoint.
31 #[request(error = crate::Error)]
32 pub struct Request {
33 /// The action to take.
34 #[ruma_api(body)]
35 pub action: PusherAction,
36 }
37
38 /// Response type for the `set_pusher` endpoint.
39 #[response(error = crate::Error)]
40 #[derive(Default)]
41 pub struct Response {}
42
43 impl Request {
44 /// Creates a new `Request` for the given action.
45 pub fn new(action: PusherAction) -> Self {
46 Self { action }
47 }
48
49 /// Creates a new `Request` to create or update the given pusher.
50 pub fn post(pusher: Pusher) -> Self {
51 Self::new(PusherAction::Post(PusherPostData { pusher, append: false }))
52 }
53
54 /// Creates a new `Request` to delete the pusher identified by the given IDs.
55 pub fn delete(ids: PusherIds) -> Self {
56 Self::new(PusherAction::Delete(ids))
57 }
58 }
59
60 impl Response {
61 /// Creates an empty `Response`.
62 pub fn new() -> Self {
63 Self {}
64 }
65 }
66
67 /// The action to take for the pusher.
68 #[derive(Clone, Debug)]
69 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
70 pub enum PusherAction {
71 /// Create or update the given pusher.
72 Post(PusherPostData),
73
74 /// Delete the pusher identified by the given IDs.
75 Delete(PusherIds),
76 }
77
78 /// Data necessary to create or update a pusher.
79 #[derive(Clone, Debug, Serialize)]
80 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
81 pub struct PusherPostData {
82 /// The pusher to configure.
83 #[serde(flatten)]
84 pub pusher: Pusher,
85
86 /// Controls if another pusher with the same pushkey and app id should be created, if there
87 /// are already others for other users.
88 ///
89 /// Defaults to `false`. See the spec for more details.
90 #[serde(skip_serializing_if = "ruma_common::serde::is_default")]
91 pub append: bool,
92 }
93}