gewe_http/group/
settings.rs

1use crate::client::GeweHttpClient;
2use gewe_core::{
3    GetChatroomAnnouncementRequest, GetChatroomAnnouncementResponse, GetChatroomQrCodeRequest,
4    GetChatroomQrCodeResponse, PinChatRequest, SaveContractListRequest,
5    SetChatroomAnnouncementRequest, SetMsgSilenceRequest,
6};
7use tracing::instrument;
8
9impl GeweHttpClient {
10    #[instrument(skip(self))]
11    pub async fn set_chatroom_announcement(
12        &self,
13        req: SetChatroomAnnouncementRequest<'_>,
14    ) -> Result<(), gewe_core::GeweError> {
15        let _ = self
16            .post_api::<_, ()>("gewe/v2/api/group/setChatroomAnnouncement", &req)
17            .await?;
18        Ok(())
19    }
20
21    #[instrument(skip(self))]
22    pub async fn get_chatroom_announcement(
23        &self,
24        req: GetChatroomAnnouncementRequest<'_>,
25    ) -> Result<GetChatroomAnnouncementResponse, gewe_core::GeweError> {
26        let env = self
27            .post_api::<_, GetChatroomAnnouncementResponse>(
28                "gewe/v2/api/group/getChatroomAnnouncement",
29                &req,
30            )
31            .await?;
32        env.data.ok_or(gewe_core::GeweError::MissingData)
33    }
34
35    #[instrument(skip(self))]
36    pub async fn get_chatroom_qr_code(
37        &self,
38        req: GetChatroomQrCodeRequest<'_>,
39    ) -> Result<GetChatroomQrCodeResponse, gewe_core::GeweError> {
40        let env = self
41            .post_api::<_, GetChatroomQrCodeResponse>("gewe/v2/api/group/getChatroomQrCode", &req)
42            .await?;
43        env.data.ok_or(gewe_core::GeweError::MissingData)
44    }
45
46    #[instrument(skip(self))]
47    pub async fn save_contract_list(
48        &self,
49        req: SaveContractListRequest<'_>,
50    ) -> Result<(), gewe_core::GeweError> {
51        let _ = self
52            .post_api::<_, ()>("gewe/v2/api/group/saveContractList", &req)
53            .await?;
54        Ok(())
55    }
56
57    #[instrument(skip(self))]
58    pub async fn pin_chat(&self, req: PinChatRequest<'_>) -> Result<(), gewe_core::GeweError> {
59        let _ = self
60            .post_api::<_, ()>("gewe/v2/api/group/pinChat", &req)
61            .await?;
62        Ok(())
63    }
64
65    #[instrument(skip(self))]
66    pub async fn set_msg_silence(
67        &self,
68        req: SetMsgSilenceRequest<'_>,
69    ) -> Result<(), gewe_core::GeweError> {
70        let _ = self
71            .post_api::<_, ()>("gewe/v2/api/group/setMsgSilence", &req)
72            .await?;
73        Ok(())
74    }
75}
76
77#[cfg(test)]
78mod tests {
79    use super::*;
80
81    #[test]
82    fn test_set_chatroom_announcement_request() {
83        let req = SetChatroomAnnouncementRequest {
84            app_id: "test_app",
85            chatroom_id: "chatroom_123",
86            content: "New announcement",
87        };
88        let json = serde_json::to_string(&req).expect("Failed to serialize");
89        assert!(json.contains("appId"));
90        assert!(json.contains("content"));
91    }
92
93    #[test]
94    fn test_get_chatroom_qr_code_request() {
95        let req = GetChatroomQrCodeRequest {
96            app_id: "test_app",
97            chatroom_id: "chatroom_123",
98        };
99        let json = serde_json::to_string(&req).expect("Failed to serialize");
100        assert!(json.contains("appId"));
101        assert!(json.contains("chatroomId"));
102    }
103
104    #[test]
105    fn test_pin_chat_request() {
106        let req = PinChatRequest {
107            app_id: "test_app",
108            chatroom_id: "chatroom_123",
109            add: true,
110        };
111        let json = serde_json::to_string(&req).expect("Failed to serialize");
112        assert!(json.contains("appId"));
113        assert!(json.contains("chatroomId"));
114    }
115
116    #[test]
117    fn test_set_msg_silence_request() {
118        let req = SetMsgSilenceRequest {
119            app_id: "test_app",
120            chatroom_id: "chatroom_123",
121            switch_: true,
122        };
123        let json = serde_json::to_string(&req).expect("Failed to serialize");
124        assert!(json.contains("appId"));
125        assert!(json.contains("chatroomId"));
126    }
127}