Documentation
¶
Overview ¶
Package store is the local SQLite archive of WhatsApp chats and messages.
WhatsApp only delivers messages once; wamcp keeps them here so they can be listed and searched later. The archive is independent from the whatsmeow session database.
Index ¶
- Variables
- type Chat
- type ListChatsParams
- type Message
- type MessagesParams
- type SearchParams
- type Store
- func (s *Store) AllChats(ctx context.Context) ([]Chat, error)
- func (s *Store) Close() error
- func (s *Store) DeleteMessage(ctx context.Context, chatJID, id, revokerJID string, anySender bool) (bool, error)
- func (s *Store) EditMessage(ctx context.Context, chatJID, id, editorJID, text string) error
- func (s *Store) GetChat(ctx context.Context, jid string) (Chat, error)
- func (s *Store) GetMessage(ctx context.Context, chatJID, id string) (Message, error)
- func (s *Store) ListChats(ctx context.Context, p ListChatsParams) ([]Chat, error)
- func (s *Store) MessageSender(ctx context.Context, chatJID, id string) (string, error)
- func (s *Store) Messages(ctx context.Context, p MessagesParams) ([]Message, error)
- func (s *Store) RenameChat(ctx context.Context, jid, name string) error
- func (s *Store) SaveMessage(ctx context.Context, m Message) error
- func (s *Store) Search(ctx context.Context, p SearchParams) ([]Message, error)
- func (s *Store) Stats(ctx context.Context) (chats, messages int, err error)
- func (s *Store) UpsertChat(ctx context.Context, jid, name string, isGroup bool, lastMessageAt time.Time) error
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a chat or message does not exist.
Functions ¶
This section is empty.
Types ¶
type Chat ¶
type Chat struct {
JID string
Name string
IsGroup bool
LastMessageAt time.Time
LastMessage *Message // nil when the chat has no stored message
}
Chat is a conversation (direct or group).
type ListChatsParams ¶
type ListChatsParams struct {
Query string // case-insensitive match on name or JID; empty matches all
Limit int
Offset int
}
ListChatsParams filters ListChats.
type Message ¶
type Message struct {
ChatJID string
ID string
SenderJID string
FromMe bool
Timestamp time.Time
Text string
MediaType string // "", "image", "video", "audio", "document", "sticker"
Filename string
MimeType string
Raw []byte // serialized waE2E.Message, kept only for media (needed to download it)
Edited bool
Deleted bool
}
Message is a single stored message.
type MessagesParams ¶
type MessagesParams struct {
ChatJID string
Before time.Time // only messages strictly older than this time; zero means "latest"
BeforeID string // only messages older than this message (pagination cursor, exact even within one second)
Limit int
}
MessagesParams selects messages of one chat.
type SearchParams ¶
type SearchParams struct {
Query string // substring of the text or filename (case-insensitive for ASCII letters)
ChatJID string // optional
Limit int
}
SearchParams filters Search.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps the SQLite database.
func (*Store) AllChats ¶
AllChats returns every chat JID with its group flag (used to refresh names).
func (*Store) DeleteMessage ¶
func (s *Store) DeleteMessage(ctx context.Context, chatJID, id, revokerJID string, anySender bool) (bool, error)
DeleteMessage marks a message as deleted for everyone and drops its content. Unless anySender is set (a verified group admin), only the message's own sender can delete it. It reports whether a message was deleted.
func (*Store) EditMessage ¶
EditMessage replaces the text of a stored message, only if editorJID is its sender (WhatsApp only lets authors edit). Unknown messages are ignored.
func (*Store) GetMessage ¶
GetMessage returns one message, including its raw payload.
func (*Store) ListChats ¶
ListChats returns chats ordered by most recent activity, each with its last message.
func (*Store) MessageSender ¶
MessageSender returns the sender of a stored message.
func (*Store) Messages ¶
Messages returns the newest messages of a chat (older than Before), in chronological order.
func (*Store) RenameChat ¶
RenameChat sets the name of an existing chat; unknown chats are left alone (so seeing someone's name in a group does not create a chat with them).
func (*Store) SaveMessage ¶
SaveMessage stores m and bumps its chat. Re-saving an existing message (e.g. from a later history sync) refreshes its content.