Skip to content

Commit

Permalink
Merge branch 'main' into threadmetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nanu-c authored Nov 18, 2023
2 parents 1a1b9c8 + 96ccb73 commit 03d5558
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
3 changes: 0 additions & 3 deletions presage-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,3 @@ tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "io-std", "i
qr2term = { version = "0.2.2" }
notify-rust = "4.6.0"
url = "2.2"

[features]
quirks = []
12 changes: 3 additions & 9 deletions presage-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use core::fmt;
use std::convert::TryInto;
use std::path::Path;
use std::path::PathBuf;
use std::time::Duration;
use std::time::UNIX_EPOCH;

use anyhow::{anyhow, bail, Context as _};
Expand Down Expand Up @@ -37,7 +36,6 @@ use presage_store_sled::OnNewIdentity;
use presage_store_sled::SledStore;
use tempfile::Builder;
use tokio::task;
use tokio::time::sleep;
use tokio::{
fs,
io::{self, AsyncBufReadExt, BufReader},
Expand Down Expand Up @@ -149,7 +147,9 @@ enum Cmd {
from: Option<u64>,
},
#[clap(about = "Get a single contact by UUID")]
GetContact { uuid: Uuid },
GetContact {
uuid: Uuid,
},
#[clap(about = "Find a contact in the embedded DB")]
FindContact {
#[clap(long, short = 'u', help = "contact UUID")]
Expand All @@ -173,7 +173,6 @@ enum Cmd {
#[clap(long, short = 'k', help = "Master Key of the V2 group (hex string)", value_parser = parse_group_master_key)]
master_key: GroupMasterKeyBytes,
},
#[cfg(feature = "quirks")]
RequestSyncContacts,
}

Expand Down Expand Up @@ -236,14 +235,10 @@ async fn send<S: Store + 'static>(
}
});

sleep(Duration::from_secs(5)).await;

manager
.send_message(*uuid, message, timestamp)
.await
.unwrap();

sleep(Duration::from_secs(5)).await;
})
.await;

Expand Down Expand Up @@ -661,7 +656,6 @@ async fn run<S: Store + 'static>(subcommand: Cmd, config_store: S) -> anyhow::Re
println!("{contact:#?}");
}
}
#[cfg(feature = "quirks")]
Cmd::RequestSyncContacts => {
let mut manager = Manager::load_registered(config_store).await?;
manager.request_contacts_sync().await?;
Expand Down
4 changes: 2 additions & 2 deletions presage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = ["Gabriel Féron <[email protected]>"]
edition = "2021"

[dependencies]
libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "f40eb4f" }
libsignal-service-hyper = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "f40eb4f" }
libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "afb5114" }
libsignal-service-hyper = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "afb5114" }

base64 = "0.21"
futures = "0.3"
Expand Down
31 changes: 17 additions & 14 deletions presage/src/manager/registered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,14 @@ impl<S: Store> Manager<S, Registered> {
certificate: sender_certificate.clone(),
});

// we need to put our profile key in DataMessage
if let ContentBody::DataMessage(message) = &mut content_body {
message
.profile_key
.get_or_insert(self.state.data.profile_key().get_bytes().to_vec());
message.required_protocol_version = Some(0);
}

sender
.send_message(
&recipient,
Expand Down Expand Up @@ -976,20 +984,6 @@ fn save_message<S: Store>(store: &mut S, message: Content) -> Result<(), Error<S
// derive the thread from the message type
let thread = Thread::try_from(&message)?;

// update recipient profile keys
if let ContentBody::DataMessage(DataMessage {
profile_key: Some(profile_key_bytes),
..
}) = &message.body
{
if let Ok(profile_key_bytes) = profile_key_bytes.clone().try_into() {
let sender_uuid = message.metadata.sender.uuid;
let profile_key = ProfileKey::create(profile_key_bytes);
debug!("inserting profile key for {sender_uuid}");
store.upsert_profile_key(&sender_uuid, profile_key)?;
}
}

// only save DataMessage and SynchronizeMessage (sent)
let message = match message.body {
ContentBody::NullMessage(_) => Some(message),
Expand All @@ -1003,12 +997,21 @@ fn save_message<S: Store>(store: &mut S, message: Content) -> Result<(), Error<S
..
}) => match data_message {
DataMessage {
profile_key: Some(profile_key_bytes),
delete:
Some(Delete {
target_sent_timestamp: Some(ts),
}),
..
} => {
// update recipient profile key
if let Ok(profile_key_bytes) = profile_key_bytes.clone().try_into() {
let sender_uuid = message.metadata.sender.uuid;
let profile_key = ProfileKey::create(profile_key_bytes);
debug!("inserting profile key for {sender_uuid}");
store.upsert_profile_key(&sender_uuid, profile_key)?;
}

// replace an existing message by an empty NullMessage
if let Some(mut existing_msg) = store.message(&thread, *ts)? {
existing_msg.metadata.sender.uuid = Uuid::nil();
Expand Down

0 comments on commit 03d5558

Please sign in to comment.