misskey_api/endpoint/channels/
timeline.rs

1use crate::model::{channel::Channel, id::Id, note::Note};
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 channel_id: Id<Channel>,
12    /// 1 .. 100
13    #[serde(skip_serializing_if = "Option::is_none")]
14    #[builder(default, setter(strip_option))]
15    pub limit: Option<u8>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    #[builder(default, setter(strip_option))]
18    pub since_id: Option<Id<Note>>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    #[builder(default, setter(strip_option))]
21    pub until_id: Option<Id<Note>>,
22    #[serde(
23        skip_serializing_if = "Option::is_none",
24        with = "ts_milliseconds_option"
25    )]
26    #[builder(default, setter(strip_option, into))]
27    pub since_date: Option<DateTime<Utc>>,
28    #[serde(
29        skip_serializing_if = "Option::is_none",
30        with = "ts_milliseconds_option"
31    )]
32    #[builder(default, setter(strip_option, into))]
33    pub until_date: Option<DateTime<Utc>>,
34}
35
36impl misskey_core::Request for Request {
37    type Response = Vec<Note>;
38    const ENDPOINT: &'static str = "channels/timeline";
39}
40
41impl_pagination!(Request, Note);
42
43#[cfg(test)]
44mod tests {
45    use super::Request;
46    use crate::test::{ClientExt, TestClient};
47
48    #[tokio::test]
49    async fn request() {
50        let client = TestClient::new();
51        let channel = client
52            .test(crate::endpoint::channels::create::Request {
53                name: "test".to_string(),
54                description: None,
55                banner_id: None,
56            })
57            .await;
58
59        client
60            .test(Request {
61                channel_id: channel.id,
62                limit: None,
63                since_id: None,
64                until_id: None,
65                since_date: None,
66                until_date: None,
67            })
68            .await;
69    }
70
71    #[tokio::test]
72    async fn request_with_limit() {
73        let client = TestClient::new();
74        let channel = client
75            .test(crate::endpoint::channels::create::Request {
76                name: "test".to_string(),
77                description: None,
78                banner_id: None,
79            })
80            .await;
81
82        client
83            .test(Request {
84                channel_id: channel.id,
85                limit: Some(100),
86                since_id: None,
87                until_id: None,
88                since_date: None,
89                until_date: None,
90            })
91            .await;
92    }
93
94    #[tokio::test]
95    async fn request_paginate() {
96        let client = TestClient::new();
97        let channel = client
98            .test(crate::endpoint::channels::create::Request {
99                name: "test".to_string(),
100                description: None,
101                banner_id: None,
102            })
103            .await;
104        let note = client
105            .test(crate::endpoint::notes::create::Request {
106                visibility: None,
107                visible_user_ids: None,
108                text: Some("some text".to_string()),
109                cw: None,
110                via_mobile: None,
111                local_only: None,
112                no_extract_mentions: None,
113                no_extract_hashtags: None,
114                no_extract_emojis: None,
115                file_ids: None,
116                reply_id: None,
117                renote_id: None,
118                poll: None,
119                channel_id: Some(channel.id.clone()),
120            })
121            .await
122            .created_note;
123
124        client
125            .test(Request {
126                channel_id: channel.id,
127                limit: None,
128                since_id: Some(note.id.clone()),
129                until_id: Some(note.id.clone()),
130                since_date: None,
131                until_date: None,
132            })
133            .await;
134    }
135
136    #[tokio::test]
137    async fn request_with_date() {
138        let client = TestClient::new();
139        let channel = client
140            .test(crate::endpoint::channels::create::Request {
141                name: "test".to_string(),
142                description: None,
143                banner_id: None,
144            })
145            .await;
146        let now = chrono::Utc::now();
147
148        client
149            .test(Request {
150                channel_id: channel.id,
151                limit: None,
152                since_id: None,
153                until_id: None,
154                since_date: Some(now),
155                until_date: Some(now),
156            })
157            .await;
158    }
159}