diff options
author | Wim <wim@42.be> | 2023-01-28 22:57:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-28 22:57:53 +0100 |
commit | 880586bac42817ffcfea5d9f746f503fa29915b8 (patch) | |
tree | a89374cba6f88975f12316ec8d1b8aa1d4c6ba79 /vendor/go.mau.fi/whatsmeow/store | |
parent | eac2a8c8dc831f946970d327e2a80b26b0684255 (diff) | |
download | matterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.tar.gz matterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.tar.bz2 matterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.zip |
Update dependencies (#1951)
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/store')
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/store/clientpayload.go | 2 | ||||
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go | 2 | ||||
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go | 41 | ||||
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go | 13 | ||||
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/store/store.go | 34 |
5 files changed, 78 insertions, 14 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/store/clientpayload.go b/vendor/go.mau.fi/whatsmeow/store/clientpayload.go index 6c683eed..08a3d280 100644 --- a/vendor/go.mau.fi/whatsmeow/store/clientpayload.go +++ b/vendor/go.mau.fi/whatsmeow/store/clientpayload.go @@ -74,7 +74,7 @@ func (vc WAVersionContainer) ProtoAppVersion() *waProto.ClientPayload_UserAgent_ } // waVersion is the WhatsApp web client version -var waVersion = WAVersionContainer{2, 2245, 9} +var waVersion = WAVersionContainer{2, 2301, 6} // waVersionHash is the md5 hash of a dot-separated waVersion var waVersionHash [16]byte diff --git a/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go b/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go index 136eda35..7f8c6c8f 100644 --- a/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go +++ b/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go @@ -126,6 +126,7 @@ func (c *Container) scanDevice(row scannable) (*store.Device, error) { device.Contacts = innerStore device.ChatSettings = innerStore device.MsgSecrets = innerStore + device.PrivacyTokens = innerStore device.Container = c device.Initialized = true @@ -240,6 +241,7 @@ func (c *Container) PutDevice(device *store.Device) error { device.Contacts = innerStore device.ChatSettings = innerStore device.MsgSecrets = innerStore + device.PrivacyTokens = innerStore device.Initialized = true } return err diff --git a/vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go b/vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go index 1261bec0..8221a4ad 100644 --- a/vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go +++ b/vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go @@ -706,7 +706,7 @@ func (s *SQLStore) PutMessageSecrets(inserts []store.MessageSecretInsert) (err e return fmt.Errorf("failed to begin transaction: %w", err) } for _, insert := range inserts { - _, err = s.db.Exec(putMsgSecret, s.JID, insert.Chat.ToNonAD(), insert.Sender.ToNonAD(), insert.ID, insert.Secret) + _, err = tx.Exec(putMsgSecret, s.JID, insert.Chat.ToNonAD(), insert.Sender.ToNonAD(), insert.ID, insert.Secret) } err = tx.Commit() if err != nil { @@ -727,3 +727,42 @@ func (s *SQLStore) GetMessageSecret(chat, sender types.JID, id types.MessageID) } return } + +const ( + putPrivacyTokens = ` + INSERT INTO whatsmeow_privacy_tokens (our_jid, their_jid, token, timestamp) + VALUES ($1, $2, $3, $4) + ON CONFLICT (our_jid, their_jid) DO UPDATE SET token=EXCLUDED.token, timestamp=EXCLUDED.timestamp + ` + getPrivacyToken = `SELECT token, timestamp FROM whatsmeow_privacy_tokens WHERE our_jid=$1 AND their_jid=$2` +) + +func (s *SQLStore) PutPrivacyTokens(tokens ...store.PrivacyToken) error { + args := make([]any, 1+len(tokens)*3) + placeholders := make([]string, len(tokens)) + args[0] = s.JID + for i, token := range tokens { + args[i*3+1] = token.User.ToNonAD().String() + args[i*3+2] = token.Token + args[i*3+3] = token.Timestamp.Unix() + placeholders[i] = fmt.Sprintf("($1, $%d, $%d, $%d)", i*3+2, i*3+3, i*3+4) + } + query := strings.ReplaceAll(putPrivacyTokens, "($1, $2, $3, $4)", strings.Join(placeholders, ",")) + _, err := s.db.Exec(query, args...) + return err +} + +func (s *SQLStore) GetPrivacyToken(user types.JID) (*store.PrivacyToken, error) { + var token store.PrivacyToken + token.User = user.ToNonAD() + var ts int64 + err := s.db.QueryRow(getPrivacyToken, s.JID, token.User).Scan(&token.Token, &ts) + if errors.Is(err, sql.ErrNoRows) { + return nil, nil + } else if err != nil { + return nil, err + } else { + token.Timestamp = time.Unix(ts, 0) + return &token, nil + } +} diff --git a/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go b/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go index 70556ec3..0919ca89 100644 --- a/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go +++ b/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go @@ -16,7 +16,7 @@ type upgradeFunc func(*sql.Tx, *Container) error // // This may be of use if you want to manage the database fully manually, but in most cases you // should just call Container.Upgrade to let the library handle everything. -var Upgrades = [...]upgradeFunc{upgradeV1, upgradeV2, upgradeV3} +var Upgrades = [...]upgradeFunc{upgradeV1, upgradeV2, upgradeV3, upgradeV4} func (c *Container) getVersion() (int, error) { _, err := c.db.Exec("CREATE TABLE IF NOT EXISTS whatsmeow_version (version INTEGER)") @@ -260,3 +260,14 @@ func upgradeV3(tx *sql.Tx, container *Container) error { )`) return err } + +func upgradeV4(tx *sql.Tx, container *Container) error { + _, err := tx.Exec(`CREATE TABLE whatsmeow_privacy_tokens ( + our_jid TEXT, + their_jid TEXT, + token bytea NOT NULL, + timestamp BIGINT NOT NULL, + PRIMARY KEY (our_jid, their_jid) + )`) + return err +} diff --git a/vendor/go.mau.fi/whatsmeow/store/store.go b/vendor/go.mau.fi/whatsmeow/store/store.go index b26a28b8..36a6dce9 100644 --- a/vendor/go.mau.fi/whatsmeow/store/store.go +++ b/vendor/go.mau.fi/whatsmeow/store/store.go @@ -112,6 +112,17 @@ type MsgSecretStore interface { GetMessageSecret(chat, sender types.JID, id types.MessageID) ([]byte, error) } +type PrivacyToken struct { + User types.JID + Token []byte + Timestamp time.Time +} + +type PrivacyTokenStore interface { + PutPrivacyTokens(tokens ...PrivacyToken) error + GetPrivacyToken(user types.JID) (*PrivacyToken, error) +} + type Device struct { Log waLog.Logger @@ -127,17 +138,18 @@ type Device struct { BusinessName string PushName string - Initialized bool - Identities IdentityStore - Sessions SessionStore - PreKeys PreKeyStore - SenderKeys SenderKeyStore - AppStateKeys AppStateSyncKeyStore - AppState AppStateStore - Contacts ContactStore - ChatSettings ChatSettingsStore - MsgSecrets MsgSecretStore - Container DeviceContainer + Initialized bool + Identities IdentityStore + Sessions SessionStore + PreKeys PreKeyStore + SenderKeys SenderKeyStore + AppStateKeys AppStateSyncKeyStore + AppState AppStateStore + Contacts ContactStore + ChatSettings ChatSettingsStore + MsgSecrets MsgSecretStore + PrivacyTokens PrivacyTokenStore + Container DeviceContainer DatabaseErrorHandler func(device *Device, action string, attemptIndex int, err error) (retry bool) } |