Added prioritisation of own ids and forgotten prioritisation of recent records, necessary for update_identity to work properly; message to self now gets green from outgoing_message_rating
authorKrista Bennett <krista@pep-project.org>
Thu, 15 Feb 2018 00:15:05 +0100
changeset 2506876532219d20
parent 2505 1102a11afe18
child 2507 27d82316d474
Added prioritisation of own ids and forgotten prioritisation of recent records, necessary for update_identity to work properly; message to self now gets green from outgoing_message_rating
src/keymanagement.c
src/pEpEngine.c
     1.1 --- a/src/keymanagement.c	Wed Feb 14 18:49:09 2018 +0100
     1.2 +++ b/src/keymanagement.c	Thu Feb 15 00:15:05 2018 +0100
     1.3 @@ -676,13 +676,14 @@
     1.4          if (status == PEP_CANNOT_FIND_IDENTITY || !stored_ident) { 
     1.5   
     1.6              identity_list* id_list = NULL;
     1.7 +            //    * Search for identity with this address
     1.8              status = get_identities_by_address(session, identity->address, &id_list);
     1.9  
    1.10 -            //    * Search for identity with this address
    1.11 -            if (id_list && !(id_list->next)) { // exactly one            
    1.12 -                //    * If exactly one found
    1.13 -                //      * elect valid key for identity (see below)
    1.14 -                //      * Return this identity
    1.15 +            // Results are ordered by timestamp descending, so this covers
    1.16 +            // both the one-result and multi-result cases
    1.17 +            if (id_list) {
    1.18 +                if (stored_ident) // unlikely
    1.19 +                    free_identity(stored_ident);
    1.20                  stored_ident = id_list->ident;
    1.21              }
    1.22          }
     2.1 --- a/src/pEpEngine.c	Wed Feb 14 18:49:09 2018 +0100
     2.2 +++ b/src/pEpEngine.c	Thu Feb 15 00:15:05 2018 +0100
     2.3 @@ -94,7 +94,8 @@
     2.4      "               else 0"
     2.5      "          end) = 1"
     2.6      "   and identity.user_id = ?2" 
     2.7 -    "   order by is_own desc; ";
     2.8 +    "   order by is_own desc, "
     2.9 +    "   timestamp desc; ";
    2.10  
    2.11  static const char *sql_get_identity_without_trust_check =  
    2.12      "select identity.main_key_id, username, lang,"
    2.13 @@ -107,7 +108,8 @@
    2.14      "               else 0"
    2.15      "          end) = 1"
    2.16      "   and identity.user_id = ?2 "
    2.17 -    "   order by is_own desc; ";
    2.18 +    "   order by is_own desc, "
    2.19 +    "   timestamp desc; ";
    2.20  
    2.21  static const char *sql_get_identities_by_address =  
    2.22      "select user_id, identity.main_key_id, username, lang,"
    2.23 @@ -119,7 +121,8 @@
    2.24      "               when (replace(lower(address),'.','') = replace(lower(?1),'.','')) then (1)"
    2.25      "               else 0"
    2.26      "          end) = 1 "
    2.27 -    "   order by is_own desc; ";
    2.28 +    "   order by is_own desc, "
    2.29 +    "   timestamp desc; ";
    2.30  
    2.31  static const char *sql_replace_identities_fpr =  
    2.32      "update identity"
    2.33 @@ -601,7 +604,7 @@
    2.34      sqlite3_busy_timeout(_session->system_db, 1000);
    2.35  
    2.36  // increment this when patching DDL
    2.37 -#define _DDL_USER_VERSION "7"
    2.38 +#define _DDL_USER_VERSION "8"
    2.39  
    2.40      if (in_first) {
    2.41  
    2.42 @@ -662,6 +665,7 @@
    2.43                  "   comment text,\n"
    2.44                  "   flags integer default 0,\n"
    2.45                  "   is_own integer default 0,\n"
    2.46 +                "   timestamp integer default (datetime('now')),\n"
    2.47                  "   primary key (address, user_id)\n"
    2.48                  ");\n"
    2.49                  "create table if not exists trust (\n"
    2.50 @@ -749,7 +753,9 @@
    2.51          // is really necessary...
    2.52          if (version == 1) {
    2.53              bool version_changed = true;
    2.54 -
    2.55 +            if (table_contains_column(_session, "identity", "timestamp") > 0) {
    2.56 +                version = 8;
    2.57 +            }            
    2.58              if (table_contains_column(_session, "person", "is_pep_user") > 0) {
    2.59                  version = 7;
    2.60              }            
    2.61 @@ -967,6 +973,17 @@
    2.62                  );
    2.63                  assert(int_result == SQLITE_OK);    
    2.64              }
    2.65 +            if (version < 8) {
    2.66 +                int_result = sqlite3_exec(
    2.67 +                    _session->db,
    2.68 +                    "alter table identity \n"
    2.69 +                    "   add column timestamp timestamp integer default (datetime('now'));\n",
    2.70 +                    NULL,
    2.71 +                    NULL,
    2.72 +                    NULL
    2.73 +                );
    2.74 +                assert(int_result == SQLITE_OK);
    2.75 +            }
    2.76          }        
    2.77          else { 
    2.78              // Version from DB was 0, it means this is initial setup.