model

package
v0.0.0-...-ab76223 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeliveryStatus map[bool]string = map[bool]string{
	// contains filtered or unexported fields
}
View Source
var ReadStatus map[bool]string = map[bool]string{
	// contains filtered or unexported fields
}

Functions

func ConfigPath

func ConfigPath() string

ConfigPath returns the config file path

func ConversationFolder

func ConversationFolder() string

ConversationFolder returns the folder where conversations are saved

func FindConfigFolder

func FindConfigFolder() string

FindConfigFolder returns $XDG_CONFIG_HOME/siggo/ if it exists, otherwise returns $HOME/.config/siggo/

func FindDataFolder

func FindDataFolder() string

FindDataFolder returns $XDG_DATA_HOME if it exists, otherwise returns $HOME/.local/share/siggo/

func LogPath

func LogPath() string

LogPath returns the log file path

Types

type Attachment

type Attachment struct {
	ContentType string `json:"contentType"`
	Filename    string `json:"filename"`
	ID          string `json:"id"`
	Size        int    `json:"size"`
	Timestamp   int64  `json:"timestamp"`
	FromSelf    bool   `json:"from_self"`
}

Attachment is any file sent or received. Received attachments are left in the usual `signal-cli` location for now. It seems to automatically delete old attachments, so we may want to come up with a way to keep our own copy somewhere in the siggo data folder.

func ConvertAttachments

func ConvertAttachments(wire []*signal.Attachment, timestamp int64, fromSelf bool) []*Attachment

ConvertAttachments converts signal's wire attachments into our model's attachments

func NewAttachmentFromWire

func NewAttachmentFromWire(wire *signal.Attachment, timestamp int64, fromSelf bool) *Attachment

NewAttachmentFromWire creates a new siggo attachment from a signal.Attachment

func (*Attachment) Path

func (a *Attachment) Path() (string, error)

Path returns the full path to an attachment file

func (*Attachment) String

func (a *Attachment) String() string

String returns the string representation of the attachment

type Config

type Config struct {
	UserNumber string `yaml:"user_number"`
	UserName   string `yaml:"user_name"`
	// SaveMessages enables message saving. You will still load any (previously) saved messages
	// at startup.
	SaveMessages bool `yaml:"save_messages"`
	// Attempt to send desktop notifications
	DesktopNotifications            bool `yaml:"desktop_notifications"`
	DesktopNotificationsShowMessage bool `yaml:"desktop_notifications_show_message"`
	DesktopNotificationsShowAvatar  bool `yaml:"desktop_notifications_show_avatar"`
	// Terminal bell
	TerminalBellNotifications bool `yaml:"terminal_bell_notifications"`
	// doesn't do anything yet
	MaxConversationLength int               `yaml:"max_coversation_length"`
	HidePanelTitles       bool              `yaml:"hide_panel_titles"`
	HidePhoneNumbers      bool              `yaml:"hide_phone_numbers"`
	ContactColors         map[string]string `yaml:"contact_colors"`
	ContactAliases        map[string]string `yaml:"contact_aliases"`

	// No rotation provided, use at your own risk!
	LogFilePath string `yaml:"log_file"`
}

Config includes both siggo and UI config

func DefaultConfig

func DefaultConfig() *Config

func GetConfig

func GetConfig() (*Config, error)

GetConfig returns the current configuration from the default config location, creates a new one if it isn't there

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads the config located @ `path`

func NewConfigFile

func NewConfigFile(path string) (*Config, error)

NewConfigFile makes a new config file at `path` and returns the default config.

func (*Config) Print

func (c *Config) Print()

Print pretty-prints the configuration

func (*Config) Save

func (c *Config) Save() error

Save saves the config to the default location

func (*Config) SaveAs

func (c *Config) SaveAs(path string) error

SaveAs writes the config to `path`

type Contact

type Contact struct {
	Number PhoneNumber
	Name   string
	Index  int
	// contains filtered or unexported fields
}

func (*Contact) Avatar

func (c *Contact) Avatar() string

Avatar returns the path to the contact's avatar, if it can find it, otherwise ""

func (*Contact) Color

func (c *Contact) Color() string

Color returns the configured color highlight for incoming messages

func (*Contact) Configure

func (c *Contact) Configure(cfg *Config)

Configure applies a configuration to the contact (for now, an alias and custom color)

func (*Contact) String

func (c *Contact) String() string

String returns a string to display for this contact. Priority is Alias > Name > Number. Groups get a cute little # indicator.

type ContactList

type ContactList map[PhoneNumber]*Contact

func (ContactList) AllNames

func (cl ContactList) AllNames() []string

AllNames returns a slice of all aliases and names in the entire contact list

func (ContactList) FindContact

func (cl ContactList) FindContact(pattern string) *Contact

FindContact searches the contact list for the first contact whose name matches the supplied pattern. Returns nil if no match is found.

func (ContactList) List

func (cl ContactList) List() []*Contact

List returns a list of contacts (in random order)

func (ContactList) SortedByIndex

func (cl ContactList) SortedByIndex() []*Contact

SortedByIndex returns a slice of contacts sorted by index provided by signal-cli

func (ContactList) SortedByName

func (cl ContactList) SortedByName() []*Contact

SortedByName returns a slice of contacts sorted alphabetically

func (ContactList) SortedByNumber

