mongostore

package module
v0.0.0-...-081b7fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2025 License: MPL-2.0 Imports: 17 Imported by: 0

README

MongoDB Store for Whatsmeow

Go Reference

A MongoDB implementation of the store interfaces for whatsmeow.

[!CAUTION] This is an experimental MongoDB implementation for whatsmeow. While it's functional, please use it with caution in your environments.

Installation

go get github.com/SoursopID/mongostore@latest

Usage

package main

import (
    "github.com/SoursopID/mongostore"
    "go.mau.fi/whatsmeow"
	waLog "go.mau.fi/whatsmeow/util/log"
)

func main() {
    walog := waLog.Stdout("test", "DEBUG", false)
	container, err := mongostore.New("mongodb://localhost:27017", "database_name", walog)
	if err != nil {
		panic(err)
	}

    ...
}

Features

  • Implements all required whatsmeow store interfaces:
    • IdentityStore
    • SessionStore
    • PreKeyStore
    • SenderKeyStore
    • AppStateSyncKeyStore
    • AppStateStore
    • ContactStore
  • Thread-safe operations
  • Persistent storage in MongoDB

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate and follow the existing coding style.

License

This project is licensed under the Mozilla Public License Version 2.0 - see the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	COL_APP_STATE_MUTATION_MACS string = "whatsmeow_app_state_mutation_macs"
	COL_APP_STATE_SYNC_KEYS     string = "whatsmeow_app_state_sync_keys"
	COL_APP_STATE_VERSION       string = "whatsmeow_app_state_version"
	COL_CHAT_SETTINGS           string = "whatsmeow_chat_settings"
	COL_CONTACTS                string = "whatsmeow_contacts"
	COL_DEVICE                  string = "whatsmeow_device"
	COL_IDENTITY_KEYS           string = "whatsmeow_identity_keys"
	COL_MESSAGE_SECRETS         string = "whatsmeow_message_secrets"
	COL_PRE_KEYS                string = "whatsmeow_pre_keys"
	COL_PRIVACY_TOKENS          string = "whatsmeow_privacy_tokens"
	COL_SENDER_KEYS             string = "whatsmeow_sender_keys"
	COL_SESSIONS                string = "whatsmeow_sessions"
	COL_VERSION                 string = "whatsmeow_version"
)

Variables

View Source
var ErrDeviceIDMustBeSet = errors.New("device JID must be known before accessing database")
View Source
var ErrInvalidLength = errors.New("database returned byte array with illegal length")
View Source
var Upgrades = [...]upgradeFunc{upgradeV1}

Functions

This section is empty.

Types

type Container

type Container struct {
	DatabaseErrorHandler func(device *store.Device, action string, attemptIndex int, err error) (retry bool)
	// contains filtered or unexported fields
}

func New

func New(address, database_name string, log waLog.Logger) (*Container, error)

func NewWithDB

func NewWithDB(db *mongo.Database, log waLog.Logger) *Container

func (*Container) Close

func (c *Container) Close() error

func (*Container) DeleteDevice

func (c *Container) DeleteDevice(device *store.Device) error

func (*Container) GetAllDevices

func (c *Container) GetAllDevices() ([]*store.Device, error)

func (*Container) GetDevice

func (c *Container) GetDevice(jid types.JID) (*store.Device, error)

func (*Container) GetFirstDevice

func (c *Container) GetFirstDevice() (*store.Device, error)

func (*Container) NewDevice

func (c *Container) NewDevice() *store.Device

func (*Container) PutDevice

func (c *Container) PutDevice(device *store.Device) error

func (*Container) Upgrade

func (c *Container) Upgrade() error

type DataAppVersion

type DataAppVersion struct {
	JID     string `bson:"jid"`
	Name    string `bson:"name"`
	Version uint64 `bson:"version"`
	Hash    []byte `bson:"hash"`
}

type DataContact

type DataContact struct {
	OurJID       string `bson:"our_jid"`
	TheirJID     string `bson:"their_jid"`
	FirstName    string `bson:"first_name"`
	FullName     string `bson:"full_name"`
	PushName     string `bson:"push_name"`
	BusinessName string `bson:"business_name"`
}

