From b2dd543e5721b40a2dd32d5cd5c6c696e6970442 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 2 Dec 2024 19:34:57 +0200 Subject: [PATCH] events: include unavailable type in undecryptable messages --- message.go | 8 +++++--- types/events/events.go | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/message.go b/message.go index 5aef10e8..9a760b91 100644 --- a/message.go +++ b/message.go @@ -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 } diff --git a/types/events/events.go b/types/events/events.go index a5a3bf89..cc5db968 100644 --- a/types/events/events.go +++ b/types/events/events.go @@ -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, @@ -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 }