Skip to main content

privchat_protocol/rpc/channel/
direct.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 路由: `channel/direct/get_or_create`
24/// 与添加好友的 source/source_id 规范一致,用于安全与追溯。
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct GetOrCreateDirectChannelRequest {
27    /// 对方用户 ID
28    pub target_user_id: u64,
29    /// 来源类型:search / phone / card_share(好友分享) / group(群聊) / qrcode 等
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub source: Option<String>,
32    /// 来源 ID:如搜索会话 id、群 id、分享 id、好友 id 等
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub source_id: Option<String>,
35
36    /// 当前用户 ID(服务器端填充,客户端不可设置)
37    #[serde(skip_deserializing, default)]
38    pub user_id: u64,
39}
40
41/// 获取或创建私聊会话响应
42///
43/// RPC 路由: `channel/direct/get_or_create`
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct GetOrCreateDirectChannelResponse {
46    /// 会话 ID,用于发消息等
47    pub channel_id: u64,
48    /// 是否本次新创建的会话(false 表示已存在)
49    pub created: bool,
50}