friends

package
v0.0.0-...-8155ea7 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: GPL-2.0, GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateRequest = errors.New("friend request already exists")

ErrDuplicateRequest is returned when a friend request already exists.

Functions

This section is empty.

Types

type Friend

type Friend struct {
	AgentID   string       `json:"agentId"`
	AgentName string       `json:"agentName"`
	PublicKey []byte       `json:"publicKey"`
	Status    FriendStatus `json:"status"`
	AddedAt   time.Time    `json:"addedAt"`
	UpdatedAt time.Time    `json:"updatedAt"`
	Message   string       `json:"message,omitempty"`
}

Friend represents a friend agent relationship.

type FriendStatus

type FriendStatus string

FriendStatus represents the status of a friend relationship.

const (
	StatusAny      FriendStatus = ""
	StatusPending  FriendStatus = "pending"
	StatusAccepted FriendStatus = "accepted"
	StatusRejected FriendStatus = "rejected"
	StatusRevoked  FriendStatus = "revoked"
)

type Manager

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

Manager handles the friend request/response lifecycle.

func NewManager

func NewManager(store *Store) *Manager

NewManager creates a new friend manager backed by the given store.

func (*Manager) AcceptRequest

func (m *Manager) AcceptRequest(agentID, myName string, myPublicKey []byte) (*Friend, error)

AcceptRequest accepts a pending friend request.

func (*Manager) GetPendingRequests

func (m *Manager) GetPendingRequests() []*Friend

GetPendingRequests returns all pending friend requests.

func (*Manager) ListAcceptedFriends

func (m *Manager) ListAcceptedFriends() []*Friend

ListAcceptedFriends returns all accepted friends.

func (*Manager) RejectRequest

func (m *Manager) RejectRequest(agentID string) (*Friend, error)

RejectRequest rejects a pending friend request.

func (*Manager) RevokeFriend

func (m *Manager) RevokeFriend(agentID string) error

RevokeFriend removes an accepted friend entirely.

func (*Manager) SendRequest

func (m *Manager) SendRequest(fromAgentID, fromAgentName string, publicKey []byte, message string) error

SendRequest creates a pending friend request from another agent.

type Store

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

Store manages persistent friend relationships using SQLite.

func NewStore

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

NewStore creates or opens a friend store at the given SQLite path.

func (*Store) AddFriend

func (s *Store) AddFriend(f *Friend) error

AddFriend inserts or replaces a friend record.

func (*Store) Close

func (s *Store) Close()

Close closes the underlying database connection. Safe to call multiple times.

func (*Store) GetFriend

func (s *Store) GetFriend(agentID string) *Friend

GetFriend retrieves a friend by agent ID. Returns nil if not found.

func (*Store) IsFriend

func (s *Store) IsFriend(agentID string) bool

IsFriend returns true if the agent exists and has StatusAccepted.

func (*Store) ListFriends

func (s *Store) ListFriends(status FriendStatus) []*Friend

ListFriends returns friends filtered by status. Use StatusAny to return all.

func (*Store) RemoveFriend

func (s *Store) RemoveFriend(agentID string) error

RemoveFriend deletes a friend by agent ID. Returns os.ErrNotExist if not found.

func (*Store) UpdateStatus

func (s *Store) UpdateStatus(agentID string, status FriendStatus) error

UpdateStatus changes the status of a friend. Returns os.ErrNotExist if not found.

Jump to

Keyboard shortcuts

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