mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 23:06:32 +03:00
back to two verification-check functions (#4966)
this pr keeps and refines documentation added in #4951, however, reverts the api introduced by #4951 which turns out to be not useful for UI in practise: UI anyway check for chat/no-chat beforehand, so a simple condition in profiles as `green_checkmark = chat_exist ? chat_is_protected() : contact_is_verified()` is more useful in practise and is waht UI need and did already in the past. (https://github.com/deltachat/deltachat-android/pull/2836 shows a detailed discussion) (as a side effect, beside saving code, this PR saves up to three database calls (get contact from chat in UI to pass it to profile_is_verified(), get chat from contact in core, load is_protected in core) - instead, core can use already is_protected from already loaded chat object) /me did check rust-tests, fingers crossed for python tests /me should re-setup python tests on local machine at some point :)
This commit is contained in:
@@ -3743,8 +3743,9 @@ int dc_chat_can_send (const dc_chat_t* chat);
|
|||||||
* if `verified_one_on_one_chats` setting is enabled.
|
* if `verified_one_on_one_chats` setting is enabled.
|
||||||
*
|
*
|
||||||
* UI should display a green checkmark
|
* UI should display a green checkmark
|
||||||
* in the chat title and
|
* in the chat title,
|
||||||
* in the chatlist item
|
* in the chatlist item
|
||||||
|
* and in the chat profile
|
||||||
* if chat protection is enabled.
|
* if chat protection is enabled.
|
||||||
*
|
*
|
||||||
* @memberof dc_chat_t
|
* @memberof dc_chat_t
|
||||||
@@ -5052,12 +5053,9 @@ int dc_contact_is_blocked (const dc_contact_t* contact);
|
|||||||
*
|
*
|
||||||
* If contact is verified
|
* If contact is verified
|
||||||
* UI should display green checkmark after the contact name
|
* UI should display green checkmark after the contact name
|
||||||
* in contact list items and
|
* in contact list items,
|
||||||
* in chat member list items.
|
* in chat member list items
|
||||||
*
|
* and in profiles if no chat with the contact exist (otherwise, use dc_chat_is_protected()).
|
||||||
* Do not use this function when displaying the contact profile view.
|
|
||||||
* Display green checkmark in the title of the contact profile
|
|
||||||
* if dc_contact_profile_is_verified() returns true.
|
|
||||||
*
|
*
|
||||||
* @memberof dc_contact_t
|
* @memberof dc_contact_t
|
||||||
* @param contact The contact object.
|
* @param contact The contact object.
|
||||||
@@ -5067,24 +5065,6 @@ int dc_contact_is_blocked (const dc_contact_t* contact);
|
|||||||
int dc_contact_is_verified (dc_contact_t* contact);
|
int dc_contact_is_verified (dc_contact_t* contact);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the contact profile title
|
|
||||||
* should contain a green checkmark.
|
|
||||||
* This indicates whether 1:1 chat with
|
|
||||||
* this contact has a green checkmark
|
|
||||||
* or will have if such chat is created.
|
|
||||||
*
|
|
||||||
* Use dc_contact_get_verified_id to display the verifier contact
|
|
||||||
* in the info section of the contact profile.
|
|
||||||
*
|
|
||||||
* @memberof dc_contact_t
|
|
||||||
* @param contact The contact object.
|
|
||||||
* @return 1=contact profile has a green checkmark in the title,
|
|
||||||
* 0=contact profile has no green checkmark in the title.
|
|
||||||
*/
|
|
||||||
int dc_contact_profile_is_verified (dc_contact_t* contact);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the contact ID that verified a contact.
|
* Return the contact ID that verified a contact.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -4119,21 +4119,6 @@ pub unsafe extern "C" fn dc_contact_is_verified(contact: *mut dc_contact_t) -> l
|
|||||||
.unwrap_or_default() as libc::c_int
|
.unwrap_or_default() as libc::c_int
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn dc_contact_profile_is_verified(contact: *mut dc_contact_t) -> libc::c_int {
|
|
||||||
if contact.is_null() {
|
|
||||||
eprintln!("ignoring careless call to dc_contact_profile_is_verified()");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
let ffi_contact = &*contact;
|
|
||||||
let ctx = &*ffi_contact.context;
|
|
||||||
|
|
||||||
block_on(ffi_contact.contact.is_profile_verified(ctx))
|
|
||||||
.context("is_profile_verified failed")
|
|
||||||
.log_err(ctx)
|
|
||||||
.unwrap_or_default() as libc::c_int
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_contact_get_verifier_id(contact: *mut dc_contact_t) -> u32 {
|
pub unsafe extern "C" fn dc_contact_get_verifier_id(contact: *mut dc_contact_t) -> u32 {
|
||||||
if contact.is_null() {
|
if contact.is_null() {
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ pub struct ContactObject {
|
|||||||
///
|
///
|
||||||
/// If this is true
|
/// If this is true
|
||||||
/// UI should display green checkmark after the contact name
|
/// UI should display green checkmark after the contact name
|
||||||
/// in contact list items and
|
/// in contact list items,
|
||||||
/// in chat member list items.
|
/// in chat member list items
|
||||||
|
/// and in profiles if no chat with the contact exist.
|
||||||
is_verified: bool,
|
is_verified: bool,
|
||||||
|
|
||||||
/// True if the contact profile title should have a green checkmark.
|
/// True if the contact profile title should have a green checkmark.
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ def test_qr_setup_contact(acfactory) -> None:
|
|||||||
alice_contact_bob = alice.get_contact_by_addr(bob.get_config("addr"))
|
alice_contact_bob = alice.get_contact_by_addr(bob.get_config("addr"))
|
||||||
alice_contact_bob_snapshot = alice_contact_bob.get_snapshot()
|
alice_contact_bob_snapshot = alice_contact_bob.get_snapshot()
|
||||||
assert alice_contact_bob_snapshot.is_verified
|
assert alice_contact_bob_snapshot.is_verified
|
||||||
assert alice_contact_bob_snapshot.is_profile_verified
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
event = bob.wait_for_event()
|
event = bob.wait_for_event()
|
||||||
@@ -30,7 +29,6 @@ def test_qr_setup_contact(acfactory) -> None:
|
|||||||
bob_contact_alice = bob.get_contact_by_addr(alice.get_config("addr"))
|
bob_contact_alice = bob.get_contact_by_addr(alice.get_config("addr"))
|
||||||
bob_contact_alice_snapshot = bob_contact_alice.get_snapshot()
|
bob_contact_alice_snapshot = bob_contact_alice.get_snapshot()
|
||||||
assert bob_contact_alice_snapshot.is_verified
|
assert bob_contact_alice_snapshot.is_verified
|
||||||
assert bob_contact_alice_snapshot.is_profile_verified
|
|
||||||
|
|
||||||
|
|
||||||
def test_qr_securejoin(acfactory):
|
def test_qr_securejoin(acfactory):
|
||||||
@@ -51,7 +49,6 @@ def test_qr_securejoin(acfactory):
|
|||||||
alice_contact_bob = alice.get_contact_by_addr(bob.get_config("addr"))
|
alice_contact_bob = alice.get_contact_by_addr(bob.get_config("addr"))
|
||||||
alice_contact_bob_snapshot = alice_contact_bob.get_snapshot()
|
alice_contact_bob_snapshot = alice_contact_bob.get_snapshot()
|
||||||
assert alice_contact_bob_snapshot.is_verified
|
assert alice_contact_bob_snapshot.is_verified
|
||||||
assert alice_contact_bob_snapshot.is_profile_verified
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
event = bob.wait_for_event()
|
event = bob.wait_for_event()
|
||||||
@@ -62,7 +59,6 @@ def test_qr_securejoin(acfactory):
|
|||||||
bob_contact_alice = bob.get_contact_by_addr(alice.get_config("addr"))
|
bob_contact_alice = bob.get_contact_by_addr(alice.get_config("addr"))
|
||||||
bob_contact_alice_snapshot = bob_contact_alice.get_snapshot()
|
bob_contact_alice_snapshot = bob_contact_alice.get_snapshot()
|
||||||
assert bob_contact_alice_snapshot.is_verified
|
assert bob_contact_alice_snapshot.is_verified
|
||||||
assert bob_contact_alice_snapshot.is_profile_verified
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail()
|
@pytest.mark.xfail()
|
||||||
|
|||||||
@@ -1261,9 +1261,8 @@ impl Contact {
|
|||||||
/// in contact list items and
|
/// in contact list items and
|
||||||
/// in chat member list items.
|
/// in chat member list items.
|
||||||
///
|
///
|
||||||
/// Do not use this function when displaying the contact profile view.
|
/// In contact profile view, us this function only if there is no chat with the contact,
|
||||||
/// Display green checkmark in the title of the contact profile
|
/// otherwise use is_chat_protected().
|
||||||
/// if [Self::is_profile_verified] returns true.
|
|
||||||
/// Use [Self::get_verifier_id] to display the verifier contact
|
/// Use [Self::get_verifier_id] to display the verifier contact
|
||||||
/// in the info section of the contact profile.
|
/// in the info section of the contact profile.
|
||||||
pub async fn is_verified(&self, context: &Context) -> Result<VerifiedStatus> {
|
pub async fn is_verified(&self, context: &Context) -> Result<VerifiedStatus> {
|
||||||
@@ -1322,6 +1321,11 @@ impl Contact {
|
|||||||
/// This generally should be consistent with the 1:1 chat with the contact
|
/// This generally should be consistent with the 1:1 chat with the contact
|
||||||
/// so 1:1 chat with the contact and the contact profile
|
/// so 1:1 chat with the contact and the contact profile
|
||||||
/// either both display the green checkmark or both don't display a green checkmark.
|
/// either both display the green checkmark or both don't display a green checkmark.
|
||||||
|
///
|
||||||
|
/// UI often knows beforehand if a chat exists and can also call
|
||||||
|
/// `chat.is_protected()` (if there is a chat)
|
||||||
|
/// or `contact.is_verified()` (if there is no chat) directly.
|
||||||
|
/// This is often easier and also skips some database calls.
|
||||||
pub async fn is_profile_verified(&self, context: &Context) -> Result<bool> {
|
pub async fn is_profile_verified(&self, context: &Context) -> Result<bool> {
|
||||||
let contact_id = self.id;
|
let contact_id = self.id;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user