Skip to content

Commit

Permalink
update whatsmeow to 20241121 from tulir/whatsmeow@ae900cb
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Dec 1, 2024
1 parent 5bf891e commit c99e57b
Show file tree
Hide file tree
Showing 70 changed files with 2,932 additions and 1,606 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.4.1"
#define NCHAT_VERSION "5.4.2"
7 changes: 7 additions & 0 deletions lib/wmchat/go/ext/whatsmeow/.github/ISSUE_TEMPLATE/issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ name: Open issue
about: For bug reports and feature requests directly related to whatsmeow

---

<!--
Do not open issues for questions!
Issues are only for bug reports and feature requests.
Questions belong in the Matrix room or on GitHub Discussions.
-->
14 changes: 7 additions & 7 deletions lib/wmchat/go/ext/whatsmeow/.github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ name: Go

on: [push, pull_request]

env:
GOTOOLCHAIN: local

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version: ["1.21", "1.22"]
name: Build ${{ matrix.go-version == '1.22' && '(latest)' || '(old)' }}
go-version: ["1.22", "1.23"]
name: Build ${{ matrix.go-version == '1.23' && '(latest)' || '(old)' }}

steps:
- uses: actions/checkout@v4
Expand All @@ -30,8 +33,5 @@ jobs:
go install golang.org/x/tools/cmd/goimports@latest
export PATH="$HOME/go/bin:$PATH"
- name: Install pre-commit
run: pip install pre-commit

