@@ -33,7 +33,7 @@ use crate::contact::{import_vcard, make_vcard, Contact, ContactId, Modifier, Ori
33
33
use crate :: context:: Context ;
34
34
use crate :: e2ee:: EncryptHelper ;
35
35
use crate :: events:: { Event , EventEmitter , EventType , Events } ;
36
- use crate :: key:: { self , DcKey } ;
36
+ use crate :: key:: { self , load_self_public_key , DcKey } ;
37
37
use crate :: message:: { update_msg_state, Message , MessageState , MsgId , Viewtype } ;
38
38
use crate :: mimeparser:: { MimeMessage , SystemMessage } ;
39
39
use crate :: peerstate:: Peerstate ;
@@ -706,12 +706,38 @@ impl TestContext {
706
706
}
707
707
708
708
/// Returns the [`Contact`] for the other [`TestContext`], creating it if necessary.
709
+ ///
710
+ /// If the contact does not exist yet, a new contact will be created
711
+ /// with the correct fingerprint, but without the public key.
712
+ pub async fn add_or_lookup_pgp_contact ( & self , other : & TestContext ) -> Contact {
713
+ let primary_self_addr = other. ctx . get_primary_self_addr ( ) . await . unwrap ( ) ;
714
+ let addr = ContactAddress :: new ( & primary_self_addr) . unwrap ( ) ;
715
+ let public_key = load_self_public_key ( other) . await . unwrap ( ) ;
716
+ let fingerprint = public_key. dc_fingerprint ( ) ;
717
+
718
+ let ( contact_id, _modified) = Contact :: add_or_lookup_ex (
719
+ self ,
720
+ "" ,
721
+ & addr,
722
+ & fingerprint. hex ( ) ,
723
+ Origin :: MailinglistAddress ,
724
+ )
725
+ . await
726
+ . expect ( "add_or_lookup" ) ;
727
+ Contact :: get_by_id ( & self . ctx , contact_id) . await . unwrap ( )
728
+ }
729
+
730
+ /// Returns the [`Contact`] for the other [`TestContext`], creating it if necessary.
731
+ ///
732
+ /// This function imports a vCard, so will transfer the public key
733
+ /// as a side effect.
709
734
pub async fn add_or_lookup_contact ( & self , other : & TestContext ) -> Contact {
710
735
let contact_id = self . create_contact_id ( other) . await ;
711
736
Contact :: get_by_id ( & self . ctx , contact_id) . await . unwrap ( )
712
737
}
713
738
714
- /// Returns 1:1 [`Chat`] with another account. Panics if it doesn't exist.
739
+ /// Returns 1:1 [`Chat`] with another account email contact.
740
+ /// Panics if it doesn't exist.
715
741
/// May return a blocked chat.
716
742
///
717
743
/// This first creates a contact using the configured details on the other account, then
@@ -731,6 +757,27 @@ impl TestContext {
731
757
Chat :: load_from_db ( & self . ctx , chat_id) . await . unwrap ( )
732
758
}
733
759
760
+ /// Returns 1:1 [`Chat`] with another account PGP-contact.
761
+ /// Panics if the chat does not exist.
762
+ ///
763
+ /// This first creates a contact, but does not import the key,
764
+ /// so may create a PGP-contact with a fingerprint
765
+ /// but without the key.
766
+ pub async fn get_pgp_chat ( & self , other : & TestContext ) -> Chat {
767
+ let contact = self . add_or_lookup_pgp_contact ( other) . await ;
768
+
769
+ let chat_id = ChatIdBlocked :: lookup_by_contact ( & self . ctx , contact. id )
770
+ . await
771
+ . unwrap ( )
772
+ . map ( |chat_id_blocked| chat_id_blocked. id )
773
+ . expect (
774
+ "There is no chat with this contact. \
775
+ Hint: Use create_chat() instead of get_chat() if this is expected.",
776
+ ) ;
777
+
778
+ Chat :: load_from_db ( & self . ctx , chat_id) . await . unwrap ( )
779
+ }
780
+
734
781
/// Creates a contact for another account.
735
782
///
736
783
/// This exports a vCard from the `other`
0 commit comments