Skip to content

Commit

Permalink
Merge pull request #325 from whisperfish/impl-display-serviceaddress
Browse files Browse the repository at this point in the history
impl Display for ServiceAddress
  • Loading branch information
rubdos authored Sep 28, 2024
2 parents f99ff83 + 24ca80f commit 9c77576
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions libsignal-service/src/account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ impl<Service: PushService> AccountManager<Service> {
/// Should be called as the primary device to migrate from pre-PNI to PNI.
///
/// This is the equivalent of Android's PnpInitializeDevicesJob or iOS' PniHelloWorldManager.
#[tracing::instrument(skip(self, aci_protocol_store, pni_protocol_store, sender, local_aci, csprng), fields(local_aci = %local_aci))]
pub async fn pnp_initialize_devices<
// XXX So many constraints here, all imposed by the MessageSender
R: rand::Rng + rand::CryptoRng,
Expand Down
24 changes: 12 additions & 12 deletions libsignal-service/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ where

/// Send a message `content` to a single `recipient`.
#[tracing::instrument(
skip(self, unidentified_access, message),
fields(unidentified_access = unidentified_access.is_some()),
skip(self, unidentified_access, message, recipient),
fields(unidentified_access = unidentified_access.is_some(), recipient = %recipient),
)]
pub async fn send_message(
&mut self,
Expand Down Expand Up @@ -496,8 +496,8 @@ where
/// Send a message (`content`) to an address (`recipient`).
#[tracing::instrument(
level = "trace",
skip(self, unidentified_access, content_body),
fields(unidentified_access = unidentified_access.is_some()),
skip(self, unidentified_access, content_body, recipient),
fields(unidentified_access = unidentified_access.is_some(), recipient = %recipient),
)]
async fn try_send_message(
&mut self,
Expand Down Expand Up @@ -646,8 +646,8 @@ where

/// Upload contact details to the CDN and send a sync message
#[tracing::instrument(
skip(self, unidentified_access, contacts),
fields(unidentified_access = unidentified_access.is_some()),
skip(self, unidentified_access, contacts, recipient),
fields(unidentified_access = unidentified_access.is_some(), recipient = %recipient),
)]
pub async fn send_contact_details<Contacts>(
&mut self,
Expand Down Expand Up @@ -687,7 +687,7 @@ where
}

/// Send `Configuration` synchronization message
#[tracing::instrument(skip(self))]
#[tracing::instrument(skip(self, recipient), fields(recipient = %recipient))]
pub async fn send_configuration(
&mut self,
recipient: &ServiceAddress,
Expand All @@ -706,7 +706,7 @@ where
}

/// Send `MessageRequestResponse` synchronization message with either a recipient ACI or a GroupV2 ID
#[tracing::instrument(skip(self))]
#[tracing::instrument(skip(self, recipient), fields(recipient = %recipient))]
pub async fn send_message_request_response(
&mut self,
recipient: &ServiceAddress,
Expand Down Expand Up @@ -772,8 +772,8 @@ where
// Equivalent with `getEncryptedMessages`
#[tracing::instrument(
level = "trace",
skip(self, unidentified_access, content),
fields(unidentified_access = unidentified_access.is_some()),
skip(self, unidentified_access, content, recipient),
fields(unidentified_access = unidentified_access.is_some(), recipient = %recipient),
)]
async fn create_encrypted_messages(
&mut self,
Expand Down Expand Up @@ -882,8 +882,8 @@ where
/// When no session with the recipient exists, we need to create one.
#[tracing::instrument(
level = "trace",
skip(self, unidentified_access, content),
fields(unidentified_access = unidentified_access.is_some()),
skip(self, unidentified_access, content, recipient),
fields(unidentified_access = unidentified_access.is_some(), recipient = %recipient),
)]
pub(crate) async fn create_encrypted_message(
&mut self,
Expand Down
19 changes: 13 additions & 6 deletions libsignal-service/src/service_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ pub struct ServiceAddress {
pub identity: ServiceIdType,
}

impl std::fmt::Display for ServiceAddress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// This is used in ServiceAddress::to_service_id(&self), so keep this consistent.
match self.identity {
ServiceIdType::AccountIdentity => write!(f, "{}", self.uuid),
ServiceIdType::PhoneNumberIdentity => {
write!(f, "PNI:{}", self.uuid)
},
}
}
}

impl ServiceAddress {
pub fn to_protocol_address(
&self,
Expand Down Expand Up @@ -71,12 +83,7 @@ impl ServiceAddress {
}

pub fn to_service_id(&self) -> String {
match self.identity {
ServiceIdType::AccountIdentity => self.uuid.to_string(),
ServiceIdType::PhoneNumberIdentity => {
format!("PNI:{}", self.uuid)
},
}
self.to_string()
}
}

Expand Down

0 comments on commit 9c77576

Please sign in to comment.