Revert the refactoring for now, it maybe things too difficult to review

This commit is contained in:
Hocuri
2025-01-06 15:44:39 +01:00
parent 1f82241465
commit 057501cacd

View File

@@ -867,35 +867,33 @@ impl Contact {
} else { } else {
row_name row_name
}; };
let new_addr = if update_addr {
addr.to_string()
} else {
row_addr
};
let new_origin = if origin > row_origin {
origin
} else {
row_origin
};
let new_authname = if update_authname {
name
} else {
row_authname
};
transaction transaction
.execute( .execute(
"UPDATE contacts SET name=?, addr=?, origin=?, authname=? WHERE id=?;", "UPDATE contacts SET name=?, addr=?, origin=?, authname=? WHERE id=?;",
( (
new_name.clone(), new_name,
new_addr, if update_addr {
new_origin, addr.to_string()
new_authname.clone(), } else {
row_addr
},
if origin > row_origin {
origin
} else {
row_origin
},
if update_authname {
name.to_string()
} else {
row_authname
},
row_id row_id
), ),
)?; )?;
if update_name || update_authname { if update_name || update_authname {
// The contact name is also used as the name of the 1:1 chat, which therefore also needs to be updated. // Update the contact name also if it is used as a group name.
// This is one of the few duplicated data, however, getting the chat list is easier this way. // This is one of the few duplicated data, however, getting the chat list is easier this way.
let chat_id: Option<ChatId> = transaction.query_row( let chat_id: Option<ChatId> = transaction.query_row(
"SELECT id FROM chats WHERE type=? AND id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?)", "SELECT id FROM chats WHERE type=? AND id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?)",
@@ -907,12 +905,26 @@ impl Contact {
).optional()?; ).optional()?;
if let Some(chat_id) = chat_id { if let Some(chat_id) = chat_id {
let chat_name = if !new_name.is_empty() { let contact_id = ContactId::new(row_id);
new_name let (addr, name, authname) =
} else if !new_authname.is_empty() { transaction.query_row(
format!("~{}", new_authname) "SELECT addr, name, authname
FROM contacts
WHERE id=?",
(contact_id,),
|row| {
let addr: String = row.get(0)?;
let name: String = row.get(1)?;
let authname: String = row.get(2)?;
Ok((addr, name, authname))
})?;
let chat_name = if !name.is_empty() {
name
} else if !authname.is_empty() {
format!("~{}", authname)
} else { } else {
addr.to_string() addr
}; };
let count = transaction.execute( let count = transaction.execute(
@@ -922,7 +934,7 @@ impl Contact {
if count > 0 { if count > 0 {
// Chat name updated // Chat name updated
context.emit_event(EventType::ChatModified(chat_id)); context.emit_event(EventType::ChatModified(chat_id));
chatlist_events::emit_chatlist_items_changed_for_contact(context, ContactId::new(row_id)); chatlist_events::emit_chatlist_items_changed_for_contact(context, contact_id);
} }
} }
} }