init authname when received by From: header (it is also updated from there)

This commit is contained in:
B. Petersen
2019-12-25 23:08:09 +01:00
committed by Alexander Krotov
parent de52c2da80
commit e1bd740249

View File

@@ -125,7 +125,7 @@ pub enum Origin {
/// set on Bob's side for contacts scanned and verified from a QR code. Only means the contact has once been established using the "securejoin" procedure in the past, getting the current key verification status requires calling dc_contact_is_verified() ! /// set on Bob's side for contacts scanned and verified from a QR code. Only means the contact has once been established using the "securejoin" procedure in the past, getting the current key verification status requires calling dc_contact_is_verified() !
SecurejoinJoined = 0x0200_0000, SecurejoinJoined = 0x0200_0000,
/// contact added mannually by dc_create_contact(), this should be the largets origin as otherwise the user cannot modify the names /// contact added mannually by dc_create_contact(), this should be the largest origin as otherwise the user cannot modify the names
ManuallyCreated = 0x0400_0000, ManuallyCreated = 0x0400_0000,
} }
@@ -410,11 +410,21 @@ impl Contact {
} }
sth_modified = Modifier::Modified; sth_modified = Modifier::Modified;
} }
} else if sql::execute( } else {
if origin == Origin::IncomingUnknownFrom {
update_authname = true;
}
if sql::execute(
context, context,
&context.sql, &context.sql,
"INSERT INTO contacts (name, addr, origin) VALUES(?, ?, ?);", "INSERT INTO contacts (name, addr, origin, authname) VALUES(?, ?, ?, ?);",
params![name.as_ref(), addr, origin,], params![
name.as_ref(),
addr,
origin,
if update_authname { name.as_ref() } else { "" }
],
) )
.is_ok() .is_ok()
{ {
@@ -424,6 +434,7 @@ impl Contact {
} else { } else {
error!(context, "Cannot add contact."); error!(context, "Cannot add contact.");
} }
}
Ok((row_id, sth_modified)) Ok((row_id, sth_modified))
} }
@@ -768,6 +779,9 @@ impl Contact {
return &self.name; return &self.name;
} }
if !self.authname.is_empty() { if !self.authname.is_empty() {
// normally, name is initialized by authname and this condition would not be needed.
// however, for some resilience against some maybe corrupted dev-versions,
// we do this extra-check for now.
return &self.authname; return &self.authname;
} }
&self.addr &self.addr