diff options
author | Wim <wim@42.be> | 2022-08-13 16:14:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-13 16:14:26 +0200 |
commit | 6a3fc713978a0c1c9290a4afd08b47886b49b635 (patch) | |
tree | aa62cd85cf5671646c75ee38b3fc140ef7edcea8 /vendor/go.mau.fi/whatsmeow/user.go | |
parent | 3c4192ebf6a32e30cdd23a9644c2ceca72a006fa (diff) | |
download | matterbridge-msglm-6a3fc713978a0c1c9290a4afd08b47886b49b635.tar.gz matterbridge-msglm-6a3fc713978a0c1c9290a4afd08b47886b49b635.tar.bz2 matterbridge-msglm-6a3fc713978a0c1c9290a4afd08b47886b49b635.zip |
Update dependencies and go1.18 (#1873)
* Update dependencies and go1.18
* Exclude unnecessary linters and update build to go1.18
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/user.go')
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/user.go | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/user.go b/vendor/go.mau.fi/whatsmeow/user.go index eadb6d6e..454a7b37 100644 --- a/vendor/go.mau.fi/whatsmeow/user.go +++ b/vendor/go.mau.fi/whatsmeow/user.go @@ -7,6 +7,7 @@ package whatsmeow import ( + "context" "errors" "fmt" "strings" @@ -70,6 +71,23 @@ func (cli *Client) ResolveBusinessMessageLink(code string) (*types.BusinessMessa return &target, ag.Error() } +// SetStatusMessage updates the current user's status text, which is shown in the "About" section in the user profile. +// +// This is different from the ephemeral status broadcast messages. Use SendMessage to types.StatusBroadcastJID to send +// such messages. +func (cli *Client) SetStatusMessage(msg string) error { + _, err := cli.sendIQ(infoQuery{ + Namespace: "status", + Type: iqSet, + To: types.ServerJID, + Content: []waBinary.Node{{ + Tag: "status", + Content: msg, + }}, + }) + return err +} + // IsOnWhatsApp checks if the given phone numbers are registered on WhatsApp. // The phone numbers should be in international format, including the `+` prefix. func (cli *Client) IsOnWhatsApp(phones []string) ([]types.IsOnWhatsAppResponse, error) { @@ -77,7 +95,7 @@ func (cli *Client) IsOnWhatsApp(phones []string) ([]types.IsOnWhatsAppResponse, for i := range jids { jids[i] = types.NewJID(phones[i], types.LegacyUserServer) } - list, err := cli.usync(jids, "query", "interactive", []waBinary.Node{ + list, err := cli.usync(context.TODO(), jids, "query", "interactive", []waBinary.Node{ {Tag: "business", Content: []waBinary.Node{{Tag: "verified_name"}}}, {Tag: "contact"}, }) @@ -108,7 +126,7 @@ func (cli *Client) IsOnWhatsApp(phones []string) ([]types.IsOnWhatsAppResponse, // GetUserInfo gets basic user info (avatar, status, verified business name, device list). func (cli *Client) GetUserInfo(jids []types.JID) (map[types.JID]types.UserInfo, error) { - list, err := cli.usync(jids, "full", "background", []waBinary.Node{ + list, err := cli.usync(context.TODO(), jids, "full", "background", []waBinary.Node{ {Tag: "business", Content: []waBinary.Node{{Tag: "verified_name"}}}, {Tag: "status"}, {Tag: "picture"}, @@ -144,6 +162,10 @@ func (cli *Client) GetUserInfo(jids []types.JID) (map[types.JID]types.UserInfo, // regular JIDs, and the output will be a list of AD JIDs. The local device will not be included in // the output even if the user's JID is included in the input. All other devices will be included. func (cli *Client) GetUserDevices(jids []types.JID) ([]types.JID, error) { + return cli.GetUserDevicesContext(context.Background(), jids) +} + +func (cli *Client) GetUserDevicesContext(ctx context.Context, jids []types.JID) ([]types.JID, error) { cli.userDevicesCacheLock.Lock() defer cli.userDevicesCacheLock.Unlock() @@ -160,7 +182,7 @@ func (cli *Client) GetUserDevices(jids []types.JID) ([]types.JID, error) { return devices, nil } - list, err := cli.usync(jidsToSync, "query", "message", []waBinary.Node{ + list, err := cli.usync(ctx, jidsToSync, "query", "message", []waBinary.Node{ {Tag: "devices", Attrs: waBinary.Attrs{"version": "2"}}, }) if err != nil { @@ -181,8 +203,10 @@ func (cli *Client) GetUserDevices(jids []types.JID) ([]types.JID, error) { } // GetProfilePictureInfo gets the URL where you can download a WhatsApp user's profile picture or group's photo. -// If the user or group doesn't have a profile picture, this returns nil with no error. -func (cli *Client) GetProfilePictureInfo(jid types.JID, preview bool) (*types.ProfilePictureInfo, error) { +// +// Optionally, you can pass the last known profile picture ID. +// If the profile picture hasn't changed, this will return nil with no error. +func (cli *Client) GetProfilePictureInfo(jid types.JID, preview bool, existingID string) (*types.ProfilePictureInfo, error) { attrs := waBinary.Attrs{ "query": "url", } @@ -191,6 +215,9 @@ func (cli *Client) GetProfilePictureInfo(jid types.JID, preview bool) (*types.Pr } else { attrs["type"] = "image" } + if existingID != "" { + attrs["id"] = existingID + } resp, err := cli.sendIQ(infoQuery{ Namespace: "w:profile:picture", Type: "get", @@ -203,12 +230,15 @@ func (cli *Client) GetProfilePictureInfo(jid types.JID, preview bool) (*types.Pr if errors.Is(err, ErrIQNotAuthorized) { return nil, wrapIQError(ErrProfilePictureUnauthorized, err) } else if errors.Is(err, ErrIQNotFound) { - return nil, nil + return nil, wrapIQError(ErrProfilePictureNotSet, err) } else if err != nil { return nil, err } picture, ok := resp.GetOptionalChildByTag("picture") if !ok { + if existingID != "" { + return nil, nil + } return nil, &ElementMissingError{Tag: "picture", In: "response to profile picture query"} } var info types.ProfilePictureInfo @@ -302,7 +332,7 @@ func parseVerifiedNameContent(verifiedNameNode waBinary.Node) (*types.VerifiedNa if err != nil { return nil, err } - var certDetails waProto.VerifiedNameDetails + var certDetails waProto.VerifiedNameCertificate_Details err = proto.Unmarshal(cert.GetDetails(), &certDetails) if err != nil { return nil, err @@ -330,7 +360,7 @@ func parseDeviceList(user string, deviceNode waBinary.Node) []types.JID { return devices } -func (cli *Client) usync(jids []types.JID, mode, context string, query []waBinary.Node) (*waBinary.Node, error) { +func (cli *Client) usync(ctx context.Context, jids []types.JID, mode, context string, query []waBinary.Node) (*waBinary.Node, error) { userList := make([]waBinary.Node, len(jids)) for i, jid := range jids { userList[i].Tag = "user" @@ -350,6 +380,7 @@ func (cli *Client) usync(jids []types.JID, mode, context string, query []waBinar } } resp, err := cli.sendIQ(infoQuery{ + Context: ctx, Namespace: "usync", Type: "get", To: types.ServerJID, |