@@ -1127,19 +1127,45 @@ func GetContacts(connId int) {
11271127 LOG_WARNING (fmt .Sprintf ("get all contacts failed %#v" , contErr ))
11281128 } else {
11291129 LOG_TRACE (fmt .Sprintf ("contacts %#v" , contacts ))
1130+ var userIdName map [string ]string = make (map [string ]string )
1131+
1132+ // add lid-based data first (public names)
11301133 for jid , contactInfo := range contacts {
1131- name := GetNameFromContactInfo (contactInfo )
1132- if len (name ) > 0 {
1133- userId := JidToStr (client , jid )
1134- phone := PhoneFromUserId (userId )
1135- isSelf := BoolToInt (userId == selfId )
1136- LOG_TRACE (fmt .Sprintf ("Call CWmNewContactsNotify %s %s" , userId , name ))
1137- CWmNewContactsNotify (connId , userId , name , phone , isSelf , isNotify )
1138- AddContactName (connId , userId , name )
1139- } else {
1140- LOG_WARNING (fmt .Sprintf ("Skip CWmNewContactsNotify %s %#v" , JidToStr (client , jid ), contactInfo ))
1134+ if jid .Server == types .HiddenUserServer {
1135+ name := GetNameFromContactInfo (contactInfo )
1136+ if len (name ) > 0 {
1137+ userId := JidToStr (client , jid )
1138+ userIdName [userId ] = name
1139+ } else {
1140+ LOG_WARNING (fmt .Sprintf ("Skip empty name %s %#v" , JidToStr (client , jid ), contactInfo ))
1141+ }
11411142 }
11421143 }
1144+
1145+ // add regular data second (address book names)
1146+ for jid , contactInfo := range contacts {
1147+ if jid .Server != types .HiddenUserServer {
1148+ name := GetNameFromContactInfo (contactInfo )
1149+ if len (name ) > 0 {
1150+ userId := JidToStr (client , jid )
1151+ if oldName , ok := userIdName [userId ]; ok {
1152+ LOG_TRACE (fmt .Sprintf ("Replace public name %s with %s" , oldName , name ))
1153+ }
1154+ userIdName [userId ] = name
1155+ } else {
1156+ LOG_WARNING (fmt .Sprintf ("Skip empty name %s %#v" , JidToStr (client , jid ), contactInfo ))
1157+ }
1158+ }
1159+ }
1160+
1161+ // propagate data
1162+ for userId , name := range userIdName {
1163+ phone := PhoneFromUserId (userId )
1164+ isSelf := BoolToInt (userId == selfId )
1165+ LOG_TRACE (fmt .Sprintf ("Call CWmNewContactsNotify %s %s" , userId , name ))
1166+ CWmNewContactsNotify (connId , userId , name , phone , isSelf , isNotify )
1167+ AddContactName (connId , userId , name )
1168+ }
11431169 }
11441170
11451171 // groups
0 commit comments