kdeconnect_proto/packet/notification.rs
1//! The Notification plugin syncs notifications between devices.
2use serde::{Deserialize, Serialize};
3
4#[cfg(not(feature = "std"))]
5use alloc::{string::String, vec::Vec};
6
7/// A message sent in the conversation.
8#[derive(Serialize, Deserialize, Debug, Clone)]
9#[serde(rename_all = "camelCase")]
10pub struct NotificationMessage {
11 /// The name of the person who sent the message.
12 pub sender: String,
13
14 /// The content of the message.
15 pub content: String,
16}
17
18/// This packet is a notification.
19///
20/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectnotification>
21#[derive(Serialize, Deserialize, Debug, Clone)]
22#[serde(rename_all = "camelCase")]
23pub struct NotificationPacket {
24 /// The notification ID.
25 pub id: String,
26
27 /// If true the notification with the indicated ID has been closed.
28 #[serde(skip_serializing_if = "Option::is_none")]
29 #[serde(default)]
30 pub is_cancel: Option<bool>,
31
32 /// If true the notification with the indicated ID can be closed.
33 #[serde(skip_serializing_if = "Option::is_none")]
34 #[serde(default)]
35 pub is_clearable: Option<bool>,
36
37 /// If true the notification is preexisting, otherwise the remote device just received it.
38 #[serde(skip_serializing_if = "Option::is_none")]
39 #[serde(default)]
40 pub silent: Option<bool>,
41
42 /// A UNIX epoch timestamp (ms) in string form.
43 #[serde(skip_serializing_if = "Option::is_none")]
44 #[serde(default)]
45 pub time: Option<String>,
46
47 /// The notifying application name.
48 pub app_name: String,
49
50 /// The notification title and text in a single string.
51 pub ticker: String,
52
53 /// The notification title.
54 pub title: String,
55
56 /// The notification body.
57 pub text: String,
58
59 /// The group name if the notification is a conversation message coming from a group.
60 #[serde(skip_serializing_if = "Option::is_none")]
61 #[serde(default)]
62 pub group_name: Option<String>,
63
64 /// An MD5 hash of the notification icon. If the packet contains this field, it will be accompanied by payload transfer information.
65 #[serde(skip_serializing_if = "Option::is_none")]
66 #[serde(default)]
67 pub payload_hash: Option<String>,
68
69 /// A list of messages in the notification if it's a conversation.
70 #[serde(skip_serializing_if = "Option::is_none")]
71 #[serde(default)]
72 pub conversation: Option<Vec<NotificationMessage>>,
73
74 /// A list of action names for the notification. Respond with kdeconnect.notification.action to activate.
75 #[serde(skip_serializing_if = "Option::is_none")]
76 #[serde(default)]
77 pub actions: Option<Vec<String>>,
78
79 /// The UUID for repliable notifications (eg. chat). Respond with kdeconnect.notification.reply to reply.
80 #[serde(skip_serializing_if = "Option::is_none")]
81 #[serde(default)]
82 pub request_reply_id: Option<String>,
83}
84
85/// This packet is an activation of a notification action.
86///
87/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectnotificationaction>
88#[derive(Serialize, Deserialize, Debug, Clone)]
89#[serde(rename_all = "camelCase")]
90pub struct NotificationActionPacket {
91 /// The notification ID.
92 pub key: String,
93
94 /// The notification action name.
95 pub action: String,
96}
97
98/// This packet is a reply for a repliable notification.
99///
100/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectnotificationreply>
101#[derive(Serialize, Deserialize, Debug, Clone)]
102#[serde(rename_all = "camelCase")]
103pub struct NotificationReplyPacket {
104 /// The message to reply with.
105 pub message: String,
106
107 /// The reply ID of the notification.
108 pub request_reply_id: String,
109}
110
111/// This packet is a request for notifications.
112///
113/// <https://invent.kde.org/network/kdeconnect-meta/blob/master/protocol.md#kdeconnectnotificationrequest>
114#[derive(Serialize, Deserialize, Debug, Clone)]
115#[serde(rename_all = "camelCase")]
116pub struct NotificationRequestPacket {
117 /// If present, holds the ID of a notification that should be closed.
118 #[serde(skip_serializing_if = "Option::is_none")]
119 #[serde(default)]
120 pub cancel: Option<bool>,
121
122 /// Indicates this is a request for the notifications.
123 #[serde(skip_serializing_if = "Option::is_none")]
124 #[serde(default)]
125 pub request: Option<bool>,
126}