diff --git a/README.md b/README.md index f9a08de6f..4819bfe4e 100644 --- a/README.md +++ b/README.md @@ -8,22 +8,17 @@ A Rust library that helps building clients for the [Signal Messenger](https://si Features: -- [x] Local storage (using [sled](https://github.com/spacejam/sled)) - - [x] Registration/linking - - [x] Contacts - - [x] Groups - - [x] Messages - - [x] Local encryption (using [matrix-sdk-store-encryption](https://crates.io/crates/matrix-sdk-store-encryption)) +- [x] Local storage with encryption: + - [x] with [sled](https://github.com/spacejam/sled) + - [ ] with [sqlx](https://crates.io/sqlx) and `sqlite` (see #287) - [x] Registration - [x] SMS - [x] Voice call - [x] Link as secondary device from Android / iOS app (like Signal Desktop) -- [x] Synchronize contacts from primary device -- [x] Receive messages -- [x] Handle groups v2 (and change events) -- [x] Download + decrypt attachments -- [x] Send messages -- [x] Groups support +- [x] Contacts (synchronized from primary device) and profiles +- [x] Groups +- [x] Messages (incoming and outgoing) +- [x] Fetch, decrypt and store attachments ## Instructions @@ -37,14 +32,14 @@ presage-store-sled = { git = "https://github.com/whisperfish/presage" } # For a discussion as to why, see: # https://github.com/whisperfish/libsignal-service-rs/tree/93c23cf27d27a17a803e34ea3dd6a82d268fa79e#working-around-the-issue-with-curve25519-dalek [patch.crates-io] -curve25519-dalek = { git = 'https://github.com/signalapp/curve25519-dalek', tag = 'signal-curve25519-4.1.1' } +curve25519-dalek = { git = 'https://github.com/signalapp/curve25519-dalek', tag = 'signal-curve25519-4.1.3' } ``` and look at the generated Rust documentation of the `Manager` struct to get started. ## Demo CLI -Included in this repository is a CLI very similar (on purpose) to the great [signal-cli](https://github.com/AsamK/signal-cli): +Included in this repository is a nearly fully functional CLI that can serve as an example to build your client (you can also use it to query your `presage` database): ``` # print help section @@ -56,5 +51,3 @@ cargo run -- link-device --device-name presage # start receiving messages cargo run -- receive ``` - -For using the library, the CLI is a good starting point to learn how the API can be used. diff --git a/presage-cli/Cargo.toml b/presage-cli/Cargo.toml index 1fe3536b6..738d810ac 100644 --- a/presage-cli/Cargo.toml +++ b/presage-cli/Cargo.toml @@ -25,4 +25,3 @@ tokio = { version = "1.35", features = ["macros", "rt-multi-thread", "io-std", " tracing = "0.1" tracing-subscriber = { version = "0.3", default-features = false } url = "2.5" -rand = "0.8.5" diff --git a/presage-cli/src/main.rs b/presage-cli/src/main.rs index 31d8e9ea4..37558422e 100644 --- a/presage-cli/src/main.rs +++ b/presage-cli/src/main.rs @@ -30,7 +30,6 @@ use presage::model::groups::Group; use presage::model::identity::OnNewIdentity; use presage::model::messages::Received; use presage::proto::receipt_message; -use presage::proto::sync_message; use presage::proto::EditMessage; use presage::proto::ReceiptMessage; use presage::proto::SyncMessage; @@ -43,7 +42,6 @@ use presage::{ }; use presage_store_sled::MigrationConflictStrategy; use presage_store_sled::SledStore; -use rand::thread_rng; use tempfile::Builder; use tempfile::TempDir; use tokio::{ diff --git a/presage/Cargo.toml b/presage/Cargo.toml index 4d203f0d2..cfbdecd1b 100644 --- a/presage/Cargo.toml +++ b/presage/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" license = "AGPL-3.0-only" [dependencies] -libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "6401dc34872a5f0c2fba32c1f136d98ccf3dd418" } +libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "268e0c47e0924597b6379e6f1b5df58abd46d5ca" } base64 = "0.22" futures = "0.3" diff --git a/presage/src/manager/registered.rs b/presage/src/manager/registered.rs index 83b55634f..1647db233 100644 --- a/presage/src/manager/registered.rs +++ b/presage/src/manager/registered.rs @@ -833,9 +833,10 @@ impl Manager { .profile_key .get_or_insert(self.state.data.profile_key().get_bytes().to_vec()); message.required_protocol_version = Some(0); - message.timestamp = Some(timestamp); } + ensure_data_message_timestamp(&mut content_body, timestamp); + sender .send_message( &recipient, @@ -900,6 +901,7 @@ impl Manager { let thread = Thread::Group(master_key_bytes); self.restore_thread_timer(&thread, &mut content_body).await; + ensure_data_message_timestamp(&mut content_body, timestamp); let mut sender = self.new_message_sender().await?; @@ -990,7 +992,7 @@ impl Manager { } } - /// Clears all sessions established wiht [recipient](ServiceId). + /// Clears all sessions established with [recipient](ServiceId). pub async fn clear_sessions(&self, recipient: &ServiceId) -> Result<(), Error> { use libsignal_service::session_store::SessionStoreExt; self.store @@ -1268,6 +1270,32 @@ impl Manager { } } +/// Set the timestamp in any DataMessage so it matches its envelope's +fn ensure_data_message_timestamp(content_body: &mut ContentBody, timestamp: u64) { + match content_body { + ContentBody::DataMessage(message) => { + message.timestamp = Some(timestamp); + } + ContentBody::EditMessage(EditMessage { + data_message: Some(data_message), + .. + }) => { + data_message.timestamp = Some(timestamp); + } + ContentBody::SynchronizeMessage(SyncMessage { + sent: + Some(sync_message::Sent { + message: Some(data_message), + .. + }), + .. + }) => { + data_message.timestamp = Some(timestamp); + } + _ => (), + } +} + async fn upsert_group( store: &S, groups_manager: &mut GroupsManager,