type DataDevice

type DataDevice struct {
	ID string `bson:"jid"`

	RegistrationID uint32 `bson:"registration_id"`

	NoiseKey    []byte `bson:"noise_key"`
	IdentityKey []byte `bson:"identity_key"`

	SignedPreKey    []byte `bson:"signed_pre_key"`
	SignedPreKeyID  uint32 `bson:"signed_pre_key_id"`
	SignedPreKeySig []byte `bson:"signed_pre_key_sig"`

	AdvKey           []byte `bson:"adv_key"`
	AdvDetails       []byte `bson:"adv_details"`
	AdvAccountSig    []byte `bson:"adv_account_sig"`
	AdvAccountSigKey []byte `bson:"adv_account_sig_key"`
	AdvDeviceSig     []byte `bson:"adv_device_sig"`

	Platform     string    `bson:"platform"`
	BusinessName string    `bson:"business_name"`
	PushName     string    `bson:"push_name"`
	FacebookUUID uuid.UUID `bson:"facebook_uuid"`

	Initialized bool `bson:"initialized"`
}

type DataMessageSecret

type DataMessageSecret struct {
	OurJID    string          `bson:"our_jid"`
	ChatJID   string          `bson:"chat_jid"`
	SenderJID string          `bson:"sender_jid"`
	MessageID types.MessageID `bson:"message_id"`
	Key       []byte          `bson:"key"`
}

type DataPrekey

type DataPrekey struct {
	JID      string `bson:"jid"`
	KeyID    uint32 `bson:"key_id"`
	Key      []byte `bson:"key"`
	Uploaded bool   `bson:"uploaded"`
}

type DataPrivacyToken

type DataPrivacyToken struct {
	OurJID    string `bson:"our_jid"`
	TheirJID  string `bson:"their_jid"`
	Token     []byte `bson:"token"`
	Timestamp int64  `bson:"timestamp"`
}

type DataStateSyncKey

type DataStateSyncKey struct {
	JID         string `bson:"jid"`
	KeyID       []byte `bson:"key_id"`
	KeyData     []byte `bson:"key_data"`
	Timestamp   int64  `bson:"timestamp"`
	Fingerprint []byte `bson:"fingerprint"`
}

type MongoStore

type MongoStore struct {
	*Container
	JID string
	// contains filtered or unexported fields
}

func NewMongoStore

func NewMongoStore(c *Container, jid types.JID) *MongoStore

func (*MongoStore) DeleteAllIdentities

func (m *MongoStore) DeleteAllIdentities(phone string) error

func (*MongoStore) DeleteAllSessions

func (m *MongoStore) DeleteAllSessions(phone string) error

func (*MongoStore) DeleteAppStateMutationMACs

func (m *MongoStore) DeleteAppStateMutationMACs(name string, indexMACs [][]byte) error

func (*MongoStore) DeleteAppStateVersion

func (m *MongoStore) DeleteAppStateVersion(name string) error

func (*MongoStore) DeleteIdentity

func (m *MongoStore) DeleteIdentity(address string) error

func (*MongoStore) DeleteSession

func (m *MongoStore) DeleteSession(address string) error

func (*MongoStore) GenOnePreKey

func (m *MongoStore) GenOnePreKey() (key *keys.PreKey, err error)

func (*MongoStore) GetAllContacts

func (m *MongoStore) GetAllContacts() (map[types.JID]types.ContactInfo, error)

func (*MongoStore) GetAppStateMutationMAC

func (m *MongoStore) GetAppStateMutationMAC(name string, indexMAC []byte) ([]byte, error)

func (*MongoStore) GetAppStateSyncKey

func (m *MongoStore) GetAppStateSyncKey(id []byte) (key *store.AppStateSyncKey, err error)

func (*MongoStore) GetAppStateVersion

func (m *MongoStore) GetAppStateVersion(name string) (version uint64, hash [128]byte, err error)

