summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/whatsmeow/store/sqlstore
diff options
context:
space:
mode:
authorWim <wim@42.be>2022-11-27 00:42:16 +0100
committerGitHub <noreply@github.com>2022-11-27 00:42:16 +0100
commit4fd0a7672777f0ed15692ae2ba47838208537558 (patch)
treeb119834a8b9ee78aa8f1b2ad05efa7da50516cbf /vendor/go.mau.fi/whatsmeow/store/sqlstore
parent6da9d567dc9195e9a5211f23a6795a41f56a1bfc (diff)
downloadmatterbridge-msglm-4fd0a7672777f0ed15692ae2ba47838208537558.tar.gz
matterbridge-msglm-4fd0a7672777f0ed15692ae2ba47838208537558.tar.bz2
matterbridge-msglm-4fd0a7672777f0ed15692ae2ba47838208537558.zip
Update dependencies (#1929)
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/store/sqlstore')
-rw-r--r--vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go16
-rw-r--r--vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go42
-rw-r--r--vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go16
3 files changed, 66 insertions, 8 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go b/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go
index 8a26fc53..136eda35 100644
--- a/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go
+++ b/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go
@@ -38,7 +38,8 @@ var _ store.DeviceContainer = (*Container)(nil)
// The logger can be nil and will default to a no-op logger.
//
// When using SQLite, it's strongly recommended to enable foreign keys by adding `?_foreign_keys=true`:
-// container, err := sqlstore.New("sqlite3", "file:yoursqlitefile.db?_foreign_keys=on", nil)
+//
+// container, err := sqlstore.New("sqlite3", "file:yoursqlitefile.db?_foreign_keys=on", nil)
func New(dialect, address string, log waLog.Logger) (*Container, error) {
db, err := sql.Open(dialect, address)
if err != nil {
@@ -59,11 +60,12 @@ func New(dialect, address string, log waLog.Logger) (*Container, error) {
// The logger can be nil and will default to a no-op logger.
//
// When using SQLite, it's strongly recommended to enable foreign keys by adding `?_foreign_keys=true`:
-// db, err := sql.Open("sqlite3", "file:yoursqlitefile.db?_foreign_keys=on")
-// if err != nil {
-// panic(err)
-// }
-// container, err := sqlstore.NewWithDB(db, "sqlite3", nil)
+//
+// db, err := sql.Open("sqlite3", "file:yoursqlitefile.db?_foreign_keys=on")
+// if err != nil {
+// panic(err)
+// }
+// container, err := sqlstore.NewWithDB(db, "sqlite3", nil)
func NewWithDB(db *sql.DB, dialect string, log waLog.Logger) *Container {
if log == nil {
log = waLog.Noop
@@ -123,6 +125,7 @@ func (c *Container) scanDevice(row scannable) (*store.Device, error) {
device.AppState = innerStore
device.Contacts = innerStore
device.ChatSettings = innerStore
+ device.MsgSecrets = innerStore
device.Container = c
device.Initialized = true
@@ -236,6 +239,7 @@ func (c *Container) PutDevice(device *store.Device) error {
device.AppState = innerStore
device.Contacts = innerStore
device.ChatSettings = innerStore
+ device.MsgSecrets = 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 abea5fe2..1261bec0 100644
--- a/vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go
+++ b/vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go
@@ -28,7 +28,8 @@ var ErrInvalidLength = errors.New("database returned byte array with illegal len
// PostgresArrayWrapper is a function to wrap array values before passing them to the sql package.
//
// When using github.com/lib/pq, you should set
-// whatsmeow.PostgresArrayWrapper = pq.Array
+//
+// whatsmeow.PostgresArrayWrapper = pq.Array
var PostgresArrayWrapper func(interface{}) interface {
driver.Valuer
sql.Scanner
@@ -687,3 +688,42 @@ func (s *SQLStore) GetChatSettings(chat types.JID) (settings types.LocalChatSett
}
return
}
+
+const (
+ putMsgSecret = `
+ INSERT INTO whatsmeow_message_secrets (our_jid, chat_jid, sender_jid, message_id, key)
+ VALUES ($1, $2, $3, $4, $5)
+ ON CONFLICT (our_jid, chat_jid, sender_jid, message_id) DO NOTHING
+ `
+ getMsgSecret = `
+ SELECT key FROM whatsmeow_message_secrets WHERE our_jid=$1 AND chat_jid=$2 AND sender_jid=$3 AND message_id=$4
+ `
+)
+
+func (s *SQLStore) PutMessageSecrets(inserts []store.MessageSecretInsert) (err error) {
+ tx, err := s.db.Begin()
+ if err != nil {
+ 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.Commit()
+ if err != nil {
+ return fmt.Errorf("failed to commit transaction: %w", err)
+ }
+ return
+}
+
+func (s *SQLStore) PutMessageSecret(chat, sender types.JID, id types.MessageID, secret []byte) (err error) {
+ _, err = s.db.Exec(putMsgSecret, s.JID, chat.ToNonAD(), sender.ToNonAD(), id, secret)
+ return
+}
+
+func (s *SQLStore) GetMessageSecret(chat, sender types.JID, id types.MessageID) (secret []byte, err error) {
+ err = s.db.QueryRow(getMsgSecret, s.JID, chat.ToNonAD(), sender.ToNonAD(), id).Scan(&secret)
+ if errors.Is(err, sql.ErrNoRows) {
+ err = nil
+ }
+ return
+}
diff --git a/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go b/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go
index 4a4b2ca7..70556ec3 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}
+var Upgrades = [...]upgradeFunc{upgradeV1, upgradeV2, upgradeV3}
func (c *Container) getVersion() (int, error) {
_, err := c.db.Exec("CREATE TABLE IF NOT EXISTS whatsmeow_version (version INTEGER)")
@@ -246,3 +246,17 @@ func upgradeV2(tx *sql.Tx, container *Container) error {
}
return err
}
+
+func upgradeV3(tx *sql.Tx, container *Container) error {
+ _, err := tx.Exec(`CREATE TABLE whatsmeow_message_secrets (
+ our_jid TEXT,
+ chat_jid TEXT,
+ sender_jid TEXT,
+ message_id TEXT,
+ key bytea NOT NULL,
+
+ PRIMARY KEY (our_jid, chat_jid, sender_jid, message_id),
+ FOREIGN KEY (our_jid) REFERENCES whatsmeow_device(jid) ON DELETE CASCADE ON UPDATE CASCADE
+ )`)
+ return err
+}