diff --git a/autopush_rs/src/client.rs b/autopush_rs/src/client.rs index a5dbd0f1..5df35a57 100644 --- a/autopush_rs/src/client.rs +++ b/autopush_rs/src/client.rs @@ -801,10 +801,10 @@ where // Topic/legacy messages have no sortkey_timestamp if n.sortkey_timestamp.is_none() { fut = if let Some(call) = fut { - let my_fut = data.srv.ddb.delete_message(&message_month, &n); + let my_fut = data.srv.ddb.delete_message(&message_month, &webpush.uaid, &n); Some(Box::new(call.and_then(move |_| my_fut))) } else { - Some(data.srv.ddb.delete_message(&message_month, &n)) + Some(data.srv.ddb.delete_message(&message_month, &webpush.uaid, &n)) } } continue; diff --git a/autopush_rs/src/db/commands.rs b/autopush_rs/src/db/commands.rs index 63603662..0a08c3d7 100644 --- a/autopush_rs/src/db/commands.rs +++ b/autopush_rs/src/db/commands.rs @@ -14,12 +14,12 @@ use rusoto_dynamodb::{ }; use serde_dynamodb; -use errors::*; -use protocol::Notification; -use util::timing::sec_since_epoch; use super::models::{DynamoDbNotification, DynamoDbUser}; use super::util::generate_last_connect; use super::{HelloResponse, MAX_EXPIRY, USER_RECORD_VERSION}; +use errors::*; +use protocol::Notification; +use util::timing::sec_since_epoch; #[derive(Default)] pub struct FetchMessageResponse { @@ -29,11 +29,10 @@ pub struct FetchMessageResponse { /// Indicate whether this last_connect falls in the current month fn has_connected_this_month(user: &DynamoDbUser) -> bool { - user.last_connect - .map_or(false, |v| { - let pat = Utc::now().format("%Y%m").to_string(); - v.to_string().starts_with(&pat) - }) + user.last_connect.map_or(false, |v| { + let pat = Utc::now().format("%Y%m").to_string(); + v.to_string().starts_with(&pat) + }) } pub fn fetch_messages( diff --git a/autopush_rs/src/db/mod.rs b/autopush_rs/src/db/mod.rs index 36bcd9a2..80a9f2a5 100644 --- a/autopush_rs/src/db/mod.rs +++ b/autopush_rs/src/db/mod.rs @@ -277,17 +277,13 @@ impl DynamoStorage { let ddb = self.ddb.clone(); let put_items: Vec = messages .into_iter() - .filter_map(|mut n| { - n.uaid = Some(uaid.simple().to_string()); - let hm = DynamoDbNotification::from_notif(n) - .map(|notif| serde_dynamodb::to_hashmap(¬if).ok()) - .unwrap_or_default(); - hm.map(|hm| { - WriteRequest { + .filter_map(|n| { + serde_dynamodb::to_hashmap(&DynamoDbNotification::from_notif(uaid, n)) + .ok() + .map(|hm| WriteRequest { put_request: Some(PutRequest { item: hm }), delete_request: None, - } - }) + }) }) .collect(); let batch_input = BatchWriteItemInput { @@ -314,21 +310,19 @@ impl DynamoStorage { /// /// No checks are done to see that this message came from the database or has /// sufficient properties for a delete as that is expected to have been done - /// before this is called. In the event information is missing, a future::ok - /// is returned. - pub fn delete_message(&self, table_name: &str, notif: &Notification) -> MyFuture<()> { + /// before this is called. + pub fn delete_message( + &self, + table_name: &str, + uaid: &Uuid, + notif: &Notification, + ) -> MyFuture<()> { let ddb = self.ddb.clone(); - let uaid = if let Some(ref uaid) = notif.uaid { - uaid.clone() - } else { - return Box::new(future::ok(())); - }; - let chidmessageid = notif.sort_key(); let delete_input = DeleteItemInput { table_name: table_name.to_string(), key: ddb_item! { - uaid: s => uaid, - chidmessageid: s => chidmessageid + uaid: s => uaid.simple().to_string(), + chidmessageid: s => notif.sort_key() }, ..Default::default() }; diff --git a/autopush_rs/src/db/models.rs b/autopush_rs/src/db/models.rs index 60aaa9d4..8ee1a65c 100644 --- a/autopush_rs/src/db/models.rs +++ b/autopush_rs/src/db/models.rs @@ -199,12 +199,12 @@ impl DynamoDbNotification { // TODO: Implement as TryFrom whenever that lands pub fn into_notif(self) -> Result { let key = Self::parse_sort_key(&self.chidmessageid)?; - let version = key.legacy_version + let version = key + .legacy_version .or(self.updateid) .ok_or("No valid updateid/version found")?; Ok(Notification { - uaid: Some(self.uaid.simple().to_string()), channel_id: key.channel_id, version, ttl: self.ttl.ok_or("No TTL found")?, @@ -216,14 +216,10 @@ impl DynamoDbNotification { }) } - // TODO: Implement as TryFrom when that lands in case uaid wasn't set - pub fn from_notif(val: Notification) -> Result { - let sort_key = val.sort_key(); - let uaid = val.uaid.ok_or("No uaid found")?; - let uaid = Uuid::parse_str(&uaid)?; - Ok(Self { - uaid, - chidmessageid: sort_key, + pub fn from_notif(uaid: &Uuid, val: Notification) -> Self { + Self { + uaid: *uaid, + chidmessageid: val.sort_key(), timestamp: Some(val.timestamp), expiry: sec_since_epoch() as u32 + min(val.ttl, MAX_EXPIRY as u32), ttl: Some(val.ttl), @@ -231,7 +227,7 @@ impl DynamoDbNotification { headers: val.headers.map(|h| h.into()), updateid: Some(val.version), ..Default::default() - }) + } } } diff --git a/autopush_rs/src/protocol.rs b/autopush_rs/src/protocol.rs index 3e571264..e318c6ae 100644 --- a/autopush_rs/src/protocol.rs +++ b/autopush_rs/src/protocol.rs @@ -105,8 +105,6 @@ pub enum ServerMessage { #[derive(Serialize, Default, Deserialize, Clone, Debug)] pub struct Notification { - #[serde(skip_serializing)] - pub uaid: Option, #[serde(rename = "channelID")] pub channel_id: Uuid, pub version: String,