diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c57bccf0..70470f658 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ All notable HyperMeow changes are documented here. HyperMeow uses commit pseudo- - Copy group-cache metadata under its lock before send-permission checks, including participant and admin slices, so notifications cannot race those reads. - Stop automatic reconnect and emit `CATRefreshError` to generic and connection-scoped observers when a 413/414 failure cannot refresh its token, including when `RefreshCAT` is unset. The missing callback returns `ErrCATRefreshUnavailable` instead of retrying unchanged credentials. - Protect the unified-session interval check during concurrent sends. +- Apply participant-hash device-cache invalidation to LID, hosted and bot recipients in both send paths. - Keep connection handler completion pending until an active handler exits, and process retired stream errors before automatic reconnect decisions. Manual disconnect retains its five-second wait bound. - Keep the newest pairing secret through bursts of rotation notifications and refresh the active QR code. - Report the destination in `SendFBMessage` responses and decrypt full bot edits using their target message ID. diff --git a/cache.go b/cache.go index ac470c070..29b160f5a 100644 --- a/cache.go +++ b/cache.go @@ -4,7 +4,24 @@ package whatsmeow -import "time" +import ( + "time" + + "github.com/polymorfa/hypermeow/types" +) + +func (cli *Client) invalidateParticipantHashCaches(to types.JID) { + switch to.Server { + case types.GroupServer: + cli.groupCacheLock.Lock() + delete(cli.groupCache, to) + cli.groupCacheLock.Unlock() + case types.DefaultUserServer, types.HiddenUserServer, types.BotServer, types.HostedServer, types.HostedLIDServer, types.MessengerServer: + cli.userDevicesCacheLock.Lock() + delete(cli.userDevicesCache, to) + cli.userDevicesCacheLock.Unlock() + } +} const ( maxGroupCacheEntries = 8 diff --git a/participant_hash_invalidation_test.go b/participant_hash_invalidation_test.go new file mode 100644 index 000000000..64457965e --- /dev/null +++ b/participant_hash_invalidation_test.go @@ -0,0 +1,36 @@ +package whatsmeow + +import ( + "testing" + + "github.com/polymorfa/hypermeow/types" +) + +func TestParticipantHashInvalidationCoversForkRecipientServers(t *testing.T) { + for _, server := range []string{ + types.DefaultUserServer, types.HiddenUserServer, types.BotServer, + types.HostedServer, types.HostedLIDServer, types.MessengerServer, types.GroupServer, + } { + t.Run(server, func(t *testing.T) { + cli, _, _ := newTestRemote(t) + target := types.NewJID("100000000000001", server) + other := types.NewJID("100000000000002", server) + cli.groupCache = map[types.JID]*groupMetaCache{target: {}, other: {}} + cli.userDevicesCache = map[types.JID]deviceCache{target: {}, other: {}} + cli.invalidateParticipantHashCaches(target) + if server == types.GroupServer { + if _, found := cli.groupCache[target]; found { + t.Fatal("participant hash mismatch retained the group route") + } + } else if _, found := cli.userDevicesCache[target]; found { + t.Fatal("participant hash mismatch retained the recipient device list") + } + if _, found := cli.groupCache[other]; !found { + t.Fatal("invalidation removed an unrelated group") + } + if _, found := cli.userDevicesCache[other]; !found { + t.Fatal("invalidation removed an unrelated recipient") + } + }) + } +} diff --git a/send.go b/send.go index c699c8400..5fb006be4 100644 --- a/send.go +++ b/send.go @@ -516,19 +516,7 @@ func (cli *Client) SendMessage(ctx context.Context, to types.JID, message *waE2E expectedPHash := ag.OptionalString("phash") if setParticipantHashMismatch(&resp, phash, expectedPHash) { cli.Log.Warnf("Server returned different participant list hash (%s != %s) when sending to %s. Some devices may not have received the message.", phash, expectedPHash, to) - switch to.Server { - case types.GroupServer: - // TODO also invalidate device list caches - cli.groupCacheLock.Lock() - delete(cli.groupCache, to) - cli.groupCacheLock.Unlock() - case types.BroadcastServer: - // TODO do something - case types.DefaultUserServer, types.HiddenUserServer, types.BotServer, types.HostedServer, types.HostedLIDServer: - cli.userDevicesCacheLock.Lock() - delete(cli.userDevicesCache, to) - cli.userDevicesCacheLock.Unlock() - } + cli.invalidateParticipantHashCaches(to) } return } diff --git a/sendfb.go b/sendfb.go index 06a92225d..d217f3843 100644 --- a/sendfb.go +++ b/sendfb.go @@ -209,17 +209,7 @@ func (cli *Client) SendFBMessage( expectedPHash := ag.OptionalString("phash") if setParticipantHashMismatch(&resp, phash, expectedPHash) { cli.Log.Warnf("Server returned different participant list hash when sending to %s. Some devices may not have received the message.", to) - switch to.Server { - case types.GroupServer: - // TODO also invalidate device list caches - cli.groupCacheLock.Lock() - delete(cli.groupCache, to) - cli.groupCacheLock.Unlock() - case types.DefaultUserServer, types.MessengerServer: - cli.userDevicesCacheLock.Lock() - delete(cli.userDevicesCache, to) - cli.userDevicesCacheLock.Unlock() - } + cli.invalidateParticipantHashCaches(to) } return }