chat

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MPL-2.0 Imports: 15 Imported by: ? 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 chat is the local roster and per-peer linear log for AID-to-AID messaging. It has no network of its own.

Index

Constants

View Source
const (
	StateOutPending = "out_pending"
	StateInPending  = "in_pending"
	StateMutual     = "mutual"
	StateBlocked    = "blocked"

	DirOut = "out"
	DirIn  = "in"

	StatusLocal = "local"
	StatusSent  = "sent"
	StatusIn    = "in"

	KindText = "text"
	KindFile = "file"

	PendingCap    = 32
	IgnoreTTL     = 72 * time.Hour
	DingMerge     = time.Hour
	NoteMaxRunes  = 80
	DefaultLimit  = 50
	PurposeInvite = "chat.invite"
	PowMaxAge     = 24 * time.Hour
)
View Source
const (
	KindInvite = "chat.invite"
	KindAccept = "chat.accept"
	KindRefuse = "chat.refuse"
	KindDing   = "chat.ding"
	KindPull   = "chat.pull"
	KindMsg    = "chat.msg"

	MsgText = "t"
	MsgFile = "f"
)

Variables

View Source
var (
	ErrSelf        = errors.New("chat: cannot message this identity")
	ErrNotFriends  = errors.New("not_friends: the peer is not on this identity's chat list — call chat_request first")
	ErrAlready     = errors.New("chat: already requested or friends")
	ErrBlocked     = errors.New("chat: this peer is blocked")
	ErrNotPending  = errors.New("chat: no pending invite from that peer")
	ErrPendingFull = errors.New("chat: pending invite list is full")
	ErrHasInbound  = errors.New("chat: inbound invite already pending")
	ErrBadState    = errors.New("chat: invalid roster state")
	ErrSignaling   = errors.New("chat: signaling not delivered")
)
View Source
var ErrTooLarge = errors.New("chat: message too large")

Functions

func DecodeNonce

func DecodeNonce(s string) ([]byte, error)

func EncodeEmpty

func EncodeEmpty() []byte

func EncodeInvite

func EncodeInvite(inv Invite) ([]byte, error)

func EncodeMsg

func EncodeMsg(m Msg) ([]byte, error)

func EncodePull

func EncodePull(after uint64) ([]byte, error)

func NonceB64

func NonceB64(nonce []byte) string

func TruncateRunes

func TruncateRunes(s string, n int) string

func VerifyInvite

func VerifyInvite(from, to a2al.Address, inv Invite, nowTS int64) bool

Types

type Invite

type Invite struct {
	TS    int64  `json:"ts"`
	Nonce string `json:"nonce"`
	Bits  int    `json:"bits"`
	Note  string `json:"note,omitempty"`
}

func DecodeInvite

func DecodeInvite(body []byte) (Invite, error)

type Msg

type Msg struct {
	Seq    uint64 `json:"seq"`
	TS     int64  `json:"ts"`
	K      string `json:"k"`
	Body   string `json:"body,omitempty"`
	Ref    string `json:"ref,omitempty"`
	Name   string `json:"name,omitempty"`
	Size   int64  `json:"size,omitempty"`
	Author string `json:"author,omitempty"`
	Grant  string `json:"grant,omitempty"`
	Sig    string `json:"sig,omitempty"`
}

func DecodeMsg

func DecodeMsg(body []byte) (Msg, error)

func MsgFromRec

func MsgFromRec(r Rec) Msg

type Pull

type Pull struct {
	After uint64 `json:"after"`
}

func DecodePull

func DecodePull(body []byte) (Pull, error)

type Rec

type Rec struct {
	Seq    uint64
	Dir    string
	TS     int64
	Kind   string
	Body   string
	Ref    [32]byte
	Name   string
	Size   int64
	Status string
	Author a2al.Address
	Grant  string
	Idx    uint64 // 1-based local log index; set on Read, not stored
}

func RecFromMsg

func RecFromMsg(m Msg, peer a2al.Address) (Rec, error)

type RosterEntry

type RosterEntry struct {
	Peer    a2al.Address
	State   string
	Since   int64
	Note    string
	DingAt  int64
	ReadIdx uint64 // exclusive local log index already marked read
}

type Store

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

func Open

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

func (*Store) AppendIn

func (s *Store) AppendIn(peer a2al.Address, rec Rec) (dup bool, unreadEdge bool, err error)

func (*Store) AppendOut

func (s *Store) AppendOut(peer a2al.Address, rec Rec) (uint64, error)

func (*Store) Block

func (s *Store) Block(peer a2al.Address) error

func (*Store) CanSend

func (s *Store) CanSend(peer a2al.Address) bool

func (*Store) Contacts

func (s *Store) Contacts() []RosterEntry

func (*Store) Delete

func (s *Store) Delete(peer a2al.Address) error

func (*Store) DingFresh

func (s *Store) DingFresh(peer a2al.Address) bool

func (*Store) Get

func (s *Store) Get(peer a2al.Address) (RosterEntry, bool)

func (*Store) InPendingCount

func (s *Store) InPendingCount() int

func (*Store) Len added in v0.3.5

func (s *Store) Len(peer a2al.Address) int

func (*Store) MarkRead

func (s *Store) MarkRead(peer a2al.Address, scannedTo uint64) error

func (*Store) MarkSent

func (s *Store) MarkSent(peer a2al.Address, seq uint64) error

func (*Store) MaxInSeq

func (s *Store) MaxInSeq(peer a2al.Address) uint64

func (*Store) PutInPending

func (s *Store) PutInPending(peer a2al.Address, note string) error

func (*Store) PutOutPending

func (s *Store) PutOutPending(peer a2al.Address) error

func (*Store) Read

func (s *Store) Read(peer a2al.Address, after uint64, limit int) (out []Rec, scannedTo uint64, hasMore bool)

func (*Store) ReadCursor

func (s *Store) ReadCursor(peer a2al.Address) uint64

func (*Store) SetMutual

func (s *Store) SetMutual(peer a2al.Address) error

func (*Store) SetNow

func (s *Store) SetNow(fn func() time.Time)

func (*Store) TotalUnread

func (s *Store) TotalUnread() int

func (*Store) TouchDing

func (s *Store) TouchDing(peer a2al.Address) error

func (*Store) UnreadCount

func (s *Store) UnreadCount(peer a2al.Address) int

func (*Store) Unsent

func (s *Store) Unsent(peer a2al.Address) []Rec

Jump to

Keyboard shortcuts

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