client

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: MIT Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides the client api.

func NewClient

func NewClient(target string, opts ...grpc.DialOption) (*Client, error)

NewClient starts the client.

func (*Client) Close

func (c *Client) Close() error

Close closes the client's grpc connection and cancels any active requests.

func (*Client) DeleteInboxMessage

func (c *Client) DeleteInboxMessage(ctx context.Context, id string) error

DeleteInboxMessage deletes an inbox message by ID.

func (*Client) DeleteSentboxMessage

func (c *Client) DeleteSentboxMessage(ctx context.Context, id string) error

DeleteSentboxMessage deletes a sent message by ID.

func (*Client) GetThread

func (c *Client) GetThread(ctx context.Context, name string) (*pb.GetThreadResponse, error)

GetThread returns a thread by name.

func (*Client) GetUsage

func (c *Client) GetUsage(ctx context.Context, opts ...UsageOption) (*pb.GetUsageResponse, error)

GetUsage returns current billing and usage information.

func (*Client) ListInboxMessages

func (c *Client) ListInboxMessages(ctx context.Context, opts ...ListOption) ([]Message, error)

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

func (*Client) ListSentboxMessages

func (c *Client) ListSentboxMessages(ctx context.Context, opts ...ListOption) ([]Message, error)

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

func (*Client) ListThreads

func (c *Client) ListThreads(ctx context.Context) (*pb.ListThreadsResponse, error)

ListThreads returns a list of threads. Threads can be created using the threads or threads network client.

func (*Client) ReadInboxMessage

func (c *Client) ReadInboxMessage(ctx context.Context, id string) error

ReadInboxMessage marks a message as read by ID.

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, from thread.Identity, to thread.PubKey, body []byte) (msg Message, err error)

SendMessage sends the message body to a recipient.

func (*Client) SetupMailbox

func (c *Client) SetupMailbox(ctx context.Context) (mailbox thread.ID, err error)

SetupMailbox creates inbox and sentbox threads needed user mail.

type ListOption

type ListOption func(*listOptions)

func WithAscending

func WithAscending(asc bool) ListOption

WithAscending lists messages by ascending order.

func WithLimit

func WithLimit(limit int) ListOption

WithLimit limits the number of list messages results.

func WithSeek

func WithSeek(id string) ListOption

WithSeek starts listing from the given ID.

func WithStatus

func WithStatus(s Status) ListOption

WithStatus filters messages by read status. Note: Only applies to inbox messages.

type Message

type Message struct {
	ID        string        `json:"_id"`
	From      thread.PubKey `json:"from"`
	To        thread.PubKey `json:"to"`
	Body      []byte        `json:"body"`
	Signature []byte        `json:"signature"`
	CreatedAt time.Time     `json:"created_at"`
	ReadAt    time.Time     `json:"read_at,omitempty"`
}

Message is the client side representation of a mailbox message. Signature corresponds to the encrypted body. Use message.Open to get the plaintext body.

func (Message) IsRead

func (m Message) IsRead() bool

IsRead returns whether or not the message has been read.

func (Message) Open

func (m Message) Open(ctx context.Context, id thread.Identity) ([]byte, error)

Open decrypts the message body with identity.

func (Message) UnmarshalInstance

func (m Message) UnmarshalInstance(data []byte) error

UnmarshalInstance unmarshals the message from its ThreadDB instance data. This will return an error if the message signature fails verification.

type Status

type Status int

Status indicates message read status.

const (
	// All includes read and unread messages.
	All Status = iota
	// Read is only read messages.
	Read
	// Unread is only unread messages.
	Unread
)

type UsageOption

type UsageOption func(*usageOptions)

func WithPubKey

func WithPubKey(key string) UsageOption

WithPubKey returns usage info for the public key.

Jump to

Keyboard shortcuts

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