diff --git a/cmdline/cmdline.c b/cmdline/cmdline.c index 1f6d569b..e24a84d4 100644 --- a/cmdline/cmdline.c +++ b/cmdline/cmdline.c @@ -347,8 +347,9 @@ static void log_contactlist(mrmailbox_t* mailbox, mrarray_t* contacts) if( (contact=mrmailbox_get_contact(mailbox, contact_id))!=NULL ) { char* name = mrcontact_get_name(contact); char* addr = mrcontact_get_addr(contact); - const char* verified = mrcontact_is_verified(contact)? " √": ""; - line = mr_mprintf("%s%s <%s>", (name&&name[0])? name : "", verified, (addr&&addr[0])? addr : "addr unset"); + int verified_state = mrcontact_is_verified(contact); + const char* verified_str = verified_state? (verified_state==2? " √√":" √"): ""; + line = mr_mprintf("%s%s <%s>", (name&&name[0])? name : "", verified_str, (addr&&addr[0])? addr : "addr unset"); mrsqlite3_lock(mailbox->m_sql); int peerstate_ok = mrapeerstate_load_by_addr__(peerstate, mailbox->m_sql, addr); mrsqlite3_unlock(mailbox->m_sql); @@ -704,7 +705,7 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline) char* temp_subtitle = mrchat_get_subtitle(chat); char* temp_name = mrchat_get_name(chat); - const char* verified = mrchat_is_verified(chat)? " √": ""; + const char* verified = mrchat_is_verified(chat)? " √√": ""; mrmailbox_log_info(mailbox, 0, "%s#%i: %s%s [%s] [%i fresh]", mrchat_get_type(chat)==MR_CHAT_TYPE_GROUP? "Groupchat" : "Chat", (int)mrchat_get_id(chat), temp_name, verified, temp_subtitle, (int)mrmailbox_get_fresh_msg_count(mailbox, mrchat_get_id(chat))); free(temp_subtitle); diff --git a/src/mrapeerstate.c b/src/mrapeerstate.c index c38efc20..f4d92214 100644 --- a/src/mrapeerstate.c +++ b/src/mrapeerstate.c @@ -496,6 +496,7 @@ cleanup: * * @param peerstate The peerstate object. * @param fingerprint Fingerprint expected in the object + * @param verified 1=we verified the contact, 2=contact verfied in both directions * * @return 1=the given fingerprint is equal to the peer's fingerprint and * the verified-state is set; you should call mrapeerstate_save_to_db__() @@ -503,11 +504,11 @@ cleanup: * 0=the given fingerprint is not eqial to the peer's fingerprint, * verified-state not changed. */ -int mrapeerstate_set_verified(mrapeerstate_t* peerstate, const char* fingerprint) +int mrapeerstate_set_verified(mrapeerstate_t* peerstate, const char* fingerprint, int verified) { - int verified = 0; + int success = 0; - if( peerstate == NULL || fingerprint == NULL ) { + if( peerstate == NULL || fingerprint == NULL || verified<1 || verified>2 ) { goto cleanup; } @@ -521,9 +522,9 @@ int mrapeerstate_set_verified(mrapeerstate_t* peerstate, const char* fingerprint peerstate->m_to_save |= MRA_SAVE_ALL; peerstate->m_prefer_encrypt = MRA_PE_MUTUAL; - peerstate->m_verified = 1; - verified = 1; + peerstate->m_verified = verified; + success = 1; cleanup: - return verified; + return success; } diff --git a/src/mrapeerstate.h b/src/mrapeerstate.h index f923dced..c3b93aba 100644 --- a/src/mrapeerstate.h +++ b/src/mrapeerstate.h @@ -87,7 +87,7 @@ mrkey_t* mrapeerstate_peek_key (const mrapeerstate_t*); int mrapeerstate_recalc_fingerprint (mrapeerstate_t*); -int mrapeerstate_set_verified (mrapeerstate_t*, const char* fingerprint); +int mrapeerstate_set_verified (mrapeerstate_t*, const char* fingerprint, int verfied); int mrapeerstate_load_by_addr__ (mrapeerstate_t*, mrsqlite3_t*, const char* addr); int mrapeerstate_load_by_fingerprint__(mrapeerstate_t*, mrsqlite3_t*, const char* fingerprint); diff --git a/src/mrcontact.c b/src/mrcontact.c index a2856e56..2136d84d 100644 --- a/src/mrcontact.c +++ b/src/mrcontact.c @@ -260,11 +260,8 @@ int mrcontact_is_blocked(mrcontact_t* contact) * @param contact The contact object. * * @return 0=contact is not verified. - * 1=SELF has verified the fingerprint of the contact, it is not clear if the - * contact has verified the fingerprint of SELF; in the UI typically - * one checkmark is shown. - * 2=secure join - SELF and contact have verified their fingerprints in both - * directions; in the UI typically two checkmarks are shown. + * 2=SELF and contact have verified their fingerprints in both directions; in the UI typically checkmarks are shown. + * 1=SELF has verified the contact but not the other way round. */ int mrcontact_is_verified(mrcontact_t* contact) { diff --git a/src/mrmailbox.c b/src/mrmailbox.c index 64cded47..7fbc6387 100644 --- a/src/mrmailbox.c +++ b/src/mrmailbox.c @@ -3759,22 +3759,26 @@ mrarray_t* mrmailbox_get_contacts(mrmailbox_t* mailbox, uint32_t listflags, cons self_addr = mrsqlite3_get_config__(mailbox->m_sql, "configured_addr", ""); /* we add MR_CONTACT_ID_SELF explicitly; so avoid doubles if the address is present as a normal entry for some case */ - if( query ) + if( (listflags&MR_GCL_VERIFIED_ONLY) || query ) { - if( (s3strLikeCmd=sqlite3_mprintf("%%%s%%", query))==NULL ) { + if( (s3strLikeCmd=sqlite3_mprintf("%%%s%%", query? query : ""))==NULL ) { goto cleanup; } stmt = mrsqlite3_predefine__(mailbox->m_sql, SELECT_id_FROM_contacts_WHERE_query_ORDER_BY, - "SELECT id FROM contacts" - " WHERE addr!=? AND id>" MR_STRINGIFY(MR_CONTACT_ID_LAST_SPECIAL) " AND origin>=" MR_STRINGIFY(MR_ORIGIN_MIN_CONTACT_LIST) " AND blocked=0 AND (name LIKE ? OR addr LIKE ?)" /* see comments in mrmailbox_search_msgs() about the LIKE operator */ - " ORDER BY LOWER(name||addr),id;"); + "SELECT c.id FROM contacts c" + " LEFT JOIN acpeerstates ps ON c.addr=ps.addr " + " WHERE c.addr!=? AND c.id>" MR_STRINGIFY(MR_CONTACT_ID_LAST_SPECIAL) " AND c.origin>=" MR_STRINGIFY(MR_ORIGIN_MIN_CONTACT_LIST) " AND c.blocked=0 AND (c.name LIKE ? OR c.addr LIKE ?)" /* see comments in mrmailbox_search_msgs() about the LIKE operator */ + " AND (ps.verified=2 OR 1=0) " + " ORDER BY LOWER(c.name||c.addr),c.id;"); sqlite3_bind_text(stmt, 1, self_addr, -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 2, s3strLikeCmd, -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 3, s3strLikeCmd, -1, SQLITE_STATIC); + //sqlite3_bind_int (stmt, 4, (listflags&MR_GCL_VERIFIED_ONLY)? 2 : 0); + //sqlite3_bind_int (stmt, 5, (listflags&MR_GCL_VERIFIED_ONLY)? 0 : 1/*force statement being always true*/); self_name = mrsqlite3_get_config__(mailbox->m_sql, "displayname", ""); self_name2 = mrstock_str(MR_STR_SELF); - if( mr_str_contains(self_addr, query) || mr_str_contains(self_name, query) || mr_str_contains(self_name2, query) ) { + if( query==NULL || mr_str_contains(self_addr, query) || mr_str_contains(self_name, query) || mr_str_contains(self_name2, query) ) { add_self = 1; } } diff --git a/src/mrmailbox_securejoin.c b/src/mrmailbox_securejoin.c index 680f617e..e6d54684 100644 --- a/src/mrmailbox_securejoin.c +++ b/src/mrmailbox_securejoin.c @@ -188,7 +188,7 @@ static int mark_peer_as_verified__(mrmailbox_t* mailbox, const char* fingerprint goto cleanup; } - if( !mrapeerstate_set_verified(peerstate, fingerprint) ) { + if( !mrapeerstate_set_verified(peerstate, fingerprint, 2) ) { goto cleanup; }