Skip to main content

privchat_protocol/rpc/group/
settings.rs

1// Copyright 2025 Shanghai Boyu Information Technology Co., Ltd.
2// https://privchat.dev
3//
4// Author: zoujiaqing <zoujiaqing@gmail.com>
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10//     http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18/// 群组设置相关 RPC
19use serde::{Deserialize, Serialize};
20
21/// 更新群组设置请求
22///
23/// RPC路由: `group/settings/update`
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct GroupSettingsPatch {
26    /// 是否开启加群审批(可选)
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub join_need_approval: Option<bool>,
29    /// 成员是否可邀请(可选)
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub member_can_invite: Option<bool>,
32    /// 是否全员禁言(可选)
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub all_muted: Option<bool>,
35    /// 最大成员数(可选)
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub max_members: Option<u32>,
38    /// 群公告(可选)
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub announcement: Option<String>,
41    /// 群描述(可选)
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub description: Option<String>,
44}
45
46/// 更新群组设置请求
47///
48/// RPC路由: `group/settings/update`
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct GroupSettingsUpdateRequest {
51    /// 群组ID
52    pub group_id: u64,
53    /// 操作者ID
54    pub operator_id: u64,
55    /// 更新项
56    pub settings: GroupSettingsPatch,
57}
58
59/// 获取群组设置请求
60///
61/// RPC路由: `group/settings/get`
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct GroupSettingsGetRequest {
64    /// 群组ID
65    pub group_id: u64,
66    /// 用户ID
67    pub user_id: u64,
68}
69
70/// 全员禁言请求
71///
72/// RPC路由: `group/settings/mute_all`
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct GroupMuteAllRequest {
75    /// 群组ID
76    pub group_id: u64,
77    /// 操作者ID
78    pub operator_id: u64,
79    /// 是否全员禁言
80    #[serde(alias = "mute_all")]
81    pub muted: bool,
82}
83
84/// 更新群组设置响应
85///
86/// RPC路由: `group/settings/update`
87#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct GroupSettingsUpdateResponse {
89    pub success: bool,
90    pub group_id: String,
91    pub message: String,
92    pub updated_count: u32,
93    pub updated_at: String,
94}
95
96/// 获取群组设置响应
97///
98/// RPC路由: `group/settings/get`
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct GroupSettingsData {
101    pub join_need_approval: bool,
102    pub member_can_invite: bool,
103    pub all_muted: bool,
104    pub max_members: usize,
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub announcement: Option<String>,
107    #[serde(skip_serializing_if = "Option::is_none")]
108    pub description: Option<String>,
109    pub created_at: String,
110    pub updated_at: String,
111}
112
113/// 获取群组设置响应
114///
115/// RPC路由: `group/settings/get`
116#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct GroupSettingsGetResponse {
118    pub group_id: u64,
119    pub settings: GroupSettingsData,
120}
121
122/// 全员禁言响应
123///
124/// RPC路由: `group/settings/mute_all`
125#[derive(Debug, Clone, Serialize, Deserialize)]
126pub struct GroupMuteAllResponse {
127    pub success: bool,
128    pub group_id: String,
129    pub all_muted: bool,
130    pub message: String,
131    pub operator_id: String,
132    pub updated_at: String,
133}