From 67c1dfbd8a340738bbbb0b74d1131a800af28d4e Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Mon, 30 Sep 2024 01:20:01 +0300 Subject: [PATCH] Add sending sync message requests --- libsignal-service/src/sender.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/libsignal-service/src/sender.rs b/libsignal-service/src/sender.rs index 86315742a..7cb271cf6 100644 --- a/libsignal-service/src/sender.rs +++ b/libsignal-service/src/sender.rs @@ -771,6 +771,37 @@ where Ok(()) } + /// Send a `Keys` request message + #[tracing::instrument(skip(self))] + pub async fn send_sync_message_request( + &mut self, + recipient: &ServiceAddress, + request_type: sync_message::request::Type, + ) -> Result<(), MessageSenderError> { + if self.device_id == DEFAULT_DEVICE_ID.into() { + let reason = format!( + "Primary device can't send sync requests, ignoring {:?}", + request_type + ); + return Err(MessageSenderError::ServiceError( + ServiceError::SendError { reason }, + )); + } + + let msg = SyncMessage { + request: Some(sync_message::Request { + r#type: Some(request_type.into()), + }), + ..SyncMessage::with_padding() + }; + + let ts = Utc::now().timestamp_millis() as u64; + self.send_message(recipient, None, msg, ts, false, true) + .await?; + + Ok(()) + } + #[tracing::instrument(level = "trace", skip(self))] fn create_pni_signature( &mut self,