Skip to content

Commit

Permalink
Fix some issues, description incoming
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon committed Nov 18, 2023
1 parent 46f6226 commit 84d10e5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ resolver = "2"
[patch.crates-io]
curve25519-dalek = { git = 'https://github.com/signalapp/curve25519-dalek', tag = 'signal-curve25519-4.0.0' }

# [patch."https://github.com/whisperfish/libsignal-service-rs.git"]
# libsignal-service = { path = "../libsignal-service-rs/libsignal-service" }
# libsignal-service-hyper = { path = "../libsignal-service-rs/libsignal-service-hyper" }
[patch."https://github.com/whisperfish/libsignal-service-rs.git"]
libsignal-service = { path = "../libsignal-service-rs/libsignal-service" }
libsignal-service-hyper = { path = "../libsignal-service-rs/libsignal-service-hyper" }
6 changes: 0 additions & 6 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 @@ -236,14 +234,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
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 = "3949d27" }
libsignal-service-hyper = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "3949d27" }

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 84d10e5

Please sign in to comment.