Skip to content

Commit

Permalink
Don't send statuses to own devices
Browse files Browse the repository at this point in the history
Otherwise the android app crashes
  • Loading branch information
tulir committed Feb 16, 2023
1 parent 6b12534 commit e1397b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 9 additions & 4 deletions broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ func (cli *Client) getBroadcastListParticipants(jid types.JID) ([]types.JID, err
return nil, ErrNotLoggedIn
}

var hasSelf bool
for _, participant := range list {
selfIndex := -1
for i, participant := range list {
if participant.User == ownID.User {
hasSelf = true
selfIndex = i
break
}
}
if !hasSelf {
if selfIndex >= 0 {
if cli.DontSendSelfBroadcast {
list[selfIndex] = list[len(list)-1]
list = list[:len(list)-1]
}
} else if !cli.DontSendSelfBroadcast {
list = append(list, ownID)
}
return list, nil
Expand Down
9 changes: 7 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ type Client struct {
// If false, decrypting a message from untrusted devices will fail.
AutoTrustIdentity bool

// Should sending to own devices be skipped when sending broadcasts?
// This works around a bug in the WhatsApp android app where it crashes if you send a status message from a linked device.
DontSendSelfBroadcast bool

// Should SubscribePresence return an error if no privacy token is stored for the user?
ErrorOnSubscribePresenceWithoutToken bool

Expand Down Expand Up @@ -186,8 +190,9 @@ func NewClient(deviceStore *store.Device, log waLog.Logger) *Client {
GetMessageForRetry: func(requester, to types.JID, id types.MessageID) *waProto.Message { return nil },
appStateKeyRequests: make(map[string]time.Time),

EnableAutoReconnect: true,
AutoTrustIdentity: true,
EnableAutoReconnect: true,
AutoTrustIdentity: true,
DontSendSelfBroadcast: true,
}
cli.nodeHandlers = map[string]nodeHandler{
"message": cli.handleEncryptedMessage,
Expand Down

0 comments on commit e1397b0

Please sign in to comment.