Skip to main content

privchat_protocol/rpc/group/
qrcode.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/qrcode/generate`
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct GroupQRCodeGenerateRequest {
26    /// 群组ID
27    pub group_id: u64,
28    /// 过期时间(秒)(可选)
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub expire_seconds: Option<u64>,
31
32    /// 操作者ID(服务器端填充,客户端不可设置)
33    #[serde(skip_deserializing, default)]
34    pub operator_id: u64,
35}
36
37/// 通过二维码加入群组请求
38///
39/// RPC路由: `group/qrcode/join`
40///
41/// 客户端扫描二维码后,应在本地解析 URL 提取 qr_key 和 token,然后发送此请求。
42///
43/// 示例:
44/// ```json
45/// {
46///   "qr_key": "abc123",
47///   "token": "xyz",
48///   "message": "我想加入群组"
49/// }
50/// ```
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct GroupQRCodeJoinRequest {
53    /// QR Key(从二维码 URL 中提取的 qrkey 参数)
54    pub qr_key: String,
55
56    /// Token(可选,从二维码 URL 中提取的 token 参数,用于群组邀请验证)
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub token: Option<String>,
59
60    /// 申请理由(可选)
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub message: Option<String>,
63
64    /// 用户ID(服务器端填充,客户端不可设置)
65    #[serde(skip_deserializing, default)]
66    pub user_id: u64,
67}
68
69/// 生成群组二维码响应
70///
71/// RPC路由: `group/qrcode/generate`
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct GroupQRCodeGenerateResponse {
74    pub qr_key: String,
75    pub qr_code: String,           // privchat://group/get?qrkey=xxx&token=yyy
76    pub expire_at: Option<String>, // ISO 8601
77    pub group_id: u64,
78    pub created_at: String, // ISO 8601
79}
80
81/// 通过二维码加入群组响应
82///
83/// RPC路由: `group/qrcode/join`
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct GroupQRCodeJoinResponse {
86    pub status: String, // "pending" 或 "joined"
87    pub group_id: u64,
88    pub request_id: Option<String>, // 如果需要审批
89    pub message: Option<String>,
90    pub expires_at: Option<String>, // ISO 8601
91    pub user_id: Option<u64>,       // 如果已加入
92    pub joined_at: Option<String>,  // ISO 8601,如果已加入
93}