contact

package
v0.0.0-...-820a931 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: AGPL-3.0 Imports: 9 Imported by: 8

Documentation

Overview

Package contact is for managing the io.cozy.contacts documents and their groups.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMailAddress is returned when trying to access the email address of
	// a contact that has no known email address.
	ErrNoMailAddress = errors.New("The contact has no email address")
	// ErrNotFound is returned when no contact has been found for a query
	ErrNotFound = errors.New("No contact has been found")
)

Functions

This section is empty.

Types

type Contact

type Contact struct {
	couchdb.JSONDoc
}

Contact is a struct containing all the informations about a contact. We are using maps/slices/interfaces instead of structs, as it is a doctype that can also be used in front applications and they can add new fields. It would be complicated to maintain a up-to-date mapping, and failing to do so means that we can lose some data on JSON round-trip.

func CreateMyself

func CreateMyself(db prefixer.Prefixer, settings *couchdb.JSONDoc) (*Contact, error)

CreateMyself creates the myself contact document from the instance settings.

func Find

func Find(db prefixer.Prefixer, contactID string) (*Contact, error)

Find returns the contact stored in database from a given ID

func FindByEmail

func FindByEmail(db prefixer.Prefixer, email string) (*Contact, error)

FindByEmail returns the contact with the given email address, when possible

func GetMyself

func GetMyself(db prefixer.Prefixer) (*Contact, error)

GetMyself returns the myself contact document, or an ErrNotFound error.

func New

func New() *Contact

New returns a new blank contact.

func (*Contact) AddCozyURL

func (c *Contact) AddCozyURL(db prefixer.Prefixer, cozyURL string) error

AddCozyURL adds a cozy URL to this contact (unless the contact has already this cozy URL) and saves the contact.

func (*Contact) AddNameIfMissing

func (c *Contact) AddNameIfMissing(db prefixer.Prefixer, name, email string) error

AddNameIfMissing can be used to add a name if there was none. We need the email address to ignore it if the displayName was updated with it by a service of the contacts application.

func (*Contact) ChangeCozyURL

func (c *Contact) ChangeCozyURL(db prefixer.Prefixer, cozyURL string) error

ChangeCozyURL is used when a contact has moved their Cozy to a new URL.

func (*Contact) DocType

func (c *Contact) DocType() string

DocType returns the contact document type

func (*Contact) GroupIDs

func (c *Contact) GroupIDs() []string

GroupIDs returns the list of the group identifiers that this contact belongs to.

func (*Contact) PrimaryCozyURL

func (c *Contact) PrimaryCozyURL() string

PrimaryCozyURL returns the URL of the primary cozy, or a blank string if the contact has no known cozy.

func (*Contact) PrimaryName

func (c *Contact) PrimaryName() string

PrimaryName returns the name of the contact

func (*Contact) PrimaryPhoneNumber

func (c *Contact) PrimaryPhoneNumber() string

PrimaryPhoneNumber returns the preferred phone number, or a blank string if the contact has no known phone number.

func (*Contact) SortingKey

func (c *Contact) SortingKey() string

SortingKey returns a string that can be used for sorting the contacts like in the contacts app.

func (*Contact) ToMailAddress

func (c *Contact) ToMailAddress() (*mail.Address, error)

ToMailAddress returns a struct that can be used by cozy-stack to send an email to this contact

type Group

type Group struct {
	couchdb.JSONDoc
}

Group is a struct for a group of contacts.

func FindGroup

func FindGroup(db prefixer.Prefixer, groupID string) (*Group, error)

FindGroup returns the group of contacts stored in database from a given ID

func NewGroup

func NewGroup() *Group

NewGroup returns a new blank group.

func (*Group) DocType

func (g *Group) DocType() string

DocType returns the contact document type

func (*Group) GetAllContacts

func (g *Group) GetAllContacts(db prefixer.Prefixer) ([]*Contact, error)

GetAllContacts returns the list of contacts inside this group.

func (*Group) Name

func (g *Group) Name() string

Name returns the name of the group

Jump to

Keyboard shortcuts

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