Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3332781
D12937.id42989.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D12937.id42989.diff
View Options
diff --git a/lib/types/tunnelbroker/message-to-tunnelbroker-types.js b/lib/types/tunnelbroker/message-to-tunnelbroker-types.js
--- a/lib/types/tunnelbroker/message-to-tunnelbroker-types.js
+++ b/lib/types/tunnelbroker/message-to-tunnelbroker-types.js
@@ -1,10 +1,19 @@
// @flow
+import type { Platform } from '../device-types.js';
+
export const messageToTunnelbrokerTypes = Object.freeze({
SET_DEVICE_TOKEN: 'SetDeviceToken',
+ SET_DEVICE_TOKEN_WITH_PLATFORM: 'SetDeviceTokenWithPlatform',
});
export type SetDeviceToken = {
+type: 'SetDeviceToken',
+deviceToken: string,
};
+
+export type SetDeviceTokenWithPlatform = {
+ +type: 'SetDeviceTokenWithPlatform',
+ +deviceToken: string,
+ +platform: Platform,
+};
diff --git a/shared/tunnelbroker_messages/src/messages/message_to_tunnelbroker.rs b/shared/tunnelbroker_messages/src/messages/message_to_tunnelbroker.rs
--- a/shared/tunnelbroker_messages/src/messages/message_to_tunnelbroker.rs
+++ b/shared/tunnelbroker_messages/src/messages/message_to_tunnelbroker.rs
@@ -1,4 +1,6 @@
use serde::{Deserialize, Serialize};
+use std::fmt::{Display, Formatter, Result as FmtResult};
+use std::str::FromStr;
/// Message sent by device to set device token.
#[derive(Serialize, Deserialize, PartialEq, Debug)]
@@ -6,3 +8,80 @@
pub struct SetDeviceToken {
pub device_token: String,
}
+
+#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
+#[serde(rename_all = "lowercase")]
+pub enum Platform {
+ Android,
+ IOS,
+ Web,
+ Windows,
+ MacOS,
+}
+
+impl Display for Platform {
+ fn fmt(&self, f: &mut Formatter) -> FmtResult {
+ match self {
+ Platform::Web => write!(f, "web"),
+ Platform::IOS => write!(f, "ios"),
+ Platform::Android => write!(f, "android"),
+ Platform::Windows => write!(f, "windows"),
+ Platform::MacOS => write!(f, "macos"),
+ }
+ }
+}
+
+impl FromStr for Platform {
+ type Err = serde_json::Error;
+ fn from_str(value: &str) -> Result<Self, Self::Err> {
+ let quoted = format!("\"{}\"", value);
+ serde_json::from_str("ed)
+ }
+}
+
+/// Message sent by device to set device with platform.
+#[derive(Serialize, Deserialize, PartialEq, Debug)]
+#[serde(tag = "type", rename_all = "camelCase")]
+pub struct SetDeviceTokenWithPlatform {
+ pub device_token: String,
+ pub platform: Platform,
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_deserialization() {
+ let device_token = "some_device_token";
+ let example_payload = r#"{
+ "type": "SetDeviceTokenWithPlatform",
+ "deviceToken": "some_device_token",
+ "platform": "macos"
+ }"#;
+
+ let deserialized: SetDeviceTokenWithPlatform =
+ serde_json::from_str(example_payload).unwrap();
+
+ assert_eq!(deserialized.device_token, device_token);
+ assert_eq!(deserialized.platform, Platform::MacOS);
+ }
+
+ #[test]
+ fn test_try_from_for_platform() {
+ assert_eq!(Platform::from_str("web").unwrap(), Platform::Web);
+ assert_eq!(Platform::from_str("ios").unwrap(), Platform::IOS);
+ assert_eq!(Platform::from_str("android").unwrap(), Platform::Android);
+ assert_eq!(Platform::from_str("windows").unwrap(), Platform::Windows);
+ assert_eq!(Platform::from_str("macos").unwrap(), Platform::MacOS);
+ }
+
+ #[test]
+ fn test_display_for_platform() {
+ assert_eq!(format!("{}", Platform::Web), "web");
+ assert_eq!(format!("{}", Platform::IOS), "ios");
+ assert_eq!(format!("{}", Platform::Android), "android");
+ assert_eq!(format!("{}", Platform::Windows), "windows");
+ assert_eq!(format!("{}", Platform::MacOS), "macos");
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 1:37 AM (5 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2559315
Default Alt Text
D12937.id42989.diff (3 KB)
Attached To
Mode
D12937: [Tunnelbroker] add message to set Device Token with Platform
Attached
Detach File
Event Timeline
Log In to Comment