revolt_api/apis/
messaging_api.rs

1/*
2 * Revolt API
3 *
4 * Open source user-first chat platform.
5 *
6 * The version of the OpenAPI document: 0.6.5
7 * Contact: contact@revolt.chat
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`channel_ack_req`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ChannelAckReqError {
22    DefaultResponse(crate::models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`message_bulk_delete_req`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum MessageBulkDeleteReqError {
30    DefaultResponse(crate::models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`message_delete_req`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum MessageDeleteReqError {
38    DefaultResponse(crate::models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`message_edit_req`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum MessageEditReqError {
46    DefaultResponse(crate::models::Error),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`message_fetch_req`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum MessageFetchReqError {
54    DefaultResponse(crate::models::Error),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`message_query_req`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum MessageQueryReqError {
62    DefaultResponse(crate::models::Error),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`message_query_stale_req`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum MessageQueryStaleReqError {
70    DefaultResponse(crate::models::Error),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`message_search_req`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum MessageSearchReqError {
78    DefaultResponse(crate::models::Error),
79    UnknownValue(serde_json::Value),
80}
81
82/// struct for typed errors of method [`message_send_message_send`]
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum MessageSendMessageSendError {
86    DefaultResponse(crate::models::Error),
87    UnknownValue(serde_json::Value),
88}
89
90
91/// Lets the server and all other clients know that we've seen this message id in this channel.
92pub async fn channel_ack_req(configuration: &configuration::Configuration, target: &str, message: &str) -> Result<(), Error<ChannelAckReqError>> {
93    let local_var_configuration = configuration;
94
95    let local_var_client = &local_var_configuration.client;
96
97    let local_var_uri_str = format!("{}/channels/{target}/ack/{message}", local_var_configuration.base_path, target=crate::apis::urlencode(target), message=crate::apis::urlencode(message));
98    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
99
100    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
101        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
102    }
103    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
104        let local_var_key = local_var_apikey.key.clone();
105        let local_var_value = match local_var_apikey.prefix {
106            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
107            None => local_var_key,
108        };
109        local_var_req_builder = local_var_req_builder.header("x-session-token", local_var_value);
110    };
111
112    let local_var_req = local_var_req_builder.build()?;
113    let local_var_resp = local_var_client.execute(local_var_req).await?;
114
115    let local_var_status = local_var_resp.status();
116    let local_var_content = local_var_resp.text().await?;
117
118    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
119        Ok(())
120    } else {
121        let local_var_entity: Option<ChannelAckReqError> = serde_json::from_str(&local_var_content).ok();
122        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
123        Err(Error::ResponseError(local_var_error))
124    }
125}
126
127/// Delete multiple messages you've sent or one you have permission to delete.  This will always require `ManageMessages` permission regardless of whether you own the message or not.  Messages must have been sent within the past 1 week.
128pub async fn message_bulk_delete_req(configuration: &configuration::Configuration, target: &str, options_bulk_delete: crate::models::OptionsBulkDelete) -> Result<(), Error<MessageBulkDeleteReqError>> {
129    let local_var_configuration = configuration;
130
131    let local_var_client = &local_var_configuration.client;
132
133    let local_var_uri_str = format!("{}/channels/{target}/messages/bulk", local_var_configuration.base_path, target=crate::apis::urlencode(target));
134    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
135
136    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
137        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
138    }
139    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
140        let local_var_key = local_var_apikey.key.clone();
141        let local_var_value = match local_var_apikey.prefix {
142            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
143            None => local_var_key,
144        };
145        local_var_req_builder = local_var_req_builder.header("x-session-token", local_var_value);
146    };
147    local_var_req_builder = local_var_req_builder.json(&options_bulk_delete);
148
149    let local_var_req = local_var_req_builder.build()?;
150    let local_var_resp = local_var_client.execute(local_var_req).await?;
151
152    let local_var_status = local_var_resp.status();
153    let local_var_content = local_var_resp.text().await?;
154
155    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
156        Ok(())
157    } else {
158        let local_var_entity: Option<MessageBulkDeleteReqError> = serde_json::from_str(&local_var_content).ok();
159        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
160        Err(Error::ResponseError(local_var_error))
161    }
162}
163
164/// Delete a message you've sent or one you have permission to delete.
165pub async fn message_delete_req(configuration: &configuration::Configuration, target: &str, msg: &str) -> Result<(), Error<MessageDeleteReqError>> {
166    let local_var_configuration = configuration;
167
168    let local_var_client = &local_var_configuration.client;
169
170    let local_var_uri_str = format!("{}/channels/{target}/messages/{msg}", local_var_configuration.base_path, target=crate::apis::urlencode(target), msg=crate::apis::urlencode(msg));
171    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
172
173    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
174        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
175    }
176    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
177        let local_var_key = local_var_apikey.key.clone();
178        let local_var_value = match local_var_apikey.prefix {
179            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
180            None => local_var_key,
181        };
182        local_var_req_builder = local_var_req_builder.header("x-session-token", local_var_value);
183    };
184
185    let local_var_req = local_var_req_builder.build()?;
186    let local_var_resp = local_var_client.execute(local_var_req).await?;
187
188    let local_var_status = local_var_resp.status();
189    let local_var_content = local_var_resp.text().await?;
190
191    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
192        Ok(())
193    } else {
194        let local_var_entity: Option<MessageDeleteReqError> = serde_json::from_str(&local_var_content).ok();
195        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
196        Err(Error::ResponseError(local_var_error))
197    }
198}
199
200/// Edits a message that you've previously sent.
201pub async fn message_edit_req(configuration: &configuration::Configuration, target: &str, msg: &str, data_edit_message: crate::models::DataEditMessage) -> Result<crate::models::Message, Error<MessageEditReqError>> {
202    let local_var_configuration = configuration;
203
204    let local_var_client = &local_var_configuration.client;
205
206    let local_var_uri_str = format!("{}/channels/{target}/messages/{msg}", local_var_configuration.base_path, target=crate::apis::urlencode(target), msg=crate::apis::urlencode(msg));
207    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
208
209    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
210        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
211    }
212    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
213        let local_var_key = local_var_apikey.key.clone();
214        let local_var_value = match local_var_apikey.prefix {
215            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
216            None => local_var_key,
217        };
218        local_var_req_builder = local_var_req_builder.header("x-session-token", local_var_value);
219    };
220    local_var_req_builder = local_var_req_builder.json(&data_edit_message);
221
222    let local_var_req = local_var_req_builder.build()?;
223    let local_var_resp = local_var_client.execute(local_var_req).await?;
224
225    let local_var_status = local_var_resp.status();
226    let local_var_content = local_var_resp.text().await?;
227
228    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
229        serde_json::from_str(&local_var_content).map_err(Error::from)
230    } else {
231        let local_var_entity: Option<MessageEditReqError> = serde_json::from_str(&local_var_content).ok();
232        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
233        Err(Error::ResponseError(local_var_error))
234    }
235}
236
237/// Retrieves a message by its id.
238pub async fn message_fetch_req(configuration: &configuration::Configuration, target: &str, msg: &str) -> Result<crate::models::Message, Error<MessageFetchReqError>> {
239    let local_var_configuration = configuration;
240
241    let local_var_client = &local_var_configuration.client;
242
243    let local_var_uri_str = format!("{}/channels/{target}/messages/{msg}", local_var_configuration.base_path, target=crate::apis::urlencode(target), msg=crate::apis::urlencode(msg));
244    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
245
246    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
247        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
248    }
249    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
250        let local_var_key = local_var_apikey.key.clone();
251        let local_var_value = match local_var_apikey.prefix {
252            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
253            None => local_var_key,
254        };
255        local_var_req_builder = local_var_req_builder.header("x-session-token", local_var_value);
256    };
257
258    let local_var_req = local_var_req_builder.build()?;
259    let local_var_resp = local_var_client.execute(local_var_req).await?;
260
261    let local_var_status = local_var_resp.status();
262    let local_var_content = local_var_resp.text().await?;
263
264    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
265        serde_json::from_str(&local_var_content).map_err(Error::from)
266    } else {
267        let local_var_entity: Option<MessageFetchReqError> = serde_json::from_str(&local_var_content).ok();
268        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
269        Err(Error::ResponseError(local_var_error))
270    }
271}
272
273/// Fetch multiple messages.
274pub async fn message_query_req(configuration: &configuration::Configuration, target: &str, limit: Option<i64>, before: Option<&str>, after: Option<&str>, sort: Option<crate::models::MessageSort>, nearby: Option<&str>, include_users: Option<bool>) -> Result<crate::models::BulkMessageResponse, Error<MessageQueryReqError>> {
275    let local_var_configuration = configuration;
276
277    let local_var_client = &local_var_configuration.client;
278
279    let local_var_uri_str = format!("{}/channels/{target}/messages", local_var_configuration.base_path, target=crate::apis::urlencode(target));
280    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
281
282    if let Some(ref local_var_str) = limit {
283        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
284    }
285    if let Some(ref local_var_str) = before {
286        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
287    }
288    if let Some(ref local_var_str) = after {
289        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
290    }
291    if let Some(ref local_var_str) = sort {
292        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
293    }
294    if let Some(ref local_var_str) = nearby {
295        local_var_req_builder = local_var_req_builder.query(&[("nearby", &local_var_str.to_string())]);
296    }
297    if let Some(ref local_var_str) = include_users {
298        local_var_req_builder = local_var_req_builder.query(&[("include_users", &local_var_str.to_string())]);
299    }
300    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
301        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
302    }
303    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
304        let local_var_key = local_var_apikey.key.clone();
305        let local_var_value = match local_var_apikey.prefix {
306            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
307            None => local_var_key,
308        };
309        local_var_req_builder = local_var_req_builder.header("x-session-token", local_var_value);
310    };
311
312    let local_var_req = local_var_req_builder.build()?;
313    let local_var_resp = local_var_client.execute(local_var_req).await?;
314
315    let local_var_status = local_var_resp.status();
316    let local_var_content = local_var_resp.text().await?;
317
318    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
319        serde_json::from_str(&local_var_content).map_err(Error::from)
320    } else {
321        let local_var_entity: Option<MessageQueryReqError> = serde_json::from_str(&local_var_content).ok();
322        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
323        Err(Error::ResponseError(local_var_error))
324    }
325}
326
327/// This route returns any changed message objects and tells you if any have been deleted.  Don't actually poll this route, instead use this to update your local database.  **DEPRECATED**
328pub async fn message_query_stale_req(configuration: &configuration::Configuration, _target: &str, options_query_stale: crate::models::OptionsQueryStale) -> Result<(), Error<MessageQueryStaleReqError>> {
329    let local_var_configuration = configuration;
330
331    let local_var_client = &local_var_configuration.client;
332
333    let local_var_uri_str = format!("{}/channels/{_target}/messages/stale", local_var_configuration.base_path, _target=crate::apis::urlencode(_target));
334    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
335
336    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
337        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
338    }
339    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
340        let local_var_key = local_var_apikey.key.clone();
341        let local_var_value = match local_var_apikey.prefix {
342            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
343            None => local_var_key,
344        };
345        local_var_req_builder = local_var_req_builder.header("x-session-token", local_var_value);
346    };
347    local_var_req_builder = local_var_req_builder.json(&options_query_stale);
348
349    let local_var_req = local_var_req_builder.build()?;
350    let local_var_resp = local_var_client.execute(local_var_req).await?;
351
352    let local_var_status = local_var_resp.status();
353    let local_var_content = local_var_resp.text().await?;
354
355    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
356        Ok(())
357    } else {
358        let local_var_entity: Option<MessageQueryStaleReqError> = serde_json::from_str(&local_var_content).ok();
359        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
360        Err(Error::ResponseError(local_var_error))
361    }
362}
363
364/// This route searches for messages within the given parameters.
365pub async fn message_search_req(configuration: &configuration::Configuration, target: &str, options_message_search: crate::models::OptionsMessageSearch) -> Result<crate::models::BulkMessageResponse, Error<MessageSearchReqError>> {
366    let local_var_configuration = configuration;
367
368    let local_var_client = &local_var_configuration.client;
369
370    let local_var_uri_str = format!("{}/channels/{target}/search", local_var_configuration.base_path, target=crate::apis::urlencode(target));
371    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
372
373    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
374        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
375    }
376    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
377        let local_var_key = local_var_apikey.key.clone();
378        let local_var_value = match local_var_apikey.prefix {
379            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
380            None => local_var_key,
381        };
382        local_var_req_builder = local_var_req_builder.header("x-session-token", local_var_value);
383    };
384    local_var_req_builder = local_var_req_builder.json(&options_message_search);
385
386    let local_var_req = local_var_req_builder.build()?;
387    let local_var_resp = local_var_client.execute(local_var_req).await?;
388
389    let local_var_status = local_var_resp.status();
390    let local_var_content = local_var_resp.text().await?;
391
392    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
393        serde_json::from_str(&local_var_content).map_err(Error::from)
394    } else {
395        let local_var_entity: Option<MessageSearchReqError> = serde_json::from_str(&local_var_content).ok();
396        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
397        Err(Error::ResponseError(local_var_error))
398    }
399}
400
401/// Sends a message to the given channel.
402pub async fn message_send_message_send(configuration: &configuration::Configuration, target: &str, data_message_send: crate::models::DataMessageSend, idempotency_key: Option<&str>) -> Result<crate::models::Message, Error<MessageSendMessageSendError>> {
403    let local_var_configuration = configuration;
404
405    let local_var_client = &local_var_configuration.client;
406
407    let local_var_uri_str = format!("{}/channels/{target}/messages", local_var_configuration.base_path, target=crate::apis::urlencode(target));
408    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
409
410    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
411        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
412    }
413    if let Some(local_var_param_value) = idempotency_key {
414        local_var_req_builder = local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
415    }
416    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
417        let local_var_key = local_var_apikey.key.clone();
418        let local_var_value = match local_var_apikey.prefix {
419            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
420            None => local_var_key,
421        };
422        local_var_req_builder = local_var_req_builder.header("x-session-token", local_var_value);
423    };
424    local_var_req_builder = local_var_req_builder.json(&data_message_send);
425
426    let local_var_req = local_var_req_builder.build()?;
427    let local_var_resp = local_var_client.execute(local_var_req).await?;
428
429    let local_var_status = local_var_resp.status();
430    let local_var_content = local_var_resp.text().await?;
431
432    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
433        serde_json::from_str(&local_var_content).map_err(Error::from)
434    } else {
435        let local_var_entity: Option<MessageSendMessageSendError> = serde_json::from_str(&local_var_content).ok();
436        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
437        Err(Error::ResponseError(local_var_error))
438    }
439}
440