Skip to content

Commit

Permalink
Merge pull request #318 from whisperfish/send_message_request_response
Browse files Browse the repository at this point in the history
Add sending message request response messages
  • Loading branch information
direc85 committed Aug 24, 2024
2 parents f21e317 + 07c1850 commit 3b8656a
Showing 1 changed file with 63 additions and 2 deletions.
65 changes: 63 additions & 2 deletions libsignal-service/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ use libsignal_protocol::{
use rand::{CryptoRng, Rng};
use tracing::{error, info, trace};
use tracing_futures::Instrument;
use uuid::Uuid;
use zkgroup::GROUP_IDENTIFIER_LEN;

use crate::{
cipher::{get_preferred_protocol_address, ServiceCipher},
content::ContentBody,
proto::{
attachment_pointer::AttachmentIdentifier,
attachment_pointer::Flags as AttachmentPointerFlags, sync_message,
attachment_pointer::{
AttachmentIdentifier, Flags as AttachmentPointerFlags,
},
sync_message::{
self, message_request_response, MessageRequestResponse,
},
AttachmentPointer, SyncMessage,
},
push_service::*,
Expand Down Expand Up @@ -123,6 +129,14 @@ pub enum MessageSenderError {
NotFound { addr: ServiceAddress },
}

pub type GroupV2Id = [u8; GROUP_IDENTIFIER_LEN];

#[derive(Debug)]
pub enum ThreadIdentifier {
Aci(Uuid),
Group(GroupV2Id),
}

impl<Service, S, R> MessageSender<Service, S, R>
where
Service: PushService,
Expand Down Expand Up @@ -691,6 +705,53 @@ where
Ok(())
}

/// Send `MessageRequestResponse` synchronization message with either a recipient ACI or a GroupV2 ID
#[tracing::instrument(skip(self))]
pub async fn send_message_request_response(
&mut self,
recipient: &ServiceAddress,
thread: &ThreadIdentifier,
action: message_request_response::Type,
) -> Result<(), MessageSenderError> {
let message_request_response = Some(match thread {
ThreadIdentifier::Aci(aci) => {
tracing::debug!(
"sending message request response {:?} for recipient {:?}",
action,
aci
);
MessageRequestResponse {
thread_aci: Some(aci.to_string()),
group_id: None,
r#type: Some(action.into()),
}
},
ThreadIdentifier::Group(id) => {
tracing::debug!(
"sending message request response {:?} for group {:?}",
action,
id
);
MessageRequestResponse {
thread_aci: None,
group_id: Some(id.to_vec()),
r#type: Some(action.into()),
}
},
});

let msg = SyncMessage {
message_request_response,
..SyncMessage::with_padding()
};

let ts = Utc::now().timestamp_millis() as u64;
self.send_message(recipient, None, msg, ts, false, false)
.await?;

Ok(())
}

#[tracing::instrument(level = "trace", skip(self))]
fn create_pni_signature(
&mut self,
Expand Down

0 comments on commit 3b8656a

Please sign in to comment.