Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

fix(contacts): use fallback names in contact listings

Aldino Kemaled6403a9425a
diff --git a/src/usecase/group.go b/src/usecase/group.go
index afedee73..ad33ceb6 100644
--- a/src/usecase/group.go
+++ b/src/usecase/group.go
@@ -594,6 +594,10 @@ func contactDisplayName(ctx context.Context, client *whatsmeow.Client, jid types
if err != nil || !contact.Found {
return ""
}
+ return contactInfoDisplayName(contact)
+}
+
+func contactInfoDisplayName(contact types.ContactInfo) string {
switch {
case contact.FullName != "":
return contact.FullName
diff --git a/src/usecase/user.go b/src/usecase/user.go
index d562496f..fd81048a 100644
--- a/src/usecase/user.go
+++ b/src/usecase/user.go
@@ -307,7 +307,7 @@ func (service serviceUser) MyListContacts(ctx context.Context) (response domainU
for jid, contact := range contacts {
response.Data = append(response.Data, domainUser.MyListContactsResponseData{
JID: jid,
- Name: contact.FullName,
+ Name: contactInfoDisplayName(contact),
})
}
diff --git a/src/usecase/user_test.go b/src/usecase/user_test.go
new file mode 100644
index 00000000..ccbf197b
--- /dev/null
+++ b/src/usecase/user_test.go
@@ -0,0 +1,43 @@
+package usecase
+
+import (
+ "testing"
+
+ "go.mau.fi/whatsmeow/types"
+)
+
+func TestContactDisplayName(t *testing.T) {
+ tests := []struct {
+ name string
+ contact types.ContactInfo
+ want string
+ }{
+ {
+ name: "prefers full name over push name and business name",
+ contact: types.ContactInfo{FullName: "Saved Name", PushName: "Push Name", BusinessName: "Biz Name"},
+ want: "Saved Name",
+ },
+ {
+ name: "falls back to push name when full name is empty",
+ contact: types.ContactInfo{PushName: "Push Name", BusinessName: "Biz Name"},
+ want: "Push Name",
+ },
+ {
+ name: "falls back to business name when full and push names are empty",
+ contact: types.ContactInfo{BusinessName: "Biz Name"},
+ want: "Biz Name",
+ },
+ {
+ name: "empty when no names are set",
+ contact: types.ContactInfo{},
+ want: "",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := contactInfoDisplayName(tt.contact); got != tt.want {
+ t.Fatalf("contactInfoDisplayName() = %q, want %q", got, tt.want)
+ }
+ })
+ }
+}