Skip to content

Commit

Permalink
update whatsmeow to 20241015 from tulir/whatsmeow@3fa42c3
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Oct 27, 2024
1 parent 615866b commit dbfcc3d
Show file tree
Hide file tree
Showing 53 changed files with 4,443 additions and 10,297 deletions.
2 changes: 1 addition & 1 deletion lib/common/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

#pragma once

#define NCHAT_VERSION "5.3.4"
#define NCHAT_VERSION "5.3.5"
19 changes: 16 additions & 3 deletions lib/wmchat/go/ext/whatsmeow/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@ repos:
hooks:
- id: trailing-whitespace
exclude_types: [markdown]
exclude: LICENSE|def.proto
exclude: LICENSE
- id: end-of-file-fixer
exclude: LICENSE|def.proto
exclude: LICENSE
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-imports-repo
args: ["-w"]
args:
- "-local"
- "go.mau.fi/whatsmeow"
- "-w"
- id: go-vet-repo-mod
# TODO enable this
#- id: go-staticcheck-repo-mod
- id: go-mod-tidy

- repo: https://github.com/beeper/pre-commit-go
rev: v0.3.1
hooks:
# TODO enable this
#- id: zerolog-ban-msgf
- id: zerolog-use-stringer
7 changes: 1 addition & 6 deletions lib/wmchat/go/ext/whatsmeow/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ func (cli *Client) getBroadcastListParticipants(jid types.JID) ([]types.JID, err
break
}
}
if selfIndex >= 0 {
if cli.DontSendSelfBroadcast {
list[selfIndex] = list[len(list)-1]
list = list[:len(list)-1]
}
} else if !cli.DontSendSelfBroadcast {
if selfIndex < 0 {
list = append(list, ownID)
}
return list, nil
Expand Down
21 changes: 11 additions & 10 deletions lib/wmchat/go/ext/whatsmeow/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"go.mau.fi/whatsmeow/appstate"
waBinary "go.mau.fi/whatsmeow/binary"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/proto/waE2E"
"go.mau.fi/whatsmeow/proto/waWeb"
"go.mau.fi/whatsmeow/socket"
"go.mau.fi/whatsmeow/store"
"go.mau.fi/whatsmeow/types"
Expand Down Expand Up @@ -147,10 +149,6 @@ 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 @@ -234,9 +232,8 @@ func NewClient(deviceStore *store.Device, log waLog.Logger) *Client {

pendingPhoneRerequests: make(map[types.MessageID]context.CancelFunc),

EnableAutoReconnect: true,
AutoTrustIdentity: true,
DontSendSelfBroadcast: true,
EnableAutoReconnect: true,
AutoTrustIdentity: true,
}
cli.nodeHandlers = map[string]nodeHandler{
"message": cli.handleEncryptedMessage,
Expand Down Expand Up @@ -775,10 +772,10 @@ func (cli *Client) dispatchEvent(evt interface{}) {
// evt, err := cli.ParseWebMessage(chatJID, historyMsg.GetMessage())
// yourNormalEventHandler(evt)
// }
func (cli *Client) ParseWebMessage(chatJID types.JID, webMsg *waProto.WebMessageInfo) (*events.Message, error) {
func (cli *Client) ParseWebMessage(chatJID types.JID, webMsg *waWeb.WebMessageInfo) (*events.Message, error) {
var err error
if chatJID.IsEmpty() {
chatJID, err = types.ParseJID(webMsg.GetKey().GetRemoteJid())
chatJID, err = types.ParseJID(webMsg.GetKey().GetRemoteJID())
if err != nil {
return nil, fmt.Errorf("no chat JID provided and failed to parse remote JID: %w", err)
}
Expand All @@ -789,7 +786,7 @@ func (cli *Client) ParseWebMessage(chatJID types.JID, webMsg *waProto.WebMessage
IsFromMe: webMsg.GetKey().GetFromMe(),
IsGroup: chatJID.Server == types.GroupServer,
},
ID: webMsg.GetKey().GetId(),
ID: webMsg.GetKey().GetID(),
PushName: webMsg.GetPushName(),
Timestamp: time.Unix(int64(webMsg.GetMessageTimestamp()), 0),
}
Expand All @@ -816,5 +813,9 @@ func (cli *Client) ParseWebMessage(chatJID types.JID, webMsg *waProto.WebMessage
Info: info,
}
evt.UnwrapRaw()
if evt.Message.GetProtocolMessage().GetType() == waE2E.ProtocolMessage_MESSAGE_EDIT {
evt.Info.ID = evt.Message.GetProtocolMessage().GetKey().GetID()
evt.Message = evt.Message.GetProtocolMessage().GetEditedMessage()
}
return evt, nil
}
8 changes: 4 additions & 4 deletions lib/wmchat/go/ext/whatsmeow/download-to-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ type File interface {
//
// This is otherwise identical to [Download], but writes the attachment to a file instead of returning it as a byte slice.
func (cli *Client) DownloadToFile(msg DownloadableMessage, file File) error {
mediaType, ok := classToMediaType[msg.ProtoReflect().Descriptor().Name()]
if !ok {
return fmt.Errorf("%w '%s'", ErrUnknownMediaType, string(msg.ProtoReflect().Descriptor().Name()))
mediaType := GetMediaType(msg)
if mediaType == "" {
return fmt.Errorf("%w %T", ErrUnknownMediaType, msg)
}
urlable, ok := msg.(downloadableMessageWithURL)
var url string
var isWebWhatsappNetURL bool
if ok {
url = urlable.GetUrl()
url = urlable.GetURL()
isWebWhatsappNetURL = strings.HasPrefix(url, "https://web.whatsapp.net")
}
if len(url) > 0 && !isWebWhatsappNetURL {
Expand Down
25 changes: 18 additions & 7 deletions lib/wmchat/go/ext/whatsmeow/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ const (
// All of the downloadable messages inside a Message struct implement this interface
// (ImageMessage, VideoMessage, AudioMessage, DocumentMessage, StickerMessage).
type DownloadableMessage interface {
proto.Message
GetDirectPath() string
GetMediaKey() []byte
GetFileSHA256() []byte
GetFileEncSHA256() []byte
}

type MediaTypeable interface {
GetMediaType() MediaType
}

// DownloadableThumbnail represents a protobuf message that contains a thumbnail attachment.
//
// This is primarily meant for link preview thumbnails in ExtendedTextMessage.
Expand Down Expand Up @@ -93,7 +96,7 @@ type downloadableMessageWithSizeBytes interface {

type downloadableMessageWithURL interface {
DownloadableMessage
GetUrl() string
GetURL() string
}

var classToMediaType = map[protoreflect.Name]MediaType{
Expand Down Expand Up @@ -175,7 +178,15 @@ func (cli *Client) DownloadThumbnail(msg DownloadableThumbnail) ([]byte, error)

// GetMediaType returns the MediaType value corresponding to the given protobuf message.
func GetMediaType(msg DownloadableMessage) MediaType {
return classToMediaType[msg.ProtoReflect().Descriptor().Name()]
protoReflecter, ok := msg.(proto.Message)
if !ok {
mediaTypeable, ok := msg.(MediaTypeable)
if !ok {
return ""
}
return mediaTypeable.GetMediaType()
}
return classToMediaType[protoReflecter.ProtoReflect().Descriptor().Name()]
}

// Download downloads the attachment from the given protobuf message.
Expand All @@ -188,15 +199,15 @@ func GetMediaType(msg DownloadableMessage) MediaType {
//
// You can also use DownloadAny to download the first non-nil sub-message.
func (cli *Client) Download(msg DownloadableMessage) ([]byte, error) {
mediaType, ok := classToMediaType[msg.ProtoReflect().Descriptor().Name()]
if !ok {
return nil, fmt.Errorf("%w '%s'", ErrUnknownMediaType, string(msg.ProtoReflect().Descriptor().Name()))
mediaType := GetMediaType(msg)
if mediaType == "" {
return nil, fmt.Errorf("%w %T", ErrUnknownMediaType, msg)
}
urlable, ok := msg.(downloadableMessageWithURL)
var url string
var isWebWhatsappNetURL bool
if ok {
url = urlable.GetUrl()
url = urlable.GetURL()
isWebWhatsappNetURL = strings.HasPrefix(url, "https://web.whatsapp.net")
}
if len(url) > 0 && !isWebWhatsappNetURL {
Expand Down
21 changes: 21 additions & 0 deletions lib/wmchat/go/ext/whatsmeow/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,25 @@ func (cli *Client) handleMexNotification(node *waBinary.Node) {
}
}

func (cli *Client) handleStatusNotification(node *waBinary.Node) {
ag := node.AttrGetter()
child, found := node.GetOptionalChildByTag("set")
if !found {
cli.Log.Debugf("Status notifcation did not contain child with tag 'set'")
return
}
status, ok := child.Content.([]byte)
if !ok {
cli.Log.Warnf("Set status notification has unexpected content (%T)", child.Content)
return
}
cli.dispatchEvent(&events.UserAbout{
JID: ag.JID("from"),
Timestamp: ag.UnixTime("t"),
Status: string(status),
})
}

func (cli *Client) handleNotification(node *waBinary.Node) {
ag := node.AttrGetter()
notifType := ag.String("type")
Expand Down Expand Up @@ -389,6 +408,8 @@ func (cli *Client) handleNotification(node *waBinary.Node) {
go cli.handleNewsletterNotification(node)
case "mex":
go cli.handleMexNotification(node)
case "status":
go cli.handleStatusNotification(node)
// Other types: business, disappearing_mode, server, status, pay, psa
default:
cli.Log.Debugf("Unhandled notification with type %s", notifType)
Expand Down
Loading

0 comments on commit dbfcc3d

Please sign in to comment.