tulir / whatsmeow

Go library for the WhatsApp web multidevice API

Home Page:https://go.mau.fi/whatsmeow

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

App states regular_low and regular_high not syncing after archiving chat

MiguelArgentina opened this issue · comments

In our app we are trying to add the archive chat feature for every message we send.
The first time we archive the chat, it works, but after that, every other message sent fails archiving with the errors shown below.
This is a part of the function where the message is sent and archived:

        userJID := types.NewJID(phoneNumber, types.DefaultUserServer)
	message := &waProto.Message{
		Conversation: proto.String(messageContent),
	}
        ctx := context.Background()
	resp, err := client.SendMessage(ctx, userJID, message)
	chatID := resp.ID
	messageTimeStamp := resp.Timestamp
	lastMessageKey := &waProto.MessageKey{
		RemoteJid: proto.String(userJID.String()),
		FromMe:    proto.Bool(true),
		Id:        proto.String(chatID),
	}
	archiveChat := true

        archivePatch := appstate.BuildArchive(userJID, *proto.Bool(archiveChat), messageTimeStamp, lastMessageKey)
        err = client.SendAppState(archivePatch)

And these are the errors shown in the logs when client.SendAppState(archivePatch) is executed:

<?xml version="1.0"?>
<collection has_more_patches="true" name="regular_low" type="error">
  <error code="409" text="conflict"/>
  <patches>
    <patch><!-- 867 bytes --></patch>
    <patch><!-- 1175 bytes --></patch>
    <patch><!-- 1021 bytes --></patch>
    <patch><!-- 1313 bytes --></patch>
    <patch><!-- 1329 bytes --></patch>
    <patch><!-- 1021 bytes --></patch>
    <patch><!-- 1021 bytes --></patch>
    <patch><!-- 1021 bytes --></patch>
   ...
  </patches>
</collection>

I also tried resyncing the patches (before archiving) with:

        for _, name := range appstate.AllPatchNames {
		err := client.FetchAppState(name, true, false)
		if err != nil {
			client.Log.Errorf("Failed to do initial fetch of app state %s: %v", name, err)
		}
	}

but I get these two errors:

[Client ERROR] Failed to do initial fetch of app state regular_high: failed to decode app state regular_high patches: failed to verify patch v897: mismatching LTHash

and

[Client ERROR] Failed to do initial fetch of app state regular_low: failed to decode app state regular_low patches: failed to verify patch v712: mismatching LTHash

Does anyone have a tip on what this could be?
Maybe I should recalculate the LTHash? If this is the case, how can I do it?

I had the same issues @MiguelArgentina. After investigations, I think it has something to do with app_state_version in the db and app_state_version stored in other device. If one of them has flaw app_state_version, it will affect all devices with the same JID.

My quick fix was disconnecting all devices that connect to my WhatsApp and deleting the db.

I had the same issues @MiguelArgentina. After investigations, I think it has something to do with app_state_version in the db and app_state_version stored in other device. If one of them has flaw app_state_version, it will affect all devices with the same JID.

My quick fix was disconnecting all devices that connect to my WhatsApp and deleting the db.

Thanks a lot for sharing! I'll have this in mind. The thing is that we have close to 100 users, and deleting the DB would be something to avoid.

Any solution for this error?

I got a similar issue #651

Disconnecting the linked device and rescanning the QR code does not fix the issue, as the patches come from the main device.

It all started after I created a label using a linked WhatsApp Web device.

A created many labels before, but always using the main device. Problem only started after the label was created on the web version. In my case It's stuck on patch 563.

Have you disconnected all linked devices from the device?

No I hadn't tried that before. As there were other linked devices being used I didn't bother doing that.
But now I followed your suggestion: erased all linked devices and it seems the issue is gone.

Although it's just a quickfix, the bug still persists.

Thanks for the tip!

In fact, reconnecting resolves the lack of synchronization...

However, the problem persists and may return at any time.
We need to find the source of the error to fix the problem once and for all.