store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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 Open

func Open(path string) (*Store, error)

Open opens (and creates if needed) the archive at path.

func (*Store) AllChats

func (s *Store) AllChats(ctx context.Context) ([]Chat, error)

AllChats returns every chat JID with its group flag (used to refresh names).

func (*Store) Close

func (s *Store) Close() error

Close closes the database.

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

func (s *Store) EditMessage(ctx context.Context, chatJID, id, editorJID, text string) error

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) GetChat

func (s *Store) GetChat(ctx context.Context, jid string) (Chat, error)

GetChat returns a single chat without its last message.

func (*Store) GetMessage

func (s *Store) GetMessage(ctx context.Context, chatJID, id string) (Message, error)

GetMessage returns one message, including its raw payload.

func (*Store) ListChats

func (s *Store) ListChats(ctx context.Context, p ListChatsParams) ([]Chat, error)

ListChats returns chats ordered by most recent activity, each with its last message.

func (*Store) MessageSender

func (s *Store) MessageSender(ctx context.Context, chatJID, id string) (string, error)

MessageSender returns the sender of a stored message.

func (*Store) Messages

func (s *Store) Messages(ctx context.Context, p MessagesParams) ([]Message, error)

Messages returns the newest messages of a chat (older than Before), in chronological order.

func (*Store) RenameChat

func (s *Store) RenameChat(ctx context.Context, jid, name string) error

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

func (s *Store) SaveMessage(ctx context.Context, m Message) error

SaveMessage stores m and bumps its chat. Re-saving an existing message (e.g. from a later history sync) refreshes its content.

func (*Store) Search

func (s *Store) Search(ctx context.Context, p SearchParams) ([]Message, error)

Search returns matching messages, newest first.

func (*Store) Stats

func (s *Store) Stats(ctx context.Context) (chats, messages int, err error)

Stats returns the number of stored chats and messages.

func (*Store) UpsertChat

func (s *Store) UpsertChat(ctx context.Context, jid, name string, isGroup bool, lastMessageAt time.Time) error

UpsertChat creates the chat or updates it. An empty name never overwrites a known one, and last_message_at only moves forward.

Jump to

Keyboard shortcuts

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