forked from lug/matterbridge
Update dependencies and build to go1.22 (#2113)
* Update dependencies and build to go1.22 * Fix api changes wrt to dependencies * Update golangci config
This commit is contained in:
88
vendor/go.mau.fi/whatsmeow/privacysettings.go
vendored
88
vendor/go.mau.fi/whatsmeow/privacysettings.go
vendored
@@ -7,6 +7,9 @@
|
||||
package whatsmeow
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
waBinary "go.mau.fi/whatsmeow/binary"
|
||||
"go.mau.fi/whatsmeow/types"
|
||||
"go.mau.fi/whatsmeow/types/events"
|
||||
@@ -39,6 +42,9 @@ 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 {
|
||||
return
|
||||
}
|
||||
settingsPtr, err := cli.TryFetchPrivacySettings(false)
|
||||
if err != nil {
|
||||
cli.Log.Errorf("Failed to fetch privacy settings: %v", err)
|
||||
@@ -48,6 +54,69 @@ func (cli *Client) GetPrivacySettings() (settings types.PrivacySettings) {
|
||||
return
|
||||
}
|
||||
|
||||
// SetPrivacySetting will set the given privacy setting to the given value.
|
||||
// The privacy settings will be fetched from the server after the change and the new settings will be returned.
|
||||
// If an error occurs while fetching the new settings, will return an empty struct.
|
||||
func (cli *Client) SetPrivacySetting(name types.PrivacySettingType, value types.PrivacySetting) (settings types.PrivacySettings, err error) {
|
||||
settingsPtr, err := cli.TryFetchPrivacySettings(false)
|
||||
if err != nil {
|
||||
return settings, err
|
||||
}
|
||||
_, err = cli.sendIQ(infoQuery{
|
||||
Namespace: "privacy",
|
||||
Type: iqSet,
|
||||
To: types.ServerJID,
|
||||
Content: []waBinary.Node{{
|
||||
Tag: "privacy",
|
||||
Content: []waBinary.Node{{
|
||||
Tag: "category",
|
||||
Attrs: waBinary.Attrs{
|
||||
"name": string(name),
|
||||
"value": string(value),
|
||||
},
|
||||
}},
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
return settings, err
|
||||
}
|
||||
settings = *settingsPtr
|
||||
switch name {
|
||||
case types.PrivacySettingTypeGroupAdd:
|
||||
settings.GroupAdd = value
|
||||
case types.PrivacySettingTypeLastSeen:
|
||||
settings.LastSeen = value
|
||||
case types.PrivacySettingTypeStatus:
|
||||
settings.Status = value
|
||||
case types.PrivacySettingTypeProfile:
|
||||
settings.Profile = value
|
||||
case types.PrivacySettingTypeReadReceipts:
|
||||
settings.ReadReceipts = value
|
||||
case types.PrivacySettingTypeOnline:
|
||||
settings.Online = value
|
||||
case types.PrivacySettingTypeCallAdd:
|
||||
settings.CallAdd = value
|
||||
}
|
||||
cli.privacySettingsCache.Store(&settings)
|
||||
return
|
||||
}
|
||||
|
||||
// SetDefaultDisappearingTimer will set the default disappearing message timer.
|
||||
func (cli *Client) SetDefaultDisappearingTimer(timer time.Duration) (err error) {
|
||||
_, err = cli.sendIQ(infoQuery{
|
||||
Namespace: "disappearing_mode",
|
||||
Type: iqSet,
|
||||
To: types.ServerJID,
|
||||
Content: []waBinary.Node{{
|
||||
Tag: "disappearing_mode",
|
||||
Attrs: waBinary.Attrs{
|
||||
"duration": strconv.Itoa(int(timer.Seconds())),
|
||||
},
|
||||
}},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (cli *Client) parsePrivacySettings(privacyNode *waBinary.Node, settings *types.PrivacySettings) *events.PrivacySettings {
|
||||
var evt events.PrivacySettings
|
||||
for _, child := range privacyNode.GetChildren() {
|
||||
@@ -55,24 +124,30 @@ func (cli *Client) parsePrivacySettings(privacyNode *waBinary.Node, settings *ty
|
||||
continue
|
||||
}
|
||||
ag := child.AttrGetter()
|
||||
name := ag.String("name")
|
||||
name := types.PrivacySettingType(ag.String("name"))
|
||||
value := types.PrivacySetting(ag.String("value"))
|
||||
switch name {
|
||||
case "groupadd":
|
||||
case types.PrivacySettingTypeGroupAdd:
|
||||
settings.GroupAdd = value
|
||||
evt.GroupAddChanged = true
|
||||
case "last":
|
||||
case types.PrivacySettingTypeLastSeen:
|
||||
settings.LastSeen = value
|
||||
evt.LastSeenChanged = true
|
||||
case "status":
|
||||
case types.PrivacySettingTypeStatus:
|
||||
settings.Status = value
|
||||
evt.StatusChanged = true
|
||||
case "profile":
|
||||
case types.PrivacySettingTypeProfile:
|
||||
settings.Profile = value
|
||||
evt.ProfileChanged = true
|
||||
case "readreceipts":
|
||||
case types.PrivacySettingTypeReadReceipts:
|
||||
settings.ReadReceipts = value
|
||||
evt.ReadReceiptsChanged = true
|
||||
case types.PrivacySettingTypeOnline:
|
||||
settings.Online = value
|
||||
evt.OnlineChanged = true
|
||||
case types.PrivacySettingTypeCallAdd:
|
||||
settings.CallAdd = value
|
||||
evt.CallAddChanged = true
|
||||
}
|
||||
}
|
||||
return &evt
|
||||
@@ -83,6 +158,7 @@ func (cli *Client) handlePrivacySettingsNotification(privacyNode *waBinary.Node)
|
||||
settings, err := cli.TryFetchPrivacySettings(false)
|
||||
if err != nil {
|
||||
cli.Log.Errorf("Failed to fetch privacy settings when handling change: %v", err)
|
||||
return
|
||||
}
|
||||
evt := cli.parsePrivacySettings(privacyNode, settings)
|
||||
// The data isn't be reliable if the fetch failed, so only cache if it didn't fail
|
||||
|
||||
Reference in New Issue
Block a user