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(history-sync): keep the disappearing-messages timer on on-demand sync

Aldino Kemal00efd36d212b
diff --git a/src/infrastructure/chatstorage/sqlite_repository.go b/src/infrastructure/chatstorage/sqlite_repository.go
index 86c8ff69..2b86dc77 100644
--- a/src/infrastructure/chatstorage/sqlite_repository.go
+++ b/src/infrastructure/chatstorage/sqlite_repository.go
@@ -2804,5 +2804,7 @@ func (r *SQLiteRepository) getMigrations() []string {
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (device_id, chat_jid, poll_message_id)
)`,
+ // Migration 45: Anchor on-demand history sync without sorting the whole chat
+ `CREATE INDEX IF NOT EXISTS idx_messages_chat_device_timestamp ON messages(chat_jid, device_id, timestamp)`,
}
}
diff --git a/src/infrastructure/whatsapp/history_sync.go b/src/infrastructure/whatsapp/history_sync.go
index 3f1c1f3b..2e64910c 100644
--- a/src/infrastructure/whatsapp/history_sync.go
+++ b/src/infrastructure/whatsapp/history_sync.go
@@ -312,6 +312,12 @@ func processConversationMessages(ctx context.Context, data *waHistorySync.Histor
chat.LastMessageTime = existing.LastMessageTime
}
chat.Archived = existing.Archived
+ // An on-demand chunk carries no ephemeral setting, so a zero
+ // here means "not reported", not "disappearing messages off".
+ // Same rule the live message path uses.
+ if chat.EphemeralExpiration == 0 {
+ chat.EphemeralExpiration = existing.EphemeralExpiration
+ }
}
}
diff --git a/src/infrastructure/whatsapp/history_sync_test.go b/src/infrastructure/whatsapp/history_sync_test.go
index 84d663e8..5bedd2f2 100644
--- a/src/infrastructure/whatsapp/history_sync_test.go
+++ b/src/infrastructure/whatsapp/history_sync_test.go
@@ -169,7 +169,8 @@ func TestProcessHistorySyncRoutesOnDemandToConversationMessages(t *testing.T) {
// TestProcessConversationMessagesOnDemandPreservesNewerChatMetadata pins the
// on-demand chat-metadata regression: HISTORY_SYNC_ON_DEMAND carries messages
// older than the local anchor, so its batch timestamp must never move an
-// already-newer LastMessageTime backward, nor unarchive an archived chat.
+// already-newer LastMessageTime backward, unarchive an archived chat, nor
+// clear the disappearing-messages timer the chunk does not report.
func TestProcessConversationMessagesOnDemandPreservesNewerChatMetadata(t *testing.T) {
originalLog := log
log = waLog.Noop
@@ -180,10 +181,11 @@ func TestProcessConversationMessagesOnDemandPreservesNewerChatMetadata(t *testin
existingLastMessageTime := time.Date(2026, time.September, 6, 12, 0, 0, 0, time.UTC)
repo := &historyMessageBatchRepoSpy{
existingChat: &domainChatStorage.Chat{
- DeviceID: deviceID,
- JID: chatJID,
- LastMessageTime: existingLastMessageTime,
- Archived: true,
+ DeviceID: deviceID,
+ JID: chatJID,
+ LastMessageTime: existingLastMessageTime,
+ Archived: true,
+ EphemeralExpiration: 604800,
},
}
ctx := ContextWithDevice(context.Background(), NewDeviceInstance(deviceID, nil, nil))
@@ -218,6 +220,9 @@ func TestProcessConversationMessagesOnDemandPreservesNewerChatMetadata(t *testin
if !repo.lastStoredChat.Archived {
t.Fatal("expected Archived to remain true after on-demand sync")
}
+ if repo.lastStoredChat.EphemeralExpiration != 604800 {
+ t.Fatalf("expected EphemeralExpiration to stay at 604800, got %d", repo.lastStoredChat.EphemeralExpiration)
+ }
}
type historyMessageBatchRepoSpy struct {
diff --git a/src/usecase/chat.go b/src/usecase/chat.go
index d56fca60..c5dec65e 100644
--- a/src/usecase/chat.go
+++ b/src/usecase/chat.go
@@ -458,19 +458,11 @@ func (service serviceChat) RequestChatHistory(ctx context.Context, request domai
return response, err
}
- senderJID := targetJID
- if parsed, parseErr := types.ParseJID(oldest.Sender); parseErr == nil {
- senderJID = parsed
- } else if oldest.IsFromMe && client.Store != nil && client.Store.ID != nil {
- senderJID = client.Store.ID.ToNonAD()
- }
-
+ // BuildHistorySyncRequest reads only Chat, ID, IsFromMe and Timestamp.
anchor := &types.MessageInfo{
MessageSource: types.MessageSource{
Chat: targetJID,
- Sender: senderJID,
IsFromMe: oldest.IsFromMe,
- IsGroup: targetJID.Server == types.GroupServer,
},
ID: oldest.ID,
Timestamp: oldest.Timestamp,