func (cl ContactList) SortedByNumber() []*Contact

SortedByNumber returns a slice of contacts sorted by phone number Idk why anyone would ever want to use this but here it is.

func (ContactList) StringSlice

func (cl ContactList) StringSlice() []string

StringSlice returns the contact list as a string slice

type ConvInfo

type ConvInfo map[*Contact]*Conversation

type Conversation

type Conversation struct {
	Contact       *Contact // can be a group!
	Messages      map[int64]*Message
	MessageOrder  []int64
	HasNewMessage bool
	StagedMessage string
	// contains filtered or unexported fields
}

Coversation is a contact or group and its associated messages

func NewConversation

func NewConversation(contact *Contact) *Conversation

func (*Conversation) AddAttachment

func (c *Conversation) AddAttachment(path string) error

StageAttachment attaches a file to be sent in the next message

func (*Conversation) AddMessage

func (c *Conversation) AddMessage(message *Message)

AddMessage appends a message to the conversation

func (*Conversation) CaughtUp

func (c *Conversation) CaughtUp()

CaughtUp iterates back through the messages of the conversation marking the un-read ones as read. We call this after we switch to this conversation.

func (*Conversation) ClearAttachments

func (c *Conversation) ClearAttachments()

ClearAttachments removes any staged attachments

func (*Conversation) ClearStaged

func (c *Conversation) ClearStaged()

ClearStaged clears any staged message or attachment

func (*Conversation) ClearStagedMessage

func (c *Conversation) ClearStagedMessage()

ClearStagedMessage removes any staged attachments

func (*Conversation) Filter

func (c *Conversation) Filter(pattern string) string

Filter redners the conversation, but filters out any messages that don't have a regex match TODO: eliminate code duplication with String()

func (*Conversation) HasStagedData

func (c *Conversation) HasStagedData() bool

HasStagedData returns whether the conversation has a staged message or attachment

func (*Conversation) HasStagedMessage

func (c *Conversation) HasStagedMessage() bool

HasStagedMessage returns whether the conversation has a staged message

func (*Conversation) LastMessage

func (c *Conversation) LastMessage() *Message

LastMessage returns the most recent message. Can be nil.

func (*Conversation) Load

func (c *Conversation) Load(path string, cfg *Config) error

Load will load a conversation saved @ `path` TODO: load only the last N messages based on config HERE IS WHERE THE COLOR THE LOADED MESSAGES

func (*Conversation) NumAttachments

func (c *Conversation) NumAttachments() int

NumAttachments returns the number of staged attachments

func (*Conversation) Save

func (c *Conversation) Save() error

Save writes the conversation to the default location only if it has new data

func (*Conversation) SaveAs

func (c *Conversation) SaveAs(path string) error

SaveAs writes the conversation to `path`.

func (*Conversation) String

func (c *Conversation) String() string

String renders the conversation to a single string

type Message

type Message struct {
	Content     string        `json:"content"`
	Timestamp   int64         `json:"timestamp"`
	IsDelivered bool          `json:"is_delivered"`
	IsRead      bool          `json:"is_read"`
	FromSelf    bool          `json:"from_self"`
	Attachments []*Attachment `json:"attachments"`
	From        string        `json:from"`
	FromContact *Contact      `json:from_contact"`
}

func (*Message) AddAttachments

func (m *Message) AddAttachments(paths []string)

AddAttachments currently only is used to track attachments we sent to other people, so that they show up in the GUI.

func (*Message) String

func (m *Message) String() string

type PhoneNumber

type PhoneNumber = string

PhoneNumber is an alias for string not derived

type Siggo

type Siggo struct {
	NewInfo    func(*Conversation)
	ErrorEvent func(error)
	// contains filtered or unexported fields
}

func NewSiggo

func NewSiggo(sig SignalAPI, config *Config) *Siggo

NewSiggo creates a new model

func (*Siggo) Config

func (s *Siggo) Config() Config

Config returns a copy of the current configuration

func (*Siggo) Contacts

func (s *Siggo) Contacts() ContactList

Contacts returns the current contact list

func (*Siggo) Conversations

func (s *Siggo) Conversations() map[*Contact]*Conversation

Conversations returns the current converstation book

func (*Siggo) Quit

func (s *Siggo) Quit()

Quit does any cleanup we want to do at exit.

func (*Siggo) Receive

func (s *Siggo) Receive() error

Receive

func (*Siggo) ReceiveForever

func (s *Siggo) ReceiveForever()

ReceiveForever waits until initialzation is complete, then starts the daemon.

func (*Siggo) SaveConversations

func (s *Siggo) SaveConversations()

SaveConversations saves all conversations to disk

func (*Siggo) Send

func (s *Siggo) Send(msg string, contact *Contact) error

Send sends a message to a contact.

type SignalAPI

type SignalAPI interface {
	Send(string, string) (int64, error)
	SendDbus(string, string, ...string) (int64, error)
	SendGroupDbus(string, string, ...string) (int64, error)
	Receive() error
	RequestGroupInfo() ([]signal.SignalGroupInfo, error)
	ReceiveForever()
	Close()
	OnReceived(signal.ReceivedCallback)
	OnReceipt(signal.ReceiptCallback)
	OnSent(signal.SentCallback)
	OnError(signal.ErrorCallback)
}

Jump to

Keyboard shortcuts

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