Skip to content

Commit

Permalink
feat: mark saved messages chat as protected
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Nov 29, 2024
1 parent 170b7e2 commit 9ec1401
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2593,10 +2593,12 @@ impl ChatIdBlocked {
_ => (),
}

let peerstate = Peerstate::from_addr(context, contact.get_addr()).await?;
let protected = peerstate.map_or(false, |p| {
p.is_using_verified_key() && p.prefer_encrypt == EncryptPreference::Mutual
});
let protected = contact_id == ContactId::SELF || {
let peerstate = Peerstate::from_addr(context, contact.get_addr()).await?;
peerstate.is_some_and(|p| {
p.is_using_verified_key() && p.prefer_encrypt == EncryptPreference::Mutual
})
};
let smeared_time = create_smeared_timestamp(context);

let chat_id = context
Expand Down
16 changes: 16 additions & 0 deletions src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3244,4 +3244,20 @@ Until the false-positive is fixed:

Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_self_is_verified() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = tcm.alice().await;

let contact = Contact::get_by_id(&alice, ContactId::SELF).await?;
assert_eq!(contact.is_verified(&alice).await?, true);
assert!(contact.is_profile_verified(&alice).await?);
assert!(contact.get_verifier_id(&alice).await?.is_none());

let chat_id = ChatId::get_for_contact(&alice, ContactId::SELF).await?;
assert!(chat_id.is_protected(&alice).await.unwrap() == ProtectionStatus::Protected);

Ok(())
}
}

0 comments on commit 9ec1401

Please sign in to comment.