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(chat): preserve peer name for outgoing messages (#824)
Hamed Yousefian48b829359670
diff --git a/src/infrastructure/chatstorage/sqlite_repository.go b/src/infrastructure/chatstorage/sqlite_repository.goindex 39272906..e5160361 100644--- a/src/infrastructure/chatstorage/sqlite_repository.go+++ b/src/infrastructure/chatstorage/sqlite_repository.go@@ -2201,8 +2201,17 @@ func (r *SQLiteRepository) CreateMessage(ctx context.Context, evt *events.Messagreturn r.DeleteMessageByDevice(deviceID, revokedMessageID, chatJID)}+ // PushName belongs to the sender. For messages sent from this account, using+ // it as the peer chat name would label the recipient with our own name.+ chatNameSenderUser := normalizedSender.User+ chatNamePushName := evt.Info.PushName+ if evt.Info.IsFromMe {+ chatNameSenderUser = normalizedChatJID.User+ chatNamePushName = ""+ }+// Get appropriate chat name using pushname if available (device-scoped)- chatName := r.GetChatNameWithPushNameByDevice(deviceID, normalizedChatJID, chatJID, normalizedSender.User, evt.Info.PushName)+ chatName := r.GetChatNameWithPushNameByDevice(deviceID, normalizedChatJID, chatJID, chatNameSenderUser, chatNamePushName)// Get existing chat to preserve ephemeral_expiration and archived status if needed (device-scoped)existingChat, err := r.GetChatByDevice(deviceID, chatJID)diff --git a/src/infrastructure/chatstorage/sqlite_repository_test.go b/src/infrastructure/chatstorage/sqlite_repository_test.goindex 2b33f146..6315e1b9 100644--- a/src/infrastructure/chatstorage/sqlite_repository_test.go+++ b/src/infrastructure/chatstorage/sqlite_repository_test.go@@ -9,7 +9,12 @@ import ("time"domainChatStorage "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"+ "github.com/aldinokemal/go-whatsapp-web-multidevice/infrastructure/whatsapp""github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/sqlite"+ "go.mau.fi/whatsmeow/proto/waE2E"+ "go.mau.fi/whatsmeow/types"+ "go.mau.fi/whatsmeow/types/events"+ "google.golang.org/protobuf/proto")func newTestSQLiteRepository(t *testing.T) *SQLiteRepository {@@ -45,6 +50,55 @@ func TestSQLiteRepositoryInitializesMessageReactionsSchema(t *testing.T) {}}+func TestCreateMessageFromMeKeepsPeerChatName(t *testing.T) {+ repo := newTestSQLiteRepository(t)+ accountJID := types.NewJID("15550101000", types.DefaultUserServer)+ peerJID := types.NewJID("15550102000", types.DefaultUserServer)+ timestamp := time.Date(2026, time.September, 2, 15, 30, 0, 0, time.UTC)++ if err := repo.StoreChat(&domainChatStorage.Chat{+ DeviceID: accountJID.String(),+ JID: peerJID.String(),+ Name: peerJID.User,+ LastMessageTime: timestamp.Add(-time.Minute),+ }); err != nil {+ t.Fatalf("store peer chat: %v", err)+ }++ ctx := whatsapp.ContextWithDevice(+ context.Background(),+ whatsapp.NewDeviceInstance(accountJID.String(), nil, repo),+ )+ event := &events.Message{+ Info: types.MessageInfo{+ MessageSource: types.MessageSource{+ Chat: peerJID,+ Sender: accountJID,+ IsFromMe: true,+ },+ ID: "outgoing-message-1",+ PushName: "Alice Smith",+ Timestamp: timestamp,+ },+ Message: &waE2E.Message{Conversation: proto.String("Hello Bob")},+ }++ if err := repo.CreateMessage(ctx, event); err != nil {+ t.Fatalf("create outgoing message: %v", err)+ }++ chat, err := repo.GetChatByDevice(accountJID.String(), peerJID.String())+ if err != nil {+ t.Fatalf("get peer chat: %v", err)+ }+ if chat == nil {+ t.Fatal("expected peer chat")+ }+ if chat.Name != peerJID.User {+ t.Fatalf("outgoing message changed peer chat name to %q, want %q", chat.Name, peerJID.User)+ }+}+func TestSQLiteRepositoryGetsDeviceWebhookConfigByJID(t *testing.T) {repo := newTestSQLiteRepository(t)