misskey_api/endpoint/
announcements.rs1use crate::model::{announcement::Announcement, id::Id};
2
3use serde::{Deserialize, Serialize};
4use typed_builder::TypedBuilder;
5
6#[derive(Serialize, Default, Debug, Clone, TypedBuilder)]
7#[serde(rename_all = "camelCase")]
8#[builder(doc)]
9pub struct Request {
10 #[cfg(feature = "12-5-0")]
11 #[cfg_attr(docsrs, doc(cfg(feature = "12-5-0")))]
12 #[serde(skip_serializing_if = "Option::is_none")]
13 #[builder(default, setter(strip_option))]
14 pub with_unreads: Option<bool>,
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<Announcement>>,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 #[builder(default, setter(strip_option))]
24 pub until_id: Option<Id<Announcement>>,
25}
26
27#[derive(Deserialize, Debug, Clone)]
28#[serde(rename_all = "camelCase")]
29pub struct AnnouncementWithIsRead {
30 pub is_read: bool,
31 #[serde(flatten)]
32 pub announcement: Announcement,
33}
34
35impl crate::PaginationItem for AnnouncementWithIsRead {
36 type Id = Id<Announcement>;
37 fn item_id(&self) -> Id<Announcement> {
38 self.announcement.id
39 }
40}
41
42impl misskey_core::Request for Request {
43 type Response = Vec<AnnouncementWithIsRead>;
44 const ENDPOINT: &'static str = "announcements";
45}
46
47impl crate::PaginationRequest for Request {
48 type Item = AnnouncementWithIsRead;
49
50 fn set_since_id(&mut self, id: Id<Announcement>) {
51 self.since_id.replace(id);
52 }
53
54 fn set_until_id(&mut self, id: Id<Announcement>) {
55 self.until_id.replace(id);
56 }
57
58 fn set_limit(&mut self, limit: u8) {
59 self.limit.replace(limit);
60 }
61}
62
63#[cfg(test)]
64mod tests {
65 use super::Request;
66 use crate::test::{ClientExt, TestClient};
67
68 #[tokio::test]
69 async fn request() {
70 let client = TestClient::new();
71 client.test(Request::default()).await;
72 }
73
74 #[tokio::test]
75 async fn request_with_options() {
76 let client = TestClient::new();
77 client
78 .test(Request {
79 #[cfg(feature = "12-5-0")]
80 with_unreads: Some(true),
81 limit: Some(100),
82 since_id: None,
83 until_id: None,
84 })
85 .await;
86 }
87
88 #[tokio::test]
89 async fn request_paginate() {
90 let client = TestClient::new();
91 let announcement = client
92 .admin
93 .test(crate::endpoint::admin::announcements::create::Request {
94 title: "hello".to_string(),
95 text: "ok".to_string(),
96 image_url: None,
97 })
98 .await;
99
100 client
101 .test(Request {
102 #[cfg(feature = "12-5-0")]
103 with_unreads: None,
104 limit: None,
105 since_id: Some(announcement.id.clone()),
106 until_id: Some(announcement.id.clone()),
107 })
108 .await;
109 }
110}