Skip to content

Commit

Permalink
Enforce selecting a mode when receiving messages (whisperfish#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon authored Nov 20, 2023
1 parent 676cf3a commit 23c157b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion presage-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -449,7 +450,7 @@ async fn receive<S: Store>(
);

let messages = manager
.receive_messages()
.receive_messages(ReceivingMode::Forever)
.await
.context("failed to initialize messages stream")?;
pin_mut!(messages);
Expand Down
12 changes: 5 additions & 7 deletions presage/src/manager/registered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl<S: Store> Manager<S, Registered> {
debug!("synchronizing contacts");

let mut messages = pin!(
self.receive_messages_with_mode(ReceivingMode::WaitForContacts)
self.receive_messages(ReceivingMode::WaitForContacts)
.await?
);

Expand Down Expand Up @@ -470,15 +470,13 @@ impl<S: Store> Manager<S, Registered> {

/// 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<impl Stream<Item = Content>, Error<S::Error>> {
self.receive_messages_stream(ReceivingMode::Forever).await
}

pub async fn receive_messages_with_mode(
&mut self,
mode: ReceivingMode,
) -> Result<impl Stream<Item = Content>, Error<S::Error>> {
self.receive_messages_stream(mode).await
Expand Down

0 comments on commit 23c157b

Please sign in to comment.