misskey_api/endpoint/notes/
user_list_timeline.rs

1use crate::model::{id::Id, note::Note, user_list::UserList};
2
3use chrono::{serde::ts_milliseconds_option, DateTime, Utc};
4use serde::Serialize;
5use typed_builder::TypedBuilder;
6
7#[derive(Serialize, Debug, Clone, TypedBuilder)]
8#[serde(rename_all = "camelCase")]
9#[builder(doc)]
10pub struct Request {
11    pub list_id: Id<UserList>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    #[builder(default, setter(strip_option))]
14    pub with_files: Option<bool>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    #[builder(default, setter(strip_option))]
17    pub include_my_renotes: Option<bool>,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    #[builder(default, setter(strip_option))]
20    pub include_renoted_my_notes: Option<bool>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    #[builder(default, setter(strip_option))]
23    pub include_local_renotes: Option<bool>,
24    /// 1 .. 100
25    #[serde(skip_serializing_if = "Option::is_none")]
26    #[builder(default, setter(strip_option))]
27    pub limit: Option<u8>,
28    #[serde(skip_serializing_if = "Option::is_none")]
29    #[builder(default, setter(strip_option))]
30    pub since_id: Option<Id<Note>>,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    #[builder(default, setter(strip_option))]
33    pub until_id: Option<Id<Note>>,
34    #[serde(
35        skip_serializing_if = "Option::is_none",
36        with = "ts_milliseconds_option"
37    )]
38    #[builder(default, setter(strip_option, into))]
39    pub since_date: Option<DateTime<Utc>>,
40    #[serde(
41        skip_serializing_if = "Option::is_none",
42        with = "ts_milliseconds_option"
43    )]
44    #[builder(default, setter(strip_option, into))]
45    pub until_date: Option<DateTime<Utc>>,
46}
47
48impl misskey_core::Request for Request {
49    type Response = Vec<Note>;
50    const ENDPOINT: &'static str = "notes/user-list-timeline";
51}
52
53impl_pagination!(Request, Note);
54
55#[cfg(test)]
56mod tests {
57    use super::Request;
58    use crate::test::{ClientExt, TestClient};
59
60    #[tokio::test]
61    async fn request() {
62        let client = TestClient::new();
63        let list = client
64            .test(crate::endpoint::users::lists::create::Request {
65                name: "testlist".to_string(),
66            })
67            .await;
68
69        client
70            .test(Request {
71                list_id: list.id,
72                with_files: None,
73                include_my_renotes: None,
74                include_renoted_my_notes: None,
75                include_local_renotes: None,
76                limit: None,
77                since_id: None,
78                until_id: None,
79                since_date: None,
80                until_date: None,
81            })
82            .await;
83    }
84
85    #[tokio::test]
86    async fn request_with_options() {
87        let client = TestClient::new();
88        let list = client
89            .test(crate::endpoint::users::lists::create::Request {
90                name: "testlist".to_string(),
91            })
92            .await;
93
94        client
95            .test(Request {
96                list_id: list.id,
97                with_files: Some(true),
98                include_my_renotes: Some(false),
99                include_renoted_my_notes: Some(false),
100                include_local_renotes: Some(false),
101                limit: None,
102                since_id: None,
103                until_id: None,
104                since_date: None,
105                until_date: None,
106            })
107            .await;
108    }
109
110    #[tokio::test]
111    async fn request_with_limit() {
112        let client = TestClient::new();
113        let list = client
114            .test(crate::endpoint::users::lists::create::Request {
115                name: "testlist".to_string(),
116            })
117            .await;
118
119        client
120            .test(Request {
121                list_id: list.id,
122                with_files: None,
123                include_my_renotes: None,
124                include_renoted_my_notes: None,
125                include_local_renotes: None,
126                limit: Some(100),
127                since_id: None,
128                until_id: None,
129                since_date: None,
130                until_date: None,
131            })
132            .await;
133    }
134
135    #[tokio::test]
136    async fn request_paginate() {
137        let client = TestClient::new();
138        let list = client
139            .test(crate::endpoint::users::lists::create::Request {
140                name: "testlist".to_string(),
141            })
142            .await;
143        let note = client.create_note(Some("test"), None, None).await;
144
145        client
146            .test(Request {
147                list_id: list.id,
148                with_files: None,
149                include_my_renotes: None,
150                include_renoted_my_notes: None,
151                include_local_renotes: None,
152                limit: None,
153                since_id: Some(note.id.clone()),
154                until_id: Some(note.id.clone()),
155                since_date: None,
156                until_date: None,
157            })
158            .await;
159    }
160
161    #[tokio::test]
162    async fn request_with_date() {
163        let client = TestClient::new();
164        let list = client
165            .test(crate::endpoint::users::lists::create::Request {
166                name: "testlist".to_string(),
167            })
168            .await;
169        let now = chrono::Utc::now();
170
171        client
172            .test(Request {
173                list_id: list.id,
174                with_files: None,
175                include_my_renotes: None,
176                include_renoted_my_notes: None,
177                include_local_renotes: None,
178                limit: None,
179                since_id: None,
180                until_id: None,
181                since_date: Some(now),
182                until_date: Some(now),
183            })
184            .await;
185    }
186}