Skip to content

Commit 36a2f65

Browse files
fix(history-sync): emit completion before contact upsert (#2510)
* fix(history-sync): emit completion before contact upsert * chore(ci): rerun checks on current head * fix(history-sync): include progress in completion event * style(chatwoot): fix lint violations * fix(history-sync): ignore non-primary completions * Revert "fix(history-sync): ignore non-primary completions" This reverts commit c0523d6. * chore: add ghcr publish workflow to branch
1 parent 27ce6e2 commit 36a2f65

2 files changed

Lines changed: 77 additions & 8 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build and Publish GHCR image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "v*"
9+
workflow_dispatch:
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository_owner }}/evolution-api
14+
15+
jobs:
16+
build-and-push:
17+
name: Build and Push GHCR
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
packages: write
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v5
26+
with:
27+
submodules: recursive
28+
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v3
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Log in to GHCR
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ${{ env.REGISTRY }}
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Extract metadata
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
47+
tags: |
48+
type=raw,value=latest,enable={{is_default_branch}}
49+
type=ref,event=branch
50+
type=ref,event=tag
51+
type=sha
52+
53+
- name: Build and push
54+
id: build-and-push
55+
uses: docker/build-push-action@v6
56+
with:
57+
context: .
58+
push: true
59+
platforms: linux/amd64,linux/arm64
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max
64+
65+
- name: Image digest
66+
run: echo ${{ steps.build-and-push.outputs.digest }}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,13 +1017,15 @@ export class BaileysStartupService extends ChannelStartupService {
10171017
syncType?: proto.HistorySync.HistorySyncType;
10181018
}) => {
10191019
try {
1020-
// Reset counters when a new sync starts (progress resets or decreases)
1021-
if (progress <= this.historySyncLastProgress) {
1020+
const normalizedProgress = progress ?? -1;
1021+
1022+
if (normalizedProgress <= this.historySyncLastProgress) {
10221023
this.historySyncMessageCount = 0;
10231024
this.historySyncChatCount = 0;
10241025
this.historySyncContactCount = 0;
10251026
}
1026-
this.historySyncLastProgress = progress ?? -1;
1027+
1028+
this.historySyncLastProgress = normalizedProgress;
10271029

10281030
if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) {
10291031
console.log('received on-demand history sync, messages=', messages);
@@ -1200,15 +1202,12 @@ export class BaileysStartupService extends ChannelStartupService {
12001202
const filteredContacts = contacts.filter((c) => !!c.notify || !!c.name);
12011203
this.historySyncContactCount += filteredContacts.length;
12021204

1203-
await this.contactHandle['contacts.upsert'](
1204-
filteredContacts.map((c) => ({ id: c.id, name: c.name ?? c.notify })),
1205-
);
1206-
1207-
if (progress === 100) {
1205+
if (normalizedProgress === 100) {
12081206
this.sendDataWebhook(Events.MESSAGING_HISTORY_SET, {
12091207
messageCount: this.historySyncMessageCount,
12101208
chatCount: this.historySyncChatCount,
12111209
contactCount: this.historySyncContactCount,
1210+
progress: normalizedProgress,
12121211
});
12131212

12141213
this.historySyncMessageCount = 0;
@@ -1217,6 +1216,10 @@ export class BaileysStartupService extends ChannelStartupService {
12171216
this.historySyncLastProgress = -1;
12181217
}
12191218

1219+
await this.contactHandle['contacts.upsert'](
1220+
filteredContacts.map((c) => ({ id: c.id, name: c.name ?? c.notify })),
1221+
);
1222+
12201223
contacts = undefined;
12211224
messages = undefined;
12221225
chats = undefined;

0 commit comments

Comments
 (0)