misskey_api/endpoint/notes/
mentions.rs1use crate::model::{
2 id::Id,
3 note::{Note, Visibility},
4};
5
6use serde::Serialize;
7use typed_builder::TypedBuilder;
8
9#[derive(Serialize, Default, Debug, Clone, TypedBuilder)]
10#[serde(rename_all = "camelCase")]
11#[builder(doc)]
12pub struct Request {
13 #[serde(skip_serializing_if = "Option::is_none")]
14 #[builder(default, setter(strip_option))]
15 pub following: Option<bool>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 #[builder(default, setter(strip_option))]
18 pub visibility: Option<Visibility>,
19 #[serde(skip_serializing_if = "Option::is_none")]
21 #[builder(default, setter(strip_option))]
22 pub limit: Option<u8>,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 #[builder(default, setter(strip_option))]
25 pub since_id: Option<Id<Note>>,
26 #[serde(skip_serializing_if = "Option::is_none")]
27 #[builder(default, setter(strip_option))]
28 pub until_id: Option<Id<Note>>,
29}
30
31impl misskey_core::Request for Request {
32 type Response = Vec<Note>;
33 const ENDPOINT: &'static str = "notes/mentions";
34}
35
36impl_pagination!(Request, Note);
37
38#[cfg(test)]
39mod tests {
40 use super::Request;
41 use crate::test::{ClientExt, TestClient};
42
43 #[tokio::test]
44 async fn request() {
45 let client = TestClient::new();
46 client.test(Request::default()).await;
47 }
48
49 #[tokio::test]
50 async fn request_with_option() {
51 let client = TestClient::new();
52 client
53 .test(Request {
54 following: Some(true),
55 visibility: None,
56 limit: None,
57 since_id: None,
58 until_id: None,
59 })
60 .await;
61 }
62
63 #[tokio::test]
64 async fn request_with_visibilty() {
65 use crate::model::note::Visibility;
66
67 let client = TestClient::new();
68
69 client
70 .test(Request {
71 following: None,
72 visibility: Some(Visibility::Home),
73 limit: None,
74 since_id: None,
75 until_id: None,
76 })
77 .await;
78 client
79 .test(Request {
80 following: None,
81 visibility: Some(Visibility::Public),
82 limit: None,
83 since_id: None,
84 until_id: None,
85 })
86 .await;
87 client
88 .test(Request {
89 following: None,
90 visibility: Some(Visibility::Followers),
91 limit: None,
92 since_id: None,
93 until_id: None,
94 })
95 .await;
96 client
97 .test(Request {
98 following: None,
99 visibility: Some(Visibility::Specified),
100 limit: None,
101 since_id: None,
102 until_id: None,
103 })
104 .await;
105 }
106
107 #[tokio::test]
108 async fn request_with_limit() {
109 let client = TestClient::new();
110 client
111 .test(Request {
112 following: None,
113 visibility: None,
114 limit: Some(100),
115 since_id: None,
116 until_id: None,
117 })
118 .await;
119 }
120
121 #[tokio::test]
122 async fn request_paginate() {
123 let client = TestClient::new();
124 let me = client.user.me().await;
125 let text = format!("hey @{}", me.username);
126 let note = client.admin.create_note(Some(&text), None, None).await;
127
128 client
129 .user
130 .test(Request {
131 following: None,
132 visibility: None,
133 limit: None,
134 since_id: Some(note.id.clone()),
135 until_id: Some(note.id.clone()),
136 })
137 .await;
138 }
139}