Skip to content

Commit

Permalink
events: include unavailable type in undecryptable messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Dec 2, 2024
1 parent ae900cb commit b2dd543
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ func (cli *Client) handlePlaintextMessage(info *types.MessageInfo, node *waBinar
}

func (cli *Client) decryptMessages(info *types.MessageInfo, node *waBinary.Node) {
if len(node.GetChildrenByTag("unavailable")) > 0 && len(node.GetChildrenByTag("enc")) == 0 {
cli.Log.Warnf("Unavailable message %s from %s", info.ID, info.SourceString())
unavailableNode, ok := node.GetOptionalChildByTag("unavailable")
if ok && len(node.GetChildrenByTag("enc")) == 0 {
uType := events.UnavailableType(unavailableNode.AttrGetter().String("type"))
cli.Log.Warnf("Unavailable message %s from %s (type: %q)", info.ID, info.SourceString(), uType)
go cli.delayedRequestMessageFromPhone(info)
cli.dispatchEvent(&events.UndecryptableMessage{Info: *info, IsUnavailable: true})
cli.dispatchEvent(&events.UndecryptableMessage{Info: *info, IsUnavailable: true, UnavailableType: uType})
return
}

Expand Down
9 changes: 9 additions & 0 deletions types/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ const (
DecryptFailHide DecryptFailMode = "hide"
)

type UnavailableType string

const (
UnavailableTypeUnknown UnavailableType = ""
UnavailableTypeViewOnce UnavailableType = "view_once"
)

// UndecryptableMessage is emitted when receiving a new message that failed to decrypt.
//
// The library will automatically ask the sender to retry. If the sender resends the message,
Expand All @@ -256,6 +263,8 @@ type UndecryptableMessage struct {
// IsUnavailable is true if the recipient device didn't send a ciphertext to this device at all
// (as opposed to sending a ciphertext, but the ciphertext not being decryptable).
IsUnavailable bool
// Some message types are intentionally unavailable. Such types usually have a type specified here.
UnavailableType UnavailableType

DecryptFailMode DecryptFailMode
}
Expand Down

0 comments on commit b2dd543

Please sign in to comment.