GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.
Go botgogolanggolang-whatsappgolang-whatsapp-apirestrest-apiwhatsappwhatsapp-apiwhatsapp-api-gowhatsapp-multi-devicewhatsapp-web-multi-device
fix(history-sync): keep DisplayName for group and newsletter chats
Aldino Kemal234811c7ad85
diff --git a/src/infrastructure/whatsapp/history_sync.go b/src/infrastructure/whatsapp/history_sync.goindex ea8cf7cb..ad1c8931 100644--- a/src/infrastructure/whatsapp/history_sync.go+++ b/src/infrastructure/whatsapp/history_sync.go@@ -401,6 +401,12 @@ func conversationChatName(ctx context.Context, resolver *ChatDisplayNameResolverif resolver == nil {return displayName}+ // Only one-to-one chats are named from the contact store. Asking the resolver with+ // no stored name makes it answer "Group <id>" / "Newsletter <id>" for those servers,+ // which is strictly worse than the subject the conversation already carries.+ if jid.Server == types.GroupServer || jid.Server == types.NewsletterServer {+ return displayName+ }resolved := resolver.Resolve(ctx, chatJID, "")if resolved == "" || resolved == chatJID || resolved == jid.ToNonAD().User {return displayNamediff --git a/src/infrastructure/whatsapp/history_sync_name_test.go b/src/infrastructure/whatsapp/history_sync_name_test.goindex 75650f44..e68890c5 100644--- a/src/infrastructure/whatsapp/history_sync_name_test.go+++ b/src/infrastructure/whatsapp/history_sync_name_test.go@@ -7,7 +7,9 @@ import ("go.mau.fi/whatsmeow/types")-type nameContactsSpy struct{ contacts map[types.JID]types.ContactInfo }+type nameContactsSpy struct {+ contacts map[types.JID]types.ContactInfo+}func (s nameContactsSpy) GetContact(_ context.Context, jid types.JID) (types.ContactInfo, error) {return s.contacts[jid], nil@@ -50,3 +52,26 @@ func TestConversationChatNameWithoutResolver(t *testing.T) {t.Fatalf("nil resolver should be a no-op: got %q", got)}}++// Groups and newsletters carry their real subject in DisplayName. Asking the resolver+// with no stored name answers "Group <id>" / "Newsletter <id>", so those servers must+// never reach it.+func TestConversationChatNameKeepsDisplayNameForGroupAndNewsletter(t *testing.T) {+ resolver := newChatDisplayNameResolver(nameContactsSpy{contacts: map[types.JID]types.ContactInfo{}}, nil)++ for _, tc := range []struct {+ name string+ jid types.JID+ displayName string+ }{+ {"group", types.NewJID("120363012345678901", types.GroupServer), "Family Group"},+ {"newsletter", types.NewJID("120363111111111111", types.NewsletterServer), "Tech Channel"},+ } {+ t.Run(tc.name, func(t *testing.T) {+ got := conversationChatName(context.Background(), resolver, tc.jid.String(), tc.jid, tc.displayName)+ if got != tc.displayName {+ t.Fatalf("expected %q to be kept for %s, got %q", tc.displayName, tc.jid, got)+ }+ })+ }+}