misskey_api/endpoint/i/
notifications.rs1use std::collections::HashSet;
2
3use crate::model::{
4 id::Id,
5 notification::{Notification, NotificationType},
6};
7
8use serde::Serialize;
9use typed_builder::TypedBuilder;
10
11#[derive(Serialize, Default, Debug, Clone, TypedBuilder)]
12#[serde(rename_all = "camelCase")]
13#[builder(doc)]
14pub struct Request {
15 #[serde(skip_serializing_if = "Option::is_none")]
17 #[builder(default, setter(strip_option))]
18 pub limit: Option<u8>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 #[builder(default, setter(strip_option))]
21 pub since_id: Option<Id<Notification>>,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 #[builder(default, setter(strip_option))]
24 pub until_id: Option<Id<Notification>>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 #[builder(default, setter(strip_option))]
27 pub following: Option<bool>,
28 #[serde(skip_serializing_if = "Option::is_none")]
29 #[builder(default, setter(strip_option))]
30 pub mark_as_read: Option<bool>,
31 #[serde(skip_serializing_if = "Option::is_none")]
32 #[builder(default, setter(strip_option))]
33 pub include_types: Option<HashSet<NotificationType>>,
34 #[serde(skip_serializing_if = "Option::is_none")]
35 #[builder(default, setter(strip_option))]
36 pub exclude_types: Option<HashSet<NotificationType>>,
37}
38
39impl misskey_core::Request for Request {
40 type Response = Vec<Notification>;
41 const ENDPOINT: &'static str = "i/notifications";
42}
43
44impl_pagination!(Request, Notification);
45
46#[cfg(test)]
47mod tests {
48 use super::Request;
49 use crate::test::{ClientExt, TestClient};
50
51 #[tokio::test]
52 async fn request() {
53 let client = TestClient::new();
54 client.test(Request::default()).await;
55 }
56
57 #[tokio::test]
58 async fn request_with_limit() {
59 let client = TestClient::new();
60 client
61 .test(Request {
62 limit: Some(100),
63 since_id: None,
64 until_id: None,
65 following: None,
66 mark_as_read: None,
67 include_types: None,
68 exclude_types: None,
69 })
70 .await;
71 }
72
73 #[tokio::test]
74 async fn request_with_options() {
75 use crate::model::notification::NotificationType;
76
77 let client = TestClient::new();
78 client
79 .test(Request {
80 limit: None,
81 since_id: None,
82 until_id: None,
83 following: Some(true),
84 mark_as_read: Some(false),
85 include_types: Some(
86 vec![NotificationType::Follow, NotificationType::Reply]
87 .into_iter()
88 .collect(),
89 ),
90 exclude_types: Some(vec![NotificationType::Mention].into_iter().collect()),
91 })
92 .await;
93 }
94
95 #[tokio::test]
96 #[cfg(feature = "12-27-0")]
97 async fn request_paginate() {
98 let client = TestClient::new();
99 client
100 .test(crate::endpoint::notifications::create::Request {
101 body: "hi".to_string(),
102 header: None,
103 icon: None,
104 })
105 .await;
106
107 let mut notification = None;
108 while notification.is_none() {
109 notification = client
110 .test(Request {
111 limit: None,
112 since_id: None,
113 until_id: None,
114 following: None,
115 mark_as_read: None,
116 include_types: None,
117 exclude_types: None,
118 })
119 .await
120 .pop();
121 }
122 let notification_id = notification.unwrap().id;
123
124 client
125 .test(Request {
126 limit: None,
127 since_id: Some(notification_id.clone()),
128 until_id: Some(notification_id.clone()),
129 following: None,
130 mark_as_read: None,
131 include_types: None,
132 exclude_types: None,
133 })
134 .await;
135 }
136}