func (*MongoStore) GetChatSettings

func (m *MongoStore) GetChatSettings(chat types.JID) (types.LocalChatSettings, error)

func (*MongoStore) GetContact

func (m *MongoStore) GetContact(user types.JID) (types.ContactInfo, error)

func (*MongoStore) GetLatestAppStateSyncKeyID

func (m *MongoStore) GetLatestAppStateSyncKeyID() ([]byte, error)

func (*MongoStore) GetMessageSecret

func (m *MongoStore) GetMessageSecret(chat, sender types.JID, id types.MessageID) ([]byte, error)

func (*MongoStore) GetOrGenPreKeys

func (m *MongoStore) GetOrGenPreKeys(count uint32) ([]*keys.PreKey, error)

func (*MongoStore) GetPreKey

func (m *MongoStore) GetPreKey(keyID uint32) (*keys.PreKey, error)

func (*MongoStore) GetPrivacyToken

func (m *MongoStore) GetPrivacyToken(user types.JID) (*store.PrivacyToken, error)

func (*MongoStore) GetSenderKey

func (m *MongoStore) GetSenderKey(chatID string, senderID string) (key []byte, err error)

func (*MongoStore) GetSession

func (m *MongoStore) GetSession(address string) ([]byte, error)

func (*MongoStore) HasSession

func (m *MongoStore) HasSession(address string) (ok bool, err error)

func (*MongoStore) IsTrustedIdentity

func (m *MongoStore) IsTrustedIdentity(address string, key [32]byte) (ok bool, err error)

func (*MongoStore) MarkPreKeysAsUploaded

func (m *MongoStore) MarkPreKeysAsUploaded(keyID uint32) error

func (*MongoStore) PutAllContactNames

func (m *MongoStore) PutAllContactNames(contacts []store.ContactEntry) error

func (*MongoStore) PutAppStateMutationMACs

func (m *MongoStore) PutAppStateMutationMACs(name string, version uint64, mutations []store.AppStateMutationMAC) error

func (*MongoStore) PutAppStateSyncKey

func (m *MongoStore) PutAppStateSyncKey(id []byte, key store.AppStateSyncKey) error

func (*MongoStore) PutAppStateVersion

func (m *MongoStore) PutAppStateVersion(name string, version uint64, hash [128]byte) error

func (*MongoStore) PutArchived

func (m *MongoStore) PutArchived(chat types.JID, archived bool) error

func (*MongoStore) PutBusinessName

func (m *MongoStore) PutBusinessName(user types.JID, businessName string) (bool, string, error)

func (*MongoStore) PutContactName

func (m *MongoStore) PutContactName(user types.JID, firstName, fullName string) error

func (*MongoStore) PutIdentity

func (m *MongoStore) PutIdentity(address string, key [32]byte) error

func (*MongoStore) PutMessageSecret

func (m *MongoStore) PutMessageSecret(chat, sender types.JID, id types.MessageID, secret []byte) error

func (*MongoStore) PutMessageSecrets

func (m *MongoStore) PutMessageSecrets(inserts []store.MessageSecretInsert) error

func (*MongoStore) PutMutedUntil

func (m *MongoStore) PutMutedUntil(chat types.JID, until time.Time) error

func (*MongoStore) PutPinned

func (m *MongoStore) PutPinned(chat types.JID, pinned bool) error

func (*MongoStore) PutPrivacyTokens

func (m *MongoStore) PutPrivacyTokens(tokens ...store.PrivacyToken) error

func (*MongoStore) PutPushName

func (m *MongoStore) PutPushName(user types.JID, pushName string) (bool, string, error)

func (*MongoStore) PutSenderKey

func (m *MongoStore) PutSenderKey(chatID string, senderID string, key []byte) error

func (*MongoStore) PutSession

func (m *MongoStore) PutSession(address string, session []byte) error

func (*MongoStore) RemovePreKey

func (m *MongoStore) RemovePreKey(keyID uint32) error

func (*MongoStore) UploadedPreKeyCount

func (m *MongoStore) UploadedPreKeyCount() (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL