File tree 2 files changed +26
-4
lines changed
2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -1537,6 +1537,7 @@ impl CommandApi {
1537
1537
Ok ( ( ) )
1538
1538
}
1539
1539
1540
+ /// Sets display name for existing contact.
1540
1541
async fn change_contact_name (
1541
1542
& self ,
1542
1543
account_id : u32 ,
@@ -1545,9 +1546,7 @@ impl CommandApi {
1545
1546
) -> Result < ( ) > {
1546
1547
let ctx = self . get_context ( account_id) . await ?;
1547
1548
let contact_id = ContactId :: new ( contact_id) ;
1548
- let contact = Contact :: get_by_id ( & ctx, contact_id) . await ?;
1549
- let addr = contact. get_addr ( ) ;
1550
- Contact :: create ( & ctx, & name, addr) . await ?;
1549
+ contact_id. set_name ( & ctx, & name) . await ?;
1551
1550
Ok ( ( ) )
1552
1551
}
1553
1552
Original file line number Diff line number Diff line change @@ -95,6 +95,29 @@ impl ContactId {
95
95
self . 0
96
96
}
97
97
98
+ /// Sets display name for existing contact.
99
+ ///
100
+ /// Display name may be an empty string,
101
+ /// in which case the name displayed in the UI
102
+ /// for this contact will switch to the
103
+ /// contact's authorized name.
104
+ pub async fn set_name ( self , context : & Context , name : & str ) -> Result < ( ) > {
105
+ context
106
+ . sql
107
+ . transaction ( |transaction| {
108
+ let is_changed = transaction. execute (
109
+ "UPDATE contacts SET name=?1 WHERE id=?2 AND name!=?1" ,
110
+ ( name, self ) ,
111
+ ) ? > 0 ;
112
+ if is_changed {
113
+ update_chat_names ( context, transaction, self ) ?;
114
+ }
115
+ Ok ( ( ) )
116
+ } )
117
+ . await ?;
118
+ Ok ( ( ) )
119
+ }
120
+
98
121
/// Mark contact as bot.
99
122
pub ( crate ) async fn mark_bot ( & self , context : & Context , is_bot : bool ) -> Result < ( ) > {
100
123
context
@@ -909,7 +932,7 @@ impl Contact {
909
932
910
933
if update_name || update_authname {
911
934
let contact_id = ContactId :: new ( row_id) ;
912
- update_chat_names ( context, & transaction, contact_id) ?;
935
+ update_chat_names ( context, transaction, contact_id) ?;
913
936
}
914
937
sth_modified = Modifier :: Modified ;
915
938
}
You can’t perform that action at this time.
0 commit comments