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: resolve display name issues and missing user info names (#590) (#595)

Aldino Kemal1c50d63f385f
diff --git a/src/cmd/root.go b/src/cmd/root.go
index 3a558222..0502cac0 100644
--- a/src/cmd/root.go
+++ b/src/cmd/root.go
@@ -390,7 +390,7 @@ func initApp() {
appUsecase = usecase.NewAppService(chatStorageRepo, dm)
chatUsecase = usecase.NewChatService(chatStorageRepo)
sendUsecase = usecase.NewSendService(appUsecase, chatStorageRepo)
- userUsecase = usecase.NewUserService()
+ userUsecase = usecase.NewUserService(chatStorageRepo)
messageUsecase = usecase.NewMessageService(chatStorageRepo)
groupUsecase = usecase.NewGroupService()
newsletterUsecase = usecase.NewNewsletterService()
diff --git a/src/domains/user/account.go b/src/domains/user/account.go
index dbf16e2d..03cc33c0 100644
--- a/src/domains/user/account.go
+++ b/src/domains/user/account.go
@@ -19,6 +19,7 @@ type InfoResponseDataDevice struct {
}
type InfoResponseData struct {
+ Name string `json:"name"`
VerifiedName string `json:"verified_name"`
Status string `json:"status"`
PictureID string `json:"picture_id"`
diff --git a/src/infrastructure/chatstorage/sqlite_repository.go b/src/infrastructure/chatstorage/sqlite_repository.go
index e0531233..14f32b40 100644
--- a/src/infrastructure/chatstorage/sqlite_repository.go
+++ b/src/infrastructure/chatstorage/sqlite_repository.go
@@ -669,7 +669,7 @@ func (r *SQLiteRepository) GetChatNameWithPushName(jid types.JID, chatJID string
existingChat, err := r.GetChat(chatJID)
if err == nil && existingChat != nil && existingChat.Name != "" {
// If we have a pushname and the existing name is just a phone number/JID user, update it
- if pushName != "" && (existingChat.Name == jid.User || existingChat.Name == senderUser) {
+ if pushName != "" && (existingChat.Name == jid.ToNonAD().User || existingChat.Name == senderUser) {
return pushName
}
return existingChat.Name
@@ -689,12 +689,12 @@ func (r *SQLiteRepository) GetChatNameWithPushName(jid types.JID, chatJID string
default:
// This is an individual contact
// Priority: pushName > senderUser > JID user
- if pushName != "" && pushName != senderUser && pushName != jid.User {
+ if pushName != "" && pushName != senderUser && pushName != jid.ToNonAD().User {
name = pushName
} else if senderUser != "" {
name = senderUser
} else {
- name = jid.User
+ name = jid.ToNonAD().User
}
}
@@ -712,7 +712,7 @@ func (r *SQLiteRepository) GetChatNameWithPushNameByDevice(deviceID string, jid
existingChat, err := r.GetChatByDevice(deviceID, chatJID)
if err == nil && existingChat != nil && existingChat.Name != "" {
// If we have a pushname and the existing name is just a phone number/JID user, update it
- if pushName != "" && (existingChat.Name == jid.User || existingChat.Name == senderUser) {
+ if pushName != "" && (existingChat.Name == jid.ToNonAD().User || existingChat.Name == senderUser) {
return pushName
}
return existingChat.Name
@@ -732,12 +732,12 @@ func (r *SQLiteRepository) GetChatNameWithPushNameByDevice(deviceID string, jid
default:
// This is an individual contact
// Priority: pushName > senderUser > JID user
- if pushName != "" && pushName != senderUser && pushName != jid.User {
+ if pushName != "" && pushName != senderUser && pushName != jid.ToNonAD().User {
name = pushName
} else if senderUser != "" {
name = senderUser
} else {
- name = jid.User
+ name = jid.ToNonAD().User
}
}
diff --git a/src/infrastructure/whatsapp/history_sync.go b/src/infrastructure/whatsapp/history_sync.go
index c98e78ac..1cb1cc6a 100644
--- a/src/infrastructure/whatsapp/history_sync.go
+++ b/src/infrastructure/whatsapp/history_sync.go
@@ -286,8 +286,24 @@ func processPushNames(ctx context.Context, data *waHistorySync.HistorySync, chat
// Check if chat exists (device-scoped to avoid cross-device data leak)
existingChat, err := chatStorageRepo.GetChatByDevice(deviceID, jidStr)
- if err != nil || existingChat == nil {
- // Chat doesn't exist yet, skip
+ if err != nil {
+ log.Warnf("Failed to check chat existence for %s: %v", jidStr, err)
+ continue
+ }
+
+ if existingChat == nil {
+ // Chat doesn't exist, create it to store the push name
+ newChat := &domainChatStorage.Chat{
+ DeviceID: deviceID,
+ JID: jidStr,
+ Name: name,
+ LastMessageTime: time.Time{}, // Use zero time so it doesn't bubble up in chat list
+ }
+ if err := chatStorageRepo.StoreChat(newChat); err != nil {
+ log.Warnf("Failed to create chat for %s during pushname sync: %v", jidStr, err)
+ } else {
+ log.Debugf("Created new chat entry from history sync")
+ }
continue
}
@@ -297,7 +313,7 @@ func processPushNames(ctx context.Context, data *waHistorySync.HistorySync, chat
if err := chatStorageRepo.StoreChat(existingChat); err != nil {
log.Warnf("Failed to update chat name for %s: %v", jidStr, err)
} else {
- log.Debugf("Updated chat name for %s to %s", jidStr, name)
+ log.Debugf("Updated chat name from history sync")
}
}
}
diff --git a/src/usecase/user.go b/src/usecase/user.go
index 37868022..45f6ef4b 100644
--- a/src/usecase/user.go
+++ b/src/usecase/user.go
@@ -9,22 +9,26 @@ import (
"time"
domainUser "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/user"
+ domainChatStorage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"
"github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp"
pkgError "github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/error"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
"github.com/aldinokemal/go-whatsapp-web-multidevice/validations"
"github.com/disintegration/imaging"
+ "github.com/sirupsen/logrus"
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/appstate"
"go.mau.fi/whatsmeow/types"
)
type serviceUser struct {
- // Remove the WaCli field - we'll use the global client instead
+ chatStorageRepo domainChatStorage.IChatStorageRepository
}
-func NewUserService() domainUser.IUserUsecase {
- return &serviceUser{}
+func NewUserService(chatStorageRepo domainChatStorage.IChatStorageRepository) domainUser.IUserUsecase {
+ return &serviceUser{
+ chatStorageRepo: chatStorageRepo,
+ }
}
func (service serviceUser) Info(ctx context.Context, request domainUser.InfoRequest) (response domainUser.InfoResponse, err error) {
@@ -67,7 +71,19 @@ func (service serviceUser) Info(ctx context.Context, request domainUser.InfoRequ
return response, err
}
- for _, userInfo := range resp {
+ // Get device ID for scoped storage lookup
+ deviceID := ""
+ if inst, ok := whatsapp.DeviceFromContext(ctx); ok && inst != nil {
+ deviceID = inst.JID()
+ if deviceID == "" {
+ deviceID = inst.ID()
+ }
+ }
+ if deviceID == "" && client.Store != nil && client.Store.ID != nil {
+ deviceID = client.Store.ID.ToNonAD().String()
+ }
+
+ for jid, userInfo := range resp {
var device []domainUser.InfoResponseDataDevice
for _, j := range userInfo.Devices {
device = append(device, domainUser.InfoResponseDataDevice{
@@ -84,6 +100,16 @@ func (service serviceUser) Info(ctx context.Context, request domainUser.InfoRequ
PictureID: userInfo.PictureID,
Devices: device,
}
+
+ // Try to get name from storage if available (device-scoped to prevent data leak)
+ if service.chatStorageRepo != nil && deviceID != "" {
+ if chat, err := service.chatStorageRepo.GetChatByDevice(deviceID, jid.String()); err == nil && chat != nil {
+ data.Name = chat.Name
+ } else if err != nil {
+ logrus.Debugf("Could not fetch chat name from storage for %s: %v", jid.String(), err)
+ }
+ }
+
if userInfo.VerifiedName != nil {
data.VerifiedName = fmt.Sprintf("%v", *userInfo.VerifiedName)
}