summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2023-01-28 22:57:53 +0100
committerGitHub <noreply@github.com>2023-01-28 22:57:53 +0100
commit880586bac42817ffcfea5d9f746f503fa29915b8 (patch)
treea89374cba6f88975f12316ec8d1b8aa1d4c6ba79 /vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go
parenteac2a8c8dc831f946970d327e2a80b26b0684255 (diff)
downloadmatterbridge-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/sqlstore/store.go')
-rw-r--r--vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go41
1 files changed, 40 insertions, 1 deletions
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
+ }
+}