Skip to content

Commit

Permalink
Add sync_id and session_id fields to Activity. (#1131)
Browse files Browse the repository at this point in the history
Signed-off-by: Kamran Mackey <kamranm1200@gmail.com>
  • Loading branch information
Kamran Mackey committed Dec 18, 2020
1 parent 12d1b22 commit 6240625
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 34 deletions.
39 changes: 5 additions & 34 deletions Cargo.toml
Expand Up @@ -95,52 +95,23 @@ version = "0.2"
package = "http"

[features]
default = [
"builder",
"cache",
"client",
"framework",
"gateway",
"model",
"http",
"standard_framework",
"utils",
"rustls_backend",
]
default_native_tls = [
"builder",
"cache",
"client",
"framework",
"gateway",
"model",
"http",
"standard_framework",
"utils",
"native_tls_backend",
]
default = ["builder", "cache", "client", "framework", "gateway", "model", "http", "standard_framework", "utils", "rustls_backend"]
default_native_tls = ["builder", "cache", "client", "framework", "gateway", "model", "http", "standard_framework", "utils", "native_tls_backend"]
builder = ["utils"]
cache = []
collector = ["gateway", "model", "tokio/stream"]
client = [
"http",
"typemap_rev"
]
client = ["http", "typemap_rev"]
extras = []
framework = ["client", "model", "utils"]
gateway = [
"flate2",
"http",
"url",
"utils",
]
gateway = ["flate2", "http", "url", "utils"]
http = ["url", "bytes"]
absolute_ratelimits = ["http"]
rustls_backend = ["reqwest/rustls-tls", "async-tungstenite/tokio-rustls"]
native_tls_backend = ["reqwest/native-tls", "async-tungstenite/tokio-native-tls"]
model = ["builder", "http"]
voice-model = ["serenity-voice-model"]
standard_framework = ["framework", "uwl", "command_attr", "static_assertions"]
unstable = []
utils = ["base64"]
voice = ["client", "model"]

Expand Down
56 changes: 56 additions & 0 deletions src/model/gateway.rs
Expand Up @@ -54,6 +54,17 @@ pub struct Activity {
pub emoji: Option<ActivityEmoji>,
/// Unix timestamps for the start and/or end times of the activity.
pub timestamps: Option<ActivityTimestamps>,
/// The sync ID of the activity. Mainly used by the Spotify activity
/// type which uses this parameter to store the track ID.
#[cfg(feature = "unstable")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
pub sync_id: Option<String>,
/// The session ID of the activity. Reserved for specific activity
/// types, such as the Activity that is transmitted when a user is
/// listening to Spotify.
#[cfg(feature = "unstable")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
pub session_id: Option<String>,
/// The Stream URL if [`kind`] is [`ActivityType::Streaming`].
///
/// [`kind`]: Self::kind
Expand Down Expand Up @@ -101,6 +112,10 @@ impl Activity {
state: None,
emoji: None,
timestamps: None,
#[cfg(feature = "unstable")]
sync_id: None,
#[cfg(feature = "unstable")]
session_id: None,
url: None,
}
}
Expand Down Expand Up @@ -147,6 +162,10 @@ impl Activity {
state: None,
emoji: None,
timestamps: None,
#[cfg(feature = "unstable")]
sync_id: None,
#[cfg(feature = "unstable")]
session_id: None,
url: Some(url.to_string()),
}
}
Expand Down Expand Up @@ -190,6 +209,10 @@ impl Activity {
state: None,
emoji: None,
timestamps: None,
#[cfg(feature = "unstable")]
sync_id: None,
#[cfg(feature = "unstable")]
session_id: None,
url: None,
}
}
Expand Down Expand Up @@ -233,6 +256,10 @@ impl Activity {
state: None,
emoji: None,
timestamps: None,
#[cfg(feature = "unstable")]
sync_id: None,
#[cfg(feature = "unstable")]
session_id: None,
url: None,
}
}
Expand All @@ -241,54 +268,79 @@ impl Activity {
impl<'de> Deserialize<'de> for Activity {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
let mut map = JsonMap::deserialize(deserializer)?;

let application_id = match map.remove("application_id") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

let assets = match map.remove("assets") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

let details = match map.remove("details") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

let flags = match map.remove("flags") {
Some(v) => serde_json::from_value::<Option<u64>>(v)
.map_err(DeError::custom)?
.map(ActivityFlags::from_bits_truncate),
None => None,
};

let instance = match map.remove("instance") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

let kind = map.remove("type")
.and_then(|v| ActivityType::deserialize(v).ok())
.unwrap_or(ActivityType::Playing);

let name = map.remove("name")
.and_then(|v| String::deserialize(v).ok())
.unwrap_or_else(String::new);

let party = match map.remove("party") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

let secrets = match map.remove("secrets") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

let state = match map.remove("state") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

let emoji = match map.remove("emoji") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

let timestamps = match map.remove("timestamps") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

#[cfg(feature = "unstable")]
let sync_id = match map.remove("sync_id") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

#[cfg(feature = "unstable")]
let session_id = match map.remove("session_id") {
Some(v) => serde_json::from_value::<Option<_>>(v).map_err(DeError::custom)?,
None => None,
};

let url = map.remove("url")
.and_then(|v| serde_json::from_value::<String>(v).ok());

Expand All @@ -305,6 +357,10 @@ impl<'de> Deserialize<'de> for Activity {
state,
emoji,
timestamps,
#[cfg(feature = "unstable")]
sync_id,
#[cfg(feature = "unstable")]
session_id,
url,
})
}
Expand Down

0 comments on commit 6240625

Please sign in to comment.