diff --git a/presage/src/manager/registered.rs b/presage/src/manager/registered.rs index 3a0a5f9d7..e3d7a54d4 100644 --- a/presage/src/manager/registered.rs +++ b/presage/src/manager/registered.rs @@ -604,6 +604,7 @@ impl Manager { &mut state.store, &mut state.push_service, content.clone(), + None, ) .await { @@ -708,7 +709,13 @@ impl Manager { }; let mut push_service = self.identified_push_service(); - save_message(&mut self.store, &mut push_service, content).await?; + save_message( + &mut self.store, + &mut push_service, + content, + Some(Thread::Contact(recipient.uuid)), + ) + .await?; Ok(()) } @@ -740,6 +747,9 @@ impl Manager { timestamp: u64, ) -> Result<(), Error> { let mut content_body = message.into(); + let master_key_bytes = master_key_bytes + .try_into() + .expect("Master key bytes to be of size 32."); // Only update the expiration timer if it is not set. match content_body { @@ -750,11 +760,7 @@ impl Manager { // Set the expire timer to None for errors. let store_expire_timer = self .store - .expire_timer(&Thread::Group( - master_key_bytes - .try_into() - .expect("Master key bytes to be of size 32."), - )) + .expire_timer(&Thread::Group(master_key_bytes)) .unwrap_or_default(); *timer = store_expire_timer; @@ -765,7 +771,7 @@ impl Manager { let mut groups_manager = self.groups_manager()?; let Some(group) = - upsert_group(&self.store, &mut groups_manager, master_key_bytes, &0).await? + upsert_group(&self.store, &mut groups_manager, &master_key_bytes, &0).await? else { return Err(Error::UnknownGroup); }; @@ -807,7 +813,13 @@ impl Manager { }; let mut push_service = self.identified_push_service(); - save_message(&mut self.store, &mut push_service, content).await?; + save_message( + &mut self.store, + &mut push_service, + content, + Some(Thread::Group(master_key_bytes)), + ) + .await?; Ok(()) } @@ -1015,13 +1027,17 @@ async fn upsert_group( Ok(store.group(master_key_bytes.try_into()?)?) } +/// Save a message into the store. +/// Note that `override_thread` can be used to specify the thread the message will be stored in. +/// This is required when storing outgoing messages, as in this case the appropriate storage place cannot be derived from the message itself. async fn save_message( store: &mut S, push_service: &mut HyperPushService, message: Content, + override_thread: Option, ) -> Result<(), Error> { // derive the thread from the message type - let thread = Thread::try_from(&message)?; + let thread = override_thread.unwrap_or(Thread::try_from(&message)?); // only save DataMessage and SynchronizeMessage (sent) let message = match message.body { diff --git a/presage/src/store.rs b/presage/src/store.rs index 335d87d1e..cee012d1d 100644 --- a/presage/src/store.rs +++ b/presage/src/store.rs @@ -115,7 +115,7 @@ pub trait ContentsStore { timestamp: SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap_or_default() - .as_secs(), + .as_millis() as u64, needs_receipt: false, unidentified_sender: false, },