Skip to content

Commit e8ffeb6

Browse files
committed
fixes #432 - prioritize names from own address book over lid public names
1 parent 7383658 commit e8ffeb6

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

lib/common/src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
#pragma once
99

10-
#define NCHAT_VERSION "5.12.4"
10+
#define NCHAT_VERSION "5.12.5"

lib/wmchat/go/gowm.go

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/nchat.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
2-
.TH NCHAT "1" "November 2025" "nchat 5.12.4" "User Commands"
2+
.TH NCHAT "1" "November 2025" "nchat 5.12.5" "User Commands"
33
.SH NAME
44
nchat \- ncurses chat
55
.SH SYNOPSIS

0 commit comments

Comments
 (0)