- name: Lint
run: pre-commit run -a
- name: Run pre-commit
uses: pre-commit/[email protected]
2 changes: 1 addition & 1 deletion lib/wmchat/go/ext/whatsmeow/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude_types: [markdown]
Expand Down
6 changes: 6 additions & 0 deletions lib/wmchat/go/ext/whatsmeow/appstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
// FetchAppState fetches updates to the given type of app state. If fullSync is true, the current
// cached state will be removed and all app state patches will be re-fetched from the server.
func (cli *Client) FetchAppState(name appstate.WAPatchName, fullSync, onlyIfNotSynced bool) error {
if cli == nil {
return ErrClientIsNil
}
cli.appStateSyncLock.Lock()
defer cli.appStateSyncLock.Unlock()
if fullSync {
Expand Down Expand Up @@ -347,6 +350,9 @@ func (cli *Client) requestAppStateKeys(ctx context.Context, rawKeyIDs [][]byte)
//
// cli.SendAppState(appstate.BuildMute(targetJID, true, 24 * time.Hour))
func (cli *Client) SendAppState(patch appstate.PatchInfo) error {
if cli == nil {
return ErrClientIsNil
}
version, hash, err := cli.Store.AppState.GetAppStateVersion(string(patch.Type))
if err != nil {
return err
Expand Down
49 changes: 38 additions & 11 deletions lib/wmchat/go/ext/whatsmeow/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Client struct {
socket *socket.NoiseSocket
socketLock sync.RWMutex
socketWait chan struct{}
wsDialer *websocket.Dialer

isLoggedIn atomic.Bool
expectedDisconnect atomic.Bool
Expand Down Expand Up @@ -172,8 +173,9 @@ type Client struct {
}

type MessengerConfig struct {
UserAgent string
BaseURL string
UserAgent string
BaseURL string
WebsocketURL string
}

// Size of buffer for the channel that all incoming XML nodes go through.
Expand Down Expand Up @@ -371,6 +373,9 @@ func (cli *Client) closeSocketWaitChan() {
}

func (cli *Client) getOwnID() types.JID {
if cli == nil {
return types.EmptyJID
}
id := cli.Store.ID
if id == nil {
return types.EmptyJID
Expand All @@ -379,6 +384,9 @@ func (cli *Client) getOwnID() types.JID {
}

func (cli *Client) WaitForConnection(timeout time.Duration) bool {
if cli == nil {
return false
}
timeoutChan := time.After(timeout)
cli.socketLock.RLock()
for cli.socket == nil || !cli.socket.IsConnected() || !cli.IsLoggedIn() {
Expand All @@ -395,9 +403,16 @@ func (cli *Client) WaitForConnection(timeout time.Duration) bool {
return true
}

func (cli *Client) SetWSDialer(dialer *websocket.Dialer) {
cli.wsDialer = dialer
}

// Connect connects the client to the WhatsApp web websocket. After connection, it will either
// authenticate if there's data in the device store, or emit a QREvent to set up a new link.
func (cli *Client) Connect() error {
if cli == nil {
return ErrClientIsNil
}
cli.socketLock.Lock()
defer cli.socketLock.Unlock()
if cli.socket != nil {
Expand All @@ -409,8 +424,10 @@ func (cli *Client) Connect() error {
}

cli.resetExpectedDisconnect()
wsDialer := websocket.Dialer{}
if !cli.proxyOnlyLogin || cli.Store.ID == nil {
var wsDialer websocket.Dialer
if cli.wsDialer != nil {
wsDialer = *cli.wsDialer
} else if !cli.proxyOnlyLogin || cli.Store.ID == nil {
if cli.proxy != nil {
wsDialer.Proxy = cli.proxy
} else if cli.socksProxy != nil {
Expand All @@ -423,12 +440,14 @@ func (cli *Client) Connect() error {
}
fs := socket.NewFrameSocket(cli.Log.Sub("Socket"), wsDialer)
if cli.MessengerConfig != nil {
fs.URL = "wss://web-chat-e2ee.facebook.com/ws/chat"
fs.URL = cli.MessengerConfig.WebsocketURL
fs.HTTPHeaders.Set("Origin", cli.MessengerConfig.BaseURL)
fs.HTTPHeaders.Set("User-Agent", cli.MessengerConfig.UserAgent)
fs.HTTPHeaders.Set("Sec-Fetch-Dest", "empty")
fs.HTTPHeaders.Set("Sec-Fetch-Mode", "websocket")
fs.HTTPHeaders.Set("Sec-Fetch-Site", "cross-site")
fs.HTTPHeaders.Set("Cache-Control", "no-cache")
fs.HTTPHeaders.Set("Pragma", "no-cache")
//fs.HTTPHeaders.Set("Sec-Fetch-Dest", "empty")
//fs.HTTPHeaders.Set("Sec-Fetch-Mode", "websocket")
//fs.HTTPHeaders.Set("Sec-Fetch-Site", "cross-site")
}
if err := fs.Connect(); err != nil {
fs.Close(0)
Expand All @@ -444,7 +463,7 @@ func (cli *Client) Connect() error {

// IsLoggedIn returns true after the client is successfully connected and authenticated on WhatsApp.
func (cli *Client) IsLoggedIn() bool {
return cli.isLoggedIn.Load()
return cli != nil && cli.isLoggedIn.Load()
}

func (cli *Client) onDisconnect(ns *socket.NoiseSocket, remote bool) {
Expand Down Expand Up @@ -508,6 +527,9 @@ func (cli *Client) autoReconnect() {
// IsConnected checks if the client is connected to the WhatsApp web websocket.
// Note that this doesn't check if the client is authenticated. See the IsLoggedIn field for that.
func (cli *Client) IsConnected() bool {
if cli == nil {
return false
}
cli.socketLock.RLock()
connected := cli.socket != nil && cli.socket.IsConnected()
cli.socketLock.RUnlock()
Expand All @@ -519,7 +541,7 @@ func (cli *Client) IsConnected() bool {
// This will not emit any events, the Disconnected event is only used when the
// connection is closed by the server or a network error.
func (cli *Client) Disconnect() {
if cli.socket == nil {
if cli == nil || cli.socket == nil {
return
}
cli.socketLock.Lock()
Expand All @@ -544,7 +566,9 @@ func (cli *Client) unlockedDisconnect() {
// Note that this will not emit any events. The LoggedOut event is only used for external logouts
// (triggered by the user from the main device or by WhatsApp servers).
func (cli *Client) Logout() error {
if cli.MessengerConfig != nil {
if cli == nil {
return ErrClientIsNil
} else if cli.MessengerConfig != nil {
return errors.New("can't logout with Messenger credentials")
}
ownID := cli.getOwnID()
Expand Down Expand Up @@ -728,6 +752,9 @@ func (cli *Client) handlerQueueLoop(ctx context.Context) {
}

func (cli *Client) sendNodeAndGetData(node waBinary.Node) ([]byte, error) {
if cli == nil {
return nil, ErrClientIsNil
}
cli.socketLock.RLock()
sock := cli.socket
cli.socketLock.RUnlock()
Expand Down
4 changes: 2 additions & 2 deletions lib/wmchat/go/ext/whatsmeow/download-to-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func (cli *Client) DownloadMediaWithPathToFile(directPath string, encFileHash, f
// TODO omit hash for unencrypted media?
mediaURL := fmt.Sprintf("https://%s%s&hash=%s&mms-type=%s&__wa-mms=", host.Hostname, directPath, base64.URLEncoding.EncodeToString(encFileHash), mmsType)
err = cli.downloadAndDecryptToFile(mediaURL, mediaKey, mediaType, fileLength, encFileHash, fileHash, file)
if err == nil || errors.Is(err, ErrFileLengthMismatch) || errors.Is(err, ErrInvalidMediaSHA256) {
if err == nil || errors.Is(err, ErrFileLengthMismatch) || errors.Is(err, ErrInvalidMediaSHA256) ||
errors.Is(err, ErrMediaDownloadFailedWith403) || errors.Is(err, ErrMediaDownloadFailedWith404) || errors.Is(err, ErrMediaDownloadFailedWith410) {
return err
} else if i >= len(mediaConn.Hosts)-1 {
return fmt.Errorf("failed to download media from last host: %w", err)
}
// TODO there are probably some errors that shouldn't retry
cli.Log.Warnf("Failed to download media: %s, trying with next host...", err)
}
return err
Expand Down
4 changes: 2 additions & 2 deletions lib/wmchat/go/ext/whatsmeow/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ func (cli *Client) DownloadMediaWithPath(directPath string, encFileHash, fileHas
// TODO omit hash for unencrypted media?
mediaURL := fmt.Sprintf("https://%s%s&hash=%s&mms-type=%s&__wa-mms=", host.Hostname, directPath, base64.URLEncoding.EncodeToString(encFileHash), mmsType)
data, err = cli.downloadAndDecrypt(mediaURL, mediaKey, mediaType, fileLength, encFileHash, fileHash)
if err == nil || errors.Is(err, ErrFileLengthMismatch) || errors.Is(err, ErrInvalidMediaSHA256) {
if err == nil || errors.Is(err, ErrFileLengthMismatch) || errors.Is(err, ErrInvalidMediaSHA256) ||
errors.Is(err, ErrMediaDownloadFailedWith403) || errors.Is(err, ErrMediaDownloadFailedWith404) || errors.Is(err, ErrMediaDownloadFailedWith410) {
return
} else if i >= len(mediaConn.Hosts)-1 {
return nil, fmt.Errorf("failed to download media from last host: %w", err)
}
// TODO there are probably some errors that shouldn't retry
cli.Log.Warnf("Failed to download media: %s, trying with next host...", err)
}
return
Expand Down
2 changes: 2 additions & 0 deletions lib/wmchat/go/ext/whatsmeow/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

// Miscellaneous errors
var (
ErrClientIsNil = errors.New("client is nil")
ErrNoSession = errors.New("can't encrypt message for device: no signal session established")
ErrIQTimedOut = errors.New("info query timed out")
ErrNotConnected = errors.New("websocket not connected")
Expand Down Expand Up @@ -183,6 +184,7 @@ var (
ErrIQGone error = &IQError{Code: 410, Text: "gone"}
ErrIQResourceLimit error = &IQError{Code: 419, Text: "resource-limit"}
ErrIQLocked error = &IQError{Code: 423, Text: "locked"}
ErrIQRateOverLimit error = &IQError{Code: 429, Text: "rate-overlimit"}
ErrIQInternalServerError error = &IQError{Code: 500, Text: "internal-server-error"}
ErrIQServiceUnavailable error = &IQError{Code: 503, Text: "service-unavailable"}
ErrIQPartialServerError error = &IQError{Code: 530, Text: "partial-server-error"}
Expand Down
12 changes: 6 additions & 6 deletions lib/wmchat/go/ext/whatsmeow/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ module go.mau.fi/whatsmeow

go 1.22.0

toolchain go1.23.1
toolchain go1.23.3

require (
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.0
github.com/rs/zerolog v1.33.0
go.mau.fi/libsignal v0.1.1
go.mau.fi/util v0.8.0
golang.org/x/crypto v0.27.0
golang.org/x/net v0.29.0
google.golang.org/protobuf v1.34.2
go.mau.fi/util v0.8.2
golang.org/x/crypto v0.29.0
golang.org/x/net v0.31.0
google.golang.org/protobuf v1.35.2
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/sys v0.27.0 // indirect
)
20 changes: 10 additions & 10 deletions lib/wmchat/go/ext/whatsmeow/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.mau.fi/libsignal v0.1.1 h1:m/0PGBh4QKP/I1MQ44ti4C0fMbLMuHb95cmDw01FIpI=
go.mau.fi/libsignal v0.1.1/go.mod h1:QLs89F/OA3ThdSL2Wz2p+o+fi8uuQUz0e1BRa6ExdBw=
go.mau.fi/util v0.8.0 h1:MiSny8jgQq4XtCLAT64gDJhZVhqiDeMVIEBDFVw+M0g=
go.mau.fi/util v0.8.0/go.mod h1:1Ixb8HWoVbl3rT6nAX6nV4iMkzn7KU/KXwE0Rn5RmsQ=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
go.mau.fi/util v0.8.2 h1:zWbVHwdRKwI6U9AusmZ8bwgcLosikwbb4GGqLrNr1YE=
go.mau.fi/util v0.8.2/go.mod h1:BHHC9R2WLMJd1bwTZfTcFxUgRFmUgUmiWcT4RbzUgiA=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 3 additions & 0 deletions lib/wmchat/go/ext/whatsmeow/mediaconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (mc *MediaConn) Expiry() time.Time {
}

func (cli *Client) refreshMediaConn(force bool) (*MediaConn, error) {
if cli == nil {
return nil, ErrClientIsNil
}
cli.mediaConnLock.Lock()
defer cli.mediaConnLock.Unlock()
if cli.mediaConnCache == nil || force || time.Now().After(cli.mediaConnCache.Expiry()) {
Expand Down
6 changes: 6 additions & 0 deletions lib/wmchat/go/ext/whatsmeow/msgsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ type messageEncryptedSecret interface {
}

func (cli *Client) decryptMsgSecret(msg *events.Message, useCase MsgSecretType, encrypted messageEncryptedSecret, origMsgKey *waCommon.MessageKey) ([]byte, error) {
if cli == nil {
return nil, ErrClientIsNil
}
pollSender, err := getOrigSenderFromKey(msg, origMsgKey)
if err != nil {
return nil, err
Expand All @@ -102,6 +105,9 @@ func (cli *Client) decryptMsgSecret(msg *events.Message, useCase MsgSecretType,
}

func (cli *Client) encryptMsgSecret(chat, origSender types.JID, origMsgID types.MessageID, useCase MsgSecretType, plaintext []byte) (ciphertext, iv []byte, err error) {
if cli == nil {
return nil, nil, ErrClientIsNil
}
ownID := cli.getOwnID()
if ownID.IsEmpty() {
return nil, nil, ErrNotLoggedIn
Expand Down
3 changes: 3 additions & 0 deletions lib/wmchat/go/ext/whatsmeow/newsletter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (cli *Client) NewsletterSubscribeLiveUpdates(ctx context.Context, jid types
//
// This is not the same as marking the channel as read on your other devices, use the usual MarkRead function for that.
func (cli *Client) NewsletterMarkViewed(jid types.JID, serverIDs []types.MessageServerID) error {
if cli == nil {
return ErrClientIsNil
}
items := make([]waBinary.Node, len(serverIDs))
for i, id := range serverIDs {
items[i] = waBinary.Node{
Expand Down
3 changes: 3 additions & 0 deletions lib/wmchat/go/ext/whatsmeow/pair-code.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func generateCompanionEphemeralKey() (ephemeralKeyPair *keys.KeyPair, ephemeralK
//
// See https://faq.whatsapp.com/1324084875126592 for more info
func (cli *Client) PairPhone(phone string, showPushNotification bool, clientType PairClientType, clientDisplayName string) (string, error) {
if cli == nil {
return "", ErrClientIsNil
}
ephemeralKeyPair, ephemeralKey, encodedLinkingCode := generateCompanionEphemeralKey()
phone = notNumbers.ReplaceAllString(phone, "")
if len(phone) <= 6 {
Expand Down
2 changes: 1 addition & 1 deletion lib/wmchat/go/ext/whatsmeow/privacysettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (cli *Client) TryFetchPrivacySettings(ignoreCache bool) (*types.PrivacySett
// GetPrivacySettings will get the user's privacy settings. If an error occurs while fetching them, the error will be
// logged, but the method will just return an empty struct.
func (cli *Client) GetPrivacySettings() (settings types.PrivacySettings) {
if cli.MessengerConfig != nil {
if cli == nil || cli.MessengerConfig != nil {
return
}
settingsPtr, err := cli.TryFetchPrivacySettings(false)
Expand Down
2 changes: 1 addition & 1 deletion lib/wmchat/go/ext/whatsmeow/proto/waAdv/WAAdv.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c99e57b

Please sign in to comment.