Skip to content

Commit 823d038

Browse files
Revert "fix(history-sync): ignore non-primary completions"
This reverts commit c0523d6.
1 parent c0523d6 commit 823d038

1 file changed

Lines changed: 10 additions & 22 deletions

File tree

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,18 +1017,15 @@ export class BaileysStartupService extends ChannelStartupService {
10171017
syncType?: proto.HistorySync.HistorySyncType;
10181018
}) => {
10191019
try {
1020-
const shouldTrackHistorySync = progress !== undefined && this.isSyncNotificationFromUsedSyncType(syncType);
10211020
const normalizedProgress = progress ?? -1;
10221021

1023-
if (shouldTrackHistorySync && normalizedProgress <= this.historySyncLastProgress) {
1022+
if (normalizedProgress <= this.historySyncLastProgress) {
10241023
this.historySyncMessageCount = 0;
10251024
this.historySyncChatCount = 0;
10261025
this.historySyncContactCount = 0;
10271026
}
10281027

1029-
if (shouldTrackHistorySync) {
1030-
this.historySyncLastProgress = normalizedProgress;
1031-
}
1028+
this.historySyncLastProgress = normalizedProgress;
10321029

10331030
if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) {
10341031
console.log('received on-demand history sync, messages=', messages);
@@ -1124,9 +1121,7 @@ export class BaileysStartupService extends ChannelStartupService {
11241121
await this.prismaRepository.chat.createMany({ data: chatsToCreateMany, skipDuplicates: true });
11251122
}
11261123

1127-
if (shouldTrackHistorySync) {
1128-
this.historySyncChatCount += chatsRaw.length;
1129-
}
1124+
this.historySyncChatCount += chatsRaw.length;
11301125

11311126
this.sendDataWebhook(Events.CHATS_SET, chatsRaw);
11321127

@@ -1181,9 +1176,7 @@ export class BaileysStartupService extends ChannelStartupService {
11811176
messagesRaw.push(this.prepareMessage(m));
11821177
}
11831178

1184-
if (shouldTrackHistorySync) {
1185-
this.historySyncMessageCount += messagesRaw.length;
1186-
}
1179+
this.historySyncMessageCount += messagesRaw.length;
11871180

11881181
if (this.configService.get<Database>('DATABASE').SAVE_DATA.HISTORIC) {
11891182
await this.prismaRepository.message.createMany({ data: messagesRaw, skipDuplicates: true });
@@ -1207,17 +1200,14 @@ export class BaileysStartupService extends ChannelStartupService {
12071200
}
12081201

12091202
const filteredContacts = contacts.filter((c) => !!c.notify || !!c.name);
1210-
if (shouldTrackHistorySync) {
1211-
this.historySyncContactCount += filteredContacts.length;
1212-
}
1203+
this.historySyncContactCount += filteredContacts.length;
12131204

1214-
if (shouldTrackHistorySync && normalizedProgress === 100) {
1205+
if (normalizedProgress === 100) {
12151206
this.sendDataWebhook(Events.MESSAGING_HISTORY_SET, {
12161207
messageCount: this.historySyncMessageCount,
12171208
chatCount: this.historySyncChatCount,
12181209
contactCount: this.historySyncContactCount,
12191210
progress: normalizedProgress,
1220-
syncType,
12211211
});
12221212

12231213
this.historySyncMessageCount = 0;
@@ -2224,7 +2214,7 @@ export class BaileysStartupService extends ChannelStartupService {
22242214
this.configService.get<Chatwoot>('CHATWOOT').ENABLED &&
22252215
this.localChatwoot?.enabled &&
22262216
this.localChatwoot.importMessages &&
2227-
this.isSyncNotificationFromUsedSyncType(msg?.syncType)
2217+
this.isSyncNotificationFromUsedSyncType(msg)
22282218
) {
22292219
if (msg.chunkOrder === 1) {
22302220
this.chatwootService.startImportHistoryMessages(instance);
@@ -2240,12 +2230,10 @@ export class BaileysStartupService extends ChannelStartupService {
22402230
return true;
22412231
}
22422232

2243-
private isSyncNotificationFromUsedSyncType(
2244-
syncType?: proto.HistorySync.HistorySyncType | proto.Message.HistorySyncType,
2245-
) {
2233+
private isSyncNotificationFromUsedSyncType(msg: proto.Message.IHistorySyncNotification) {
22462234
return (
2247-
(this.localSettings.syncFullHistory && syncType === proto.HistorySync.HistorySyncType.FULL) ||
2248-
(!this.localSettings.syncFullHistory && syncType === proto.HistorySync.HistorySyncType.RECENT)
2235+
(this.localSettings.syncFullHistory && msg?.syncType === 2) ||
2236+
(!this.localSettings.syncFullHistory && msg?.syncType === 3)
22492237
);
22502238
}
22512239

0 commit comments

Comments
 (0)