Skip to main content

privchat_protocol/rpc/
channel_broadcast.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/broadcast/subscribe`
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct ChannelBroadcastSubscribeRequest {
26    /// 用户ID(服务器端从 ctx 填充)
27    #[serde(default)]
28    pub user_id: u64,
29
30    /// 广播频道ID
31    pub channel_id: u64,
32}
33
34/// 订阅广播频道响应
35///
36/// RPC路由: `channel/broadcast/subscribe`
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct ChannelBroadcastSubscribeResponse {
39    pub status: String,
40    pub message: String,
41    pub channel_id: u64,
42    pub user_id: u64,
43    pub subscribed_at: String,
44}
45
46/// 通用动作响应(当前 create/publish/list/content/list 在服务端返回该形态)
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct ChannelBroadcastActionResponse {
49    pub status: String,
50    pub action: String,
51    pub timestamp: String,
52}
53
54/// 创建广播频道请求
55///
56/// RPC路由: `channel/broadcast/create`
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct ChannelBroadcastCreateRequest {
59    pub name: String,
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub description: Option<String>,
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub avatar_url: Option<String>,
64}
65
66/// 创建广播频道响应
67///
68/// RPC路由: `channel/broadcast/create`
69pub type ChannelBroadcastCreateResponse = ChannelBroadcastActionResponse;
70
71/// 获取广播频道列表请求
72///
73/// RPC路由: `channel/broadcast/list`
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct ChannelBroadcastListRequest {
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub page: Option<u32>,
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub page_size: Option<u32>,
80}
81
82/// 获取广播频道列表响应
83///
84/// RPC路由: `channel/broadcast/list`
85pub type ChannelBroadcastListResponse = ChannelBroadcastActionResponse;
86
87/// 频道内容发布请求
88///
89/// RPC路由: `channel/content/publish`
90#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct ChannelContentPublishRequest {
92    pub channel_id: u64,
93    pub content: String,
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub title: Option<String>,
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub content_type: Option<String>,
98}
99
100/// 频道内容发布响应
101///
102/// RPC路由: `channel/content/publish`
103pub type ChannelContentPublishResponse = ChannelBroadcastActionResponse;
104
105/// 频道内容列表请求
106///
107/// RPC路由: `channel/content/list`
108#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct ChannelContentListRequest {
110    pub channel_id: u64,
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub page: Option<u32>,
113    #[serde(skip_serializing_if = "Option::is_none")]
114    pub page_size: Option<u32>,
115}
116
117/// 频道内容列表响应
118///
119/// RPC路由: `channel/content/list`
120pub type ChannelContentListResponse = ChannelBroadcastActionResponse;