Skip to content

Commit 6cb6daa

Browse files
committed
fix: synchronize contact name changes
1 parent d25fb47 commit 6cb6daa

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

deltachat-rpc-client/tests/test_something.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,3 +730,20 @@ def test_no_old_msg_is_fresh(acfactory):
730730
assert ev.chat_id == first_msg.get_snapshot().chat_id
731731
assert ac1.create_chat(ac2).get_fresh_message_count() == 0
732732
assert len(list(ac1.get_fresh_messages())) == 0
733+
734+
735+
def test_rename_synchronization(acfactory):
736+
"""Test synchronization of contact renaming."""
737+
alice, bob = acfactory.get_online_accounts(2)
738+
alice2 = alice.clone()
739+
alice2.bring_online()
740+
741+
bob.set_config("displayname", "Bob")
742+
bob.create_chat(alice).send_text("Hello!")
743+
alice_msg = alice.wait_for_incoming_msg().get_snapshot()
744+
alice2_msg = alice2.wait_for_incoming_msg().get_snapshot()
745+
746+
assert alice2_msg.sender.get_snapshot().display_name == "Bob"
747+
alice_msg.sender.set_name("Bobby")
748+
alice2.wait_for_event(EventType.CONTACTS_CHANGED)
749+
assert alice2_msg.sender.get_snapshot().display_name == "Bobby"

src/contact.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl ContactId {
102102
/// for this contact will switch to the
103103
/// contact's authorized name.
104104
pub async fn set_name(self, context: &Context, name: &str) -> Result<()> {
105-
context
105+
let addr = context
106106
.sql
107107
.transaction(|transaction| {
108108
let is_changed = transaction.execute(
@@ -111,10 +111,31 @@ impl ContactId {
111111
)? > 0;
112112
if is_changed {
113113
update_chat_names(context, transaction, self)?;
114+
let addr = transaction.query_row(
115+
"SELECT addr FROM contacts WHERE id=?",
116+
(self,),
117+
|row| {
118+
let addr: String = row.get(0)?;
119+
Ok(addr)
120+
},
121+
)?;
122+
Ok(Some(addr))
123+
} else {
124+
Ok(None)
114125
}
115-
Ok(())
116126
})
117127
.await?;
128+
129+
if let Some(addr) = addr {
130+
chat::sync(
131+
context,
132+
chat::SyncId::ContactAddr(addr.to_string()),
133+
chat::SyncAction::Rename(name.to_string()),
134+
)
135+
.await
136+
.log_err(context)
137+
.ok();
138+
}
118139
Ok(())
119140
}
120141

0 commit comments

Comments
 (0)