mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
fix: synchronize contact name changes
This commit is contained in:
@@ -730,3 +730,20 @@ def test_no_old_msg_is_fresh(acfactory):
|
|||||||
assert ev.chat_id == first_msg.get_snapshot().chat_id
|
assert ev.chat_id == first_msg.get_snapshot().chat_id
|
||||||
assert ac1.create_chat(ac2).get_fresh_message_count() == 0
|
assert ac1.create_chat(ac2).get_fresh_message_count() == 0
|
||||||
assert len(list(ac1.get_fresh_messages())) == 0
|
assert len(list(ac1.get_fresh_messages())) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_rename_synchronization(acfactory):
|
||||||
|
"""Test synchronization of contact renaming."""
|
||||||
|
alice, bob = acfactory.get_online_accounts(2)
|
||||||
|
alice2 = alice.clone()
|
||||||
|
alice2.bring_online()
|
||||||
|
|
||||||
|
bob.set_config("displayname", "Bob")
|
||||||
|
bob.create_chat(alice).send_text("Hello!")
|
||||||
|
alice_msg = alice.wait_for_incoming_msg().get_snapshot()
|
||||||
|
alice2_msg = alice2.wait_for_incoming_msg().get_snapshot()
|
||||||
|
|
||||||
|
assert alice2_msg.sender.get_snapshot().display_name == "Bob"
|
||||||
|
alice_msg.sender.set_name("Bobby")
|
||||||
|
alice2.wait_for_event(EventType.CONTACTS_CHANGED)
|
||||||
|
assert alice2_msg.sender.get_snapshot().display_name == "Bobby"
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ impl ContactId {
|
|||||||
/// for this contact will switch to the
|
/// for this contact will switch to the
|
||||||
/// contact's authorized name.
|
/// contact's authorized name.
|
||||||
pub async fn set_name(self, context: &Context, name: &str) -> Result<()> {
|
pub async fn set_name(self, context: &Context, name: &str) -> Result<()> {
|
||||||
context
|
let addr = context
|
||||||
.sql
|
.sql
|
||||||
.transaction(|transaction| {
|
.transaction(|transaction| {
|
||||||
let is_changed = transaction.execute(
|
let is_changed = transaction.execute(
|
||||||
@@ -111,10 +111,31 @@ impl ContactId {
|
|||||||
)? > 0;
|
)? > 0;
|
||||||
if is_changed {
|
if is_changed {
|
||||||
update_chat_names(context, transaction, self)?;
|
update_chat_names(context, transaction, self)?;
|
||||||
|
let addr = transaction.query_row(
|
||||||
|
"SELECT addr FROM contacts WHERE id=?",
|
||||||
|
(self,),
|
||||||
|
|row| {
|
||||||
|
let addr: String = row.get(0)?;
|
||||||
|
Ok(addr)
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
Ok(Some(addr))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
if let Some(addr) = addr {
|
||||||
|
chat::sync(
|
||||||
|
context,
|
||||||
|
chat::SyncId::ContactAddr(addr.to_string()),
|
||||||
|
chat::SyncAction::Rename(name.to_string()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.log_err(context)
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user