Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 18 additions & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions participant_hash_invalidation_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
})
}
}
14 changes: 1 addition & 13 deletions send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 1 addition & 11 deletions sendfb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading