Skip to main content

privchat_protocol/rpc/message/
history.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路由: `message/history/get`
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct MessageHistoryGetRequest {
26    /// 用户ID
27    pub user_id: u64,
28    /// 频道ID
29    pub channel_id: u64,
30    /// 起始服务端消息ID(可选,用于分页)
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub before_server_message_id: Option<u64>,
33    /// 限制数量(可选,默认50)
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub limit: Option<u32>,
36}
37
38/// 消息历史响应
39///
40/// RPC路由: `message/history/get`
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct MessageHistoryItem {
43    pub message_id: u64,
44    pub channel_id: u64,
45    pub sender_id: u64,
46    pub content: String,
47    pub message_type: String,
48    pub timestamp: String,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub reply_to_message_id: Option<u64>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub metadata: Option<serde_json::Map<String, serde_json::Value>>,
53    pub revoked: bool,
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub revoked_at: Option<i64>,
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub revoked_by: Option<u64>,
58}
59
60/// 消息历史响应
61///
62/// RPC路由: `message/history/get`
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct MessageHistoryResponse {
65    pub messages: Vec<MessageHistoryItem>,
66    #[serde(default)]
67    pub total: usize,
68    pub has_more: bool,
69}