From 23c157b0ad1e369b3e0318c22b1a45b2a0eefacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20F=C3=A9ron?= Date: Mon, 20 Nov 2023 10:41:07 +0100 Subject: [PATCH] Enforce selecting a mode when receiving messages (#212) --- presage-cli/src/main.rs | 3 ++- presage/src/manager/registered.rs | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/presage-cli/src/main.rs b/presage-cli/src/main.rs index ff9887a8f..8b3565f29 100644 --- a/presage-cli/src/main.rs +++ b/presage-cli/src/main.rs @@ -22,6 +22,7 @@ use presage::libsignal_service::proto::data_message::Quote; use presage::libsignal_service::proto::sync_message::Sent; use presage::libsignal_service::zkgroup::GroupMasterKeyBytes; use presage::libsignal_service::{groups_v2::Group, prelude::ProfileKey}; +use presage::manager::ReceivingMode; use presage::proto::EditMessage; use presage::proto::SyncMessage; use presage::store::ContentExt; @@ -449,7 +450,7 @@ async fn receive( ); let messages = manager - .receive_messages() + .receive_messages(ReceivingMode::Forever) .await .context("failed to initialize messages stream")?; pin_mut!(messages); diff --git a/presage/src/manager/registered.rs b/presage/src/manager/registered.rs index 1af2c938b..3a0a5f9d7 100644 --- a/presage/src/manager/registered.rs +++ b/presage/src/manager/registered.rs @@ -331,7 +331,7 @@ impl Manager { debug!("synchronizing contacts"); let mut messages = pin!( - self.receive_messages_with_mode(ReceivingMode::WaitForContacts) + self.receive_messages(ReceivingMode::WaitForContacts) .await? ); @@ -470,15 +470,13 @@ impl Manager { /// Starts receiving and storing messages. /// + /// As a client, it is heavily recommended to run this once in `ReceivingMode::InitialSync` once + /// before enabling the possiblity of sending messages. That way, all possible updates (sessions, profile keys, sender keys) + /// are processed _before_ trying to encrypt and send messages which might fail otherwise. + /// /// Returns a [futures::Stream] of messages to consume. Messages will also be stored by the implementation of the [Store]. pub async fn receive_messages( &mut self, - ) -> Result, Error> { - self.receive_messages_stream(ReceivingMode::Forever).await - } - - pub async fn receive_messages_with_mode( - &mut self, mode: ReceivingMode, ) -> Result, Error> { self.receive_messages_stream(mode).await