Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into expose-queue-empty
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon committed Jan 2, 2025
2 parents 26467a6 + 3017e6a commit 0c9f371
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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.
2 changes: 0 additions & 2 deletions presage-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion presage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 30 additions & 2 deletions presage/src/manager/registered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,10 @@ impl<S: Store> Manager<S, Registered> {
.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,
Expand Down Expand Up @@ -900,6 +901,7 @@ impl<S: Store> Manager<S, Registered> {
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?;

Expand Down Expand Up @@ -990,7 +992,7 @@ impl<S: Store> Manager<S, Registered> {
}
}

/// Clears all sessions established wiht [recipient](ServiceId).
/// Clears all sessions established with [recipient](ServiceId).
pub async fn clear_sessions(&self, recipient: &ServiceId) -> Result<(), Error<S::Error>> {
use libsignal_service::session_store::SessionStoreExt;
self.store
Expand Down Expand Up @@ -1268,6 +1270,32 @@ impl<S: Store> Manager<S, Registered> {
}
}

/// 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<S: Store>(
store: &S,
groups_manager: &mut GroupsManager<InMemoryCredentialsCache>,
Expand Down

0 comments on commit 0c9f371

Please sign in to comment.