acter_core/
super_invites.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
use matrix_sdk_base::ruma::{OwnedMxcUri, OwnedUserId};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Token {
    pub token: String,
    pub create_dm: bool,
    pub accepted_count: u32,
    pub rooms: Vec<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TokenOwner {
    pub user_id: OwnedUserId,
    pub display_name: Option<String>,
    pub avatar_url: Option<OwnedMxcUri>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TokenInfo {
    pub rooms_count: u32,
    pub create_dm: bool,
    pub has_redeemed: bool,
    pub inviter: TokenOwner,
}

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct CreateToken {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub token: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_dm: Option<bool>,
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub rooms: Vec<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct UpdateToken {
    pub token: String,
    pub create_dm: bool,
    pub rooms: Vec<String>,
}

pub mod api {
    pub mod list {

        use matrix_sdk_base::ruma::{
            api::{request, response, Metadata},
            metadata,
        };

        use super::super::Token;

        const METADATA: Metadata = metadata! {
            method: GET,
            rate_limited: false,
            authentication: AccessToken,
            history: {
                unstable => "/_synapse/client/super_invites/tokens",
            }
        };

        #[request]
        pub struct Request {}

        impl Request {
            pub fn new() -> Self {
                Request {}
            }
        }
        impl Default for Request {
            fn default() -> Self {
                Self::new()
            }
        }

        #[response]
        #[derive(Default)]
        pub struct Response {
            pub tokens: Vec<Token>,
        }

        impl Response {
            /// Creates an empty `Response`.
            pub fn new() -> Self {
                Default::default()
            }
        }
    }

    pub mod create {

        use matrix_sdk_base::ruma::{
            api::{request, response, Metadata},
            metadata,
        };

        use super::super::{CreateToken, Token};

        const METADATA: Metadata = metadata! {
            method: POST,
            rate_limited: false,
            authentication: AccessToken,
            history: {
                unstable => "/_synapse/client/super_invites/tokens",
            }
        };

        #[request]
        pub struct Request {
            #[serde(flatten)]
            pub token: CreateToken,
        }

        impl Request {
            pub fn new(token: CreateToken) -> Self {
                Request { token }
            }
        }

        #[response]
        pub struct Response {
            pub token: Token,
        }
    }

    pub mod update {

        use matrix_sdk_base::ruma::{
            api::{request, response, Metadata},
            metadata,
        };

        use super::super::{Token, UpdateToken};

        const METADATA: Metadata = metadata! {
            method: POST,
            rate_limited: false,
            authentication: AccessToken,
            history: {
                unstable => "/_synapse/client/super_invites/tokens",
            }
        };

        #[request]
        pub struct Request {
            #[serde(flatten)]
            pub token: UpdateToken,
        }

        impl Request {
            pub fn new(token: UpdateToken) -> Self {
                Request { token }
            }
        }

        #[response]
        pub struct Response {
            pub token: Token,
        }
    }

    pub mod delete {

        use matrix_sdk_base::ruma::{
            api::{request, response, Metadata},
            metadata,
        };

        const METADATA: Metadata = metadata! {
            method: DELETE,
            rate_limited: false,
            authentication: AccessToken,
            history: {
                unstable => "/_synapse/client/super_invites/tokens",
            }
        };

        #[request]
        pub struct Request {
            #[ruma_api(query)]
            pub token: String,
        }

        impl Request {
            pub fn new(token: String) -> Self {
                Request { token }
            }
        }

        #[response]
        pub struct Response {}
    }

    pub mod redeem {

        use matrix_sdk_base::ruma::{
            api::{request, response, Metadata},
            metadata,
        };

        const METADATA: Metadata = metadata! {
            method: POST,
            rate_limited: false,
            authentication: AccessToken,
            history: {
                unstable => "/_synapse/client/super_invites/redeem",
            }
        };

        #[request]
        pub struct Request {
            #[ruma_api(query)]
            pub token: String,
        }

        impl Request {
            pub fn new(token: String) -> Self {
                Request { token }
            }
        }

        #[response]
        pub struct Response {
            pub rooms: Vec<String>,
        }
    }

    pub mod info {

        use matrix_sdk_base::ruma::{
            api::{request, response, Metadata},
            metadata,
        };

        use super::super::TokenInfo;

        const METADATA: Metadata = metadata! {
            method: GET,
            rate_limited: false,
            authentication: AccessToken,
            history: {
                unstable => "/_synapse/client/super_invites/info",
            }
        };

        #[request]
        pub struct Request {
            #[ruma_api(query)]
            pub token: String,
        }

        impl Request {
            pub fn new(token: String) -> Self {
                Request { token }
            }
        }

        #[response]
        pub struct Response {
            #[serde(flatten)]
            pub info: TokenInfo,
        }
    }
}