Page MenuHomePhabricator

D12767.id42527.diff
No OneTemporary

D12767.id42527.diff

diff --git a/services/tunnelbroker/src/notifs/fcm/firebase_message.rs b/services/tunnelbroker/src/notifs/fcm/firebase_message.rs
new file mode 100644
--- /dev/null
+++ b/services/tunnelbroker/src/notifs/fcm/firebase_message.rs
@@ -0,0 +1,48 @@
+use serde::{Deserialize, Serialize};
+use serde_json::Value;
+
+#[derive(Debug, Serialize)]
+pub struct FCMMessageWrapper {
+ pub message: FCMMessage,
+}
+
+/// Message to send by Firebase Cloud Messaging Service.
+#[derive(Debug, Serialize)]
+pub struct FCMMessage {
+ /// Arbitrary key/value payload, which must be UTF-8 encoded.
+ pub data: Value,
+ /// Target to send a notification/message to.
+ pub token: String,
+ /// Android specific options for messages sent through FCM connection server.
+ pub android: AndroidConfig,
+}
+
+#[derive(Debug, Serialize)]
+pub struct AndroidConfig {
+ /// Message priority. Can take "normal" and "high" values.
+ pub priority: AndroidMessagePriority,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+#[serde(rename_all = "UPPERCASE")]
+pub enum AndroidMessagePriority {
+ /// Default priority for data messages. Normal priority messages won't
+ /// open network connections on a sleeping device, and their delivery
+ /// may be delayed to conserve the battery.
+ Normal,
+ /// Default priority for notification messages. FCM attempts to deliver
+ /// high priority messages immediately, allowing the FCM service to wake
+ /// a sleeping device when possible and open a network connection to
+ /// your app server.
+ High,
+}
+
+impl AndroidMessagePriority {
+ pub fn from_str(value: &str) -> Option<Self> {
+ match value {
+ "NORMAL" => Some(AndroidMessagePriority::Normal),
+ "HIGH" => Some(AndroidMessagePriority::High),
+ _ => None,
+ }
+ }
+}
diff --git a/services/tunnelbroker/src/notifs/fcm/mod.rs b/services/tunnelbroker/src/notifs/fcm/mod.rs
--- a/services/tunnelbroker/src/notifs/fcm/mod.rs
+++ b/services/tunnelbroker/src/notifs/fcm/mod.rs
@@ -4,6 +4,7 @@
pub mod config;
mod error;
+mod firebase_message;
mod token;
#[derive(Clone)]

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 11:31 AM (21 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2579248
Default Alt Text
D12767.id42527.diff (2 KB)

Event Timeline