Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon committed Nov 16, 2023
1 parent 8d77ae1 commit ec44a50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
22 changes: 10 additions & 12 deletions presage-store-sled/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,17 +997,15 @@ impl IdentityKeyStore for SledStore {
e.into_signal_error()
})?;

if let Ok(uuid) = address.name().parse() {
self.save_trusted_identity_message(
uuid,
*identity_key,
if existed_before {
verified::State::Unverified
} else {
verified::State::Default
},
);
};
self.save_trusted_identity_message(
address,
*identity_key,
if existed_before {
verified::State::Unverified
} else {
verified::State::Default
},
);

Ok(true)
}
Expand Down Expand Up @@ -1310,7 +1308,7 @@ mod tests {

#[quickcheck_async::tokio]
async fn test_store_messages(thread: Thread, content: Content) -> anyhow::Result<()> {
let mut db = SledStore::temporary()?;
let db = SledStore::temporary()?;
let thread = thread.0;
db.save_message(&thread, content_with_timestamp(&content, 1678295210))?;
db.save_message(&thread, content_with_timestamp(&content, 1678295220))?;
Expand Down
18 changes: 12 additions & 6 deletions presage/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use libsignal_service::{
sync_message::{self, Sent},
verified, DataMessage, EditMessage, GroupContextV2, SyncMessage, Verified,
},
protocol::{IdentityKey, ProtocolStore, SenderKeyStore},
protocol::{IdentityKey, ProtocolAddress, ProtocolStore, SenderKeyStore},
session_store::SessionStoreExt,
zkgroup::GroupMasterKeyBytes,
Profile,
Expand Down Expand Up @@ -93,19 +93,24 @@ pub trait ContentsStore {
message: Content,
) -> Result<(), Self::ContentsStoreError>;

/// Saves a message to mark an identity as trusted or not
/// Saves a message that can show users when the identity of a contact has changed
/// On Signal Android, this is usually displayed as: "Your safety number with XYZ has changed."
fn save_trusted_identity_message(
&self,
contact: Uuid,
protocol_address: &ProtocolAddress,
right_identity_key: IdentityKey,
verified_state: verified::State,
) {
let Ok(sender) = protocol_address.name().parse() else {
return;
};

// TODO: this is a hack to save a message showing that the verification status changed
// It is possibly ok to do it like this, but rebuidling the metadata and content body feels dirty
let thread = Thread::Contact(contact);
let thread = Thread::Contact(sender);
let verified_sync_message = Content {
metadata: Metadata {
sender: contact.into(),
sender: sender.into(),
sender_device: 0,
timestamp: SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
Expand All @@ -116,7 +121,7 @@ pub trait ContentsStore {
},
body: SyncMessage {
verified: Some(Verified {
destination_aci: Some(contact.to_string()),
destination_aci: None,
identity_key: Some(right_identity_key.public_key().serialize().to_vec()),
state: Some(verified_state.into()),
null_message: None,
Expand All @@ -125,6 +130,7 @@ pub trait ContentsStore {
}
.into(),
};

if let Err(error) = self.save_message(&thread, verified_sync_message) {
error!("failed to save the verified session message in thread: {error}");
}
Expand Down

0 comments on commit ec44a50

Please sign in to comment.