api!: return DC_CONTACT_ID_SELF from dc_contact_get_verifier_id() for directly verified contacts

This commit is contained in:
link2xt
2023-09-28 16:09:15 +00:00
parent b463a0566e
commit f23023961e
2 changed files with 18 additions and 6 deletions

View File

@@ -5047,6 +5047,7 @@ int dc_contact_is_verified (dc_contact_t* contact);
* A string containing the verifiers address. If it is the same address as the contact itself, * A string containing the verifiers address. If it is the same address as the contact itself,
* we verified the contact ourself. If it is an empty string, we don't have verifier * we verified the contact ourself. If it is an empty string, we don't have verifier
* information or the contact is not verified. * information or the contact is not verified.
* @deprecated 2023-09-28, use dc_contact_get_verifier_id instead
*/ */
char* dc_contact_get_verifier_addr (dc_contact_t* contact); char* dc_contact_get_verifier_addr (dc_contact_t* contact);
@@ -5059,7 +5060,7 @@ char* dc_contact_get_verifier_addr (dc_contact_t* contact);
* @memberof dc_contact_t * @memberof dc_contact_t
* @param contact The contact object. * @param contact The contact object.
* @return * @return
* The `ContactId` of the verifiers address. If it is the same address as the contact itself, * The contact ID of the verifier. If it is DC_CONTACT_ID_SELF,
* we verified the contact ourself. If it is 0, we don't have verifier information or * we verified the contact ourself. If it is 0, we don't have verifier information or
* the contact is not verified. * the contact is not verified.
*/ */

View File

@@ -1252,13 +1252,24 @@ impl Contact {
/// Returns the ContactId that verified the contact. /// Returns the ContactId that verified the contact.
pub async fn get_verifier_id(&self, context: &Context) -> Result<Option<ContactId>> { pub async fn get_verifier_id(&self, context: &Context) -> Result<Option<ContactId>> {
let verifier_addr = self.get_verifier_addr(context).await?; let Some(verifier_addr) = self.get_verifier_addr(context).await? else {
if let Some(addr) = verifier_addr { return Ok(None);
Ok(Contact::lookup_id_by_addr(context, &addr, Origin::AddressBook).await?) };
} else {
if verifier_addr == self.addr {
// Contact is directly verified via QR code.
return Ok(Some(ContactId::SELF));
}
match Contact::lookup_id_by_addr(context, &verifier_addr, Origin::AddressBook).await? {
Some(contact_id) => Ok(Some(contact_id)),
None => {
let addr = &self.addr;
warn!(context, "Could not lookup contact with address {verifier_addr} which introduced {addr}.");
Ok(None) Ok(None)
} }
} }
}
/// Returns the number of real (i.e. non-special) contacts in the database. /// Returns the number of real (i.e. non-special) contacts in the database.
pub async fn get_real_cnt(context: &Context) -> Result<usize> { pub async fn get_real_cnt(context: &Context) -> Result<usize> {