local

package
v2.6.20 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotAMailbox indicates the given path is not within a mailbox.
	ErrNotAMailbox = errors.New("not a mailbox (or any of the parent directories): .textile")
	// ErrMailboxExists is used during initialization to indicate the path already contains a mailbox.
	ErrMailboxExists = errors.New("mailbox is already initialized")
	// ErrIdentityRequired indicates the operation requires a thread Identity but none was given.
	ErrIdentityRequired = errors.New("thread Identity is required")
	// ErrAPIKeyRequired indicates the operation requires am API keybut none was given.
	ErrAPIKeyRequired = errors.New("api key is required")
)

Functions

func DefaultConfConfig

func DefaultConfConfig() cmd.ConfConfig

DefaultConfConfig returns the default ConfConfig.

Types

type Config

type Config struct {
	// Path is the path in which the new mailbox should be created (required).
	Path string
	// Identity is the thread.Identity of the mailbox owner (required).
	// It's value may be inflated from a --identity flag or {EnvPrefix}_IDENTITY env variable.
	Identity thread.Identity
	// APIKey is hub API key (required).
	// It's value may be inflated from a --api-key flag or {EnvPrefix}_API_KEY env variable.
	APIKey string
	// APISecret is hub API key secret (optional).
	// It's value may be inflated from a --api-secret flag or {EnvPrefix}_API_SECRET env variable.
	APISecret string
}

Config contains details for a new local mailbox.

type Mail

type Mail struct {
	// contains filtered or unexported fields
}

Mail is used to create new mailboxes based on the provided clients and config.

func NewMail

func NewMail(clients *cmd.Clients, config cmd.ConfConfig) *Mail

NewMail creates Mail from clients and config.

func (*Mail) Clients

func (m *Mail) Clients() *cmd.Clients

Clients returns the underlying clients object.

func (*Mail) GetLocalMailbox

func (m *Mail) GetLocalMailbox(_ context.Context, pth string) (*Mailbox, error)

GetLocalMailbox loads and returns the mailbox at path if it exists.

func (*Mail) NewConfigFromCmd

func (m *Mail) NewConfigFromCmd(c *cobra.Command, pth string) (conf Config, err error)

NewConfigFromCmd returns a config by inflating values from the given cobra command and path. First, flags for "identity", "api_key", and "api_secret" are used if they exist. If still unset, the env vars {EnvPrefix}_IDENTITY, {EnvPrefix}_API_KEY, and {EnvPrefix}_API_SECRET are used.

func (*Mail) NewMailbox

func (m *Mail) NewMailbox(ctx context.Context, conf Config) (box *Mailbox, err error)

NewMailbox initializes a new mailbox from the config.

type Mailbox

type Mailbox struct {
	// contains filtered or unexported fields
}

Mailbox is a local-first messaging library built on ThreadDB and IPFS.

func (*Mailbox) DeleteInboxMessage

func (m *Mailbox) DeleteInboxMessage(ctx context.Context, id string) error

DeleteInboxMessage deletes an inbox message by ID.

func (*Mailbox) DeleteSentboxMessage

func (m *Mailbox) DeleteSentboxMessage(ctx context.Context, id string) error

DeleteSentboxMessage deletes a sent message by ID.

func (*Mailbox) Identity

func (m *Mailbox) Identity() thread.Identity

Identity returns the mailbox's identity.

func (*Mailbox) ListInboxMessages

func (m *Mailbox) ListInboxMessages(ctx context.Context, opts ...client.ListOption) ([]client.Message, error)

ListInboxMessages lists messages from the inbox. Use options to paginate with seek and limit, and filter by read status.

func (*Mailbox) ListSentboxMessages

func (m *Mailbox) ListSentboxMessages(ctx context.Context, opts ...client.ListOption) ([]client.Message, error)

ListSentboxMessages lists messages from the sentbox. Use options to paginate with seek and limit.

func (*Mailbox) ReadInboxMessage

func (m *Mailbox) ReadInboxMessage(ctx context.Context, id string) error

ReadInboxMessage marks a message as read by ID.

func (*Mailbox) SendMessage

func (m *Mailbox) SendMessage(ctx context.Context, to thread.PubKey, body []byte) (msg client.Message, err error)

SendMessage sends the message body to a recipient.

func (*Mailbox) WatchInbox

func (m *Mailbox) WatchInbox(ctx context.Context, mevents chan<- MailboxEvent, offline bool) (<-chan cmd.WatchState, error)

WatchInbox watches the inbox for new mailbox events. If offline is true, this will keep watching during network interruptions. Returns a channel of watch connectivity states. Cancel context to stop watching.

func (*Mailbox) WatchSentbox

func (m *Mailbox) WatchSentbox(ctx context.Context, mevents chan<- MailboxEvent, offline bool) (<-chan cmd.WatchState, error)

WatchSentbox watches the sentbox for new mailbox events. If offline is true, this will keep watching during network interruptions. Returns a channel of watch connectivity states. Cancel context to stop watching.

type MailboxEvent

type MailboxEvent struct {
	// Type of event.
	Type MailboxEventType
	// Message identifier.
	MessageID db.InstanceID
	// Message will contain the full message unless this is a delete event.
	Message client.Message
}

MailboxEvent describes an event that occurred in a mailbox.

type MailboxEventType

type MailboxEventType int

MailboxEventType is the type of mailbox event.

const (
	// NewMessage indicates the mailbox has a new message.
	NewMessage MailboxEventType = iota
	// MessageRead indicates a message was read in the mailbox.
	MessageRead
	// MessageDeleted indicates a message was deleted from the mailbox.
	MessageDeleted
)

Jump to

Keyboard shortcuts

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