diff options
author | Wim <wim@42.be> | 2022-03-12 23:02:04 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2022-03-20 14:57:48 +0100 |
commit | aefa70891cfd489fccb8a9567b5bdafb0f863ede (patch) | |
tree | 90fe7c91d7b33b2a1ed08ea3a94840860adc6fc1 /vendor/go.mau.fi/whatsmeow/store/clientpayload.go | |
parent | 1b9877fda45be021ea6a5677c78648cecc19dcd5 (diff) | |
download | matterbridge-msglm-aefa70891cfd489fccb8a9567b5bdafb0f863ede.tar.gz matterbridge-msglm-aefa70891cfd489fccb8a9567b5bdafb0f863ede.tar.bz2 matterbridge-msglm-aefa70891cfd489fccb8a9567b5bdafb0f863ede.zip |
Update vendor (whatsapp)
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/store/clientpayload.go')
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/store/clientpayload.go | 96 |
1 files changed, 79 insertions, 17 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/store/clientpayload.go b/vendor/go.mau.fi/whatsmeow/store/clientpayload.go index 81519ee2..675719a2 100644 --- a/vendor/go.mau.fi/whatsmeow/store/clientpayload.go +++ b/vendor/go.mau.fi/whatsmeow/store/clientpayload.go @@ -20,36 +20,98 @@ import ( waProto "go.mau.fi/whatsmeow/binary/proto" ) +// WAVersionContainer is a container for a WhatsApp web version number. +type WAVersionContainer [3]uint32 + +// ParseVersion parses a version string (three dot-separated numbers) into a WAVersionContainer. +func ParseVersion(version string) (parsed WAVersionContainer, err error) { + var part1, part2, part3 int + if parts := strings.Split(version, "."); len(parts) != 3 { + err = fmt.Errorf("'%s' doesn't contain three dot-separated parts", version) + } else if part1, err = strconv.Atoi(parts[0]); err != nil { + err = fmt.Errorf("first part of '%s' is not a number: %w", version, err) + } else if part2, err = strconv.Atoi(parts[1]); err != nil { + err = fmt.Errorf("second part of '%s' is not a number: %w", version, err) + } else if part3, err = strconv.Atoi(parts[2]); err != nil { + err = fmt.Errorf("third part of '%s' is not a number: %w", version, err) + } else { + parsed = WAVersionContainer{uint32(part1), uint32(part2), uint32(part3)} + } + return +} + +func (vc WAVersionContainer) LessThan(other WAVersionContainer) bool { + return vc[0] < other[0] || + (vc[0] == other[0] && vc[1] < other[1]) || + (vc[0] == other[0] && vc[1] == other[1] && vc[2] < other[2]) +} + +// IsZero returns true if the version is zero. +func (vc WAVersionContainer) IsZero() bool { + return vc == [3]uint32{0, 0, 0} +} + +// String returns the version number as a dot-separated string. +func (vc WAVersionContainer) String() string { + parts := make([]string, len(vc)) + for i, part := range vc { + parts[i] = strconv.Itoa(int(part)) + } + return strings.Join(parts, ".") +} + +// Hash returns the md5 hash of the String representation of this version. +func (vc WAVersionContainer) Hash() [16]byte { + return md5.Sum([]byte(vc.String())) +} + +func (vc WAVersionContainer) ProtoAppVersion() *waProto.AppVersion { + return &waProto.AppVersion{ + Primary: &vc[0], + Secondary: &vc[1], + Tertiary: &vc[2], + } +} + // waVersion is the WhatsApp web client version -var waVersion = []uint32{2, 2202, 9} +var waVersion = WAVersionContainer{2, 2208, 7} // waVersionHash is the md5 hash of a dot-separated waVersion var waVersionHash [16]byte func init() { - waVersionParts := make([]string, len(waVersion)) - for i, part := range waVersion { - waVersionParts[i] = strconv.Itoa(int(part)) + waVersionHash = waVersion.Hash() +} + +// GetWAVersion gets the current WhatsApp web client version. +func GetWAVersion() WAVersionContainer { + return waVersion +} + +// SetWAVersion sets the current WhatsApp web client version. +// +// In general, you should keep the library up-to-date instead of using this, +// as there may be code changes that are necessary too (like protobuf schema changes). +func SetWAVersion(version WAVersionContainer) { + if version.IsZero() { + return } - waVersionString := strings.Join(waVersionParts, ".") - waVersionHash = md5.Sum([]byte(waVersionString)) + waVersion = version + waVersionHash = version.Hash() } var BaseClientPayload = &waProto.ClientPayload{ UserAgent: &waProto.UserAgent{ Platform: waProto.UserAgent_WEB.Enum(), ReleaseChannel: waProto.UserAgent_RELEASE.Enum(), - AppVersion: &waProto.AppVersion{ - Primary: &waVersion[0], - Secondary: &waVersion[1], - Tertiary: &waVersion[2], - }, - Mcc: proto.String("000"), - Mnc: proto.String("000"), - OsVersion: proto.String("0.1.0"), - Manufacturer: proto.String(""), - Device: proto.String("Desktop"), - OsBuildNumber: proto.String("0.1.0"), + AppVersion: waVersion.ProtoAppVersion(), + Mcc: proto.String("000"), + Mnc: proto.String("000"), + OsVersion: proto.String("0.1.0"), + Manufacturer: proto.String(""), + Device: proto.String("Desktop"), + OsBuildNumber: proto.String("0.1.0"), + LocaleLanguageIso6391: proto.String("en"), LocaleCountryIso31661Alpha2: proto.String("en"), }, |