privchat_protocol/rpc/device.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
18use serde::{Deserialize, Serialize};
19
20/// RPC: device/push/update
21/// 更新设备推送状态(前台/后台切换时调用)
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct DevicePushUpdateRequest {
24 /// 设备ID
25 pub device_id: String,
26 /// 是否需要推送(true: 需要推送, false: 不需要推送)
27 pub apns_armed: bool,
28 /// 可选的推送令牌(如果提供则更新)
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub push_token: Option<String>,
31 /// 可选的推送厂商(apns/fcm/hms/xiaomi/oppo/vivo/honor/lenovo/zte/meizu)
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub vendor: Option<String>,
34}
35
36/// 设备推送状态更新响应
37///
38/// RPC路由: `device/push/update`
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct DevicePushUpdateResponse {
41 /// 设备ID
42 pub device_id: String,
43 /// 推送状态
44 pub apns_armed: bool,
45 /// 用户级别:所有设备都需要推送
46 pub user_push_enabled: bool,
47}
48
49/// RPC: device/push/status
50/// 获取设备推送状态
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct DevicePushStatusRequest {
53 /// 可选的设备ID(不提供则返回所有设备)
54 #[serde(skip_serializing_if = "Option::is_none")]
55 pub device_id: Option<String>,
56}
57
58/// 设备推送状态查询响应
59///
60/// RPC路由: `device/push/status`
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct DevicePushStatusResponse {
63 /// 设备列表
64 pub devices: Vec<DevicePushInfo>,
65 /// 用户级别:所有设备都需要推送
66 pub user_push_enabled: bool,
67}
68
69/// 设备推送信息
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct DevicePushInfo {
72 /// 设备ID
73 pub device_id: String,
74 /// 是否需要推送
75 pub apns_armed: bool,
76 /// 是否已连接
77 pub connected: bool,
78 /// 平台
79 pub platform: String,
80 /// 推送厂商
81 pub vendor: String,
82}