summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/whatsmeow/store
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/store')
-rw-r--r--vendor/go.mau.fi/whatsmeow/store/clientpayload.go2
-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
-rw-r--r--vendor/go.mau.fi/whatsmeow/store/store.go14
5 files changed, 81 insertions, 9 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/store/clientpayload.go b/vendor/go.mau.fi/whatsmeow/store/clientpayload.go
index 3bed656f..6c683eed 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, 2230, 10}
+var waVersion = WAVersionContainer{2, 2245, 9}
// 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 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
+}
diff --git a/vendor/go.mau.fi/whatsmeow/store/store.go b/vendor/go.mau.fi/whatsmeow/store/store.go
index 76087e46..b26a28b8 100644
--- a/vendor/go.mau.fi/whatsmeow/store/store.go
+++ b/vendor/go.mau.fi/whatsmeow/store/store.go
@@ -99,6 +99,19 @@ type DeviceContainer interface {
DeleteDevice(store *Device) error
}
+type MessageSecretInsert struct {
+ Chat types.JID
+ Sender types.JID
+ ID types.MessageID
+ Secret []byte
+}
+
+type MsgSecretStore interface {
+ PutMessageSecrets([]MessageSecretInsert) error
+ PutMessageSecret(chat, sender types.JID, id types.MessageID, secret []byte) error
+ GetMessageSecret(chat, sender types.JID, id types.MessageID) ([]byte, error)
+}
+
type Device struct {
Log waLog.Logger
@@ -123,6 +136,7 @@ type Device struct {
AppState AppStateStore
Contacts ContactStore
ChatSettings ChatSettingsStore
+ MsgSecrets MsgSecretStore
Container DeviceContainer
DatabaseErrorHandler func(device *Device, action string, attemptIndex int, err error) (retry bool)