privchat_protocol/rpc/account/search.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路由: `account/search/query`
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct AccountSearchQueryRequest {
26 /// 搜索关键词(用户名、手机号等)
27 pub query: String,
28 /// 页码(可选)
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub page: Option<u32>,
31 /// 每页数量(可选)
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub page_size: Option<u32>,
34
35 /// 搜索发起者ID(服务器端填充,客户端不可设置)
36 #[serde(skip_deserializing, default)]
37 pub from_user_id: u64,
38}
39
40/// 通过二维码搜索用户请求
41///
42/// RPC路由: `account/search/by_qrcode`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct AccountSearchByQRCodeRequest {
45 /// 二维码Key
46 pub qr_key: String,
47 /// Token(可选)
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub token: Option<String>,
50
51 /// 搜索发起者ID(服务器端填充,客户端不可设置)
52 #[serde(skip_deserializing, default)]
53 pub searcher_id: u64,
54}
55
56/// 搜索到的用户信息
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct SearchedUser {
59 /// 用户ID
60 pub user_id: u64,
61 /// 用户名
62 pub username: String,
63 /// 昵称
64 pub nickname: String,
65 /// 头像URL
66 #[serde(skip_serializing_if = "Option::is_none")]
67 pub avatar_url: Option<String>,
68 /// 用户类型(0: 普通用户, 1: 系统用户, 2: 机器人)
69 pub user_type: i16,
70 /// 搜索会话ID(用于后续操作)
71 pub search_session_id: u64,
72 /// 是否已是好友
73 pub is_friend: bool,
74 /// 是否可以发送消息
75 pub can_send_message: bool,
76}
77
78/// 搜索响应(返回用户信息列表)
79#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct AccountSearchResponse {
81 /// 搜索到的用户列表
82 pub users: Vec<SearchedUser>,
83 /// 总数
84 pub total: usize,
85 /// 搜索关键词
86 pub query: String,
87}