store

package
v1.6.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	GroupRecordTypeGroupv1 = 0
	GroupRecordTypeGroupv2 = 1
)
View Source
const (
	SessionTypePrivateChat    int32 = 0
	SessionTypeGroupV1        int32 = 1
	SessionTypeGroupV2        int32 = 2
	SessionTypeGroupV2Invited int32 = 3
)

SessionTypes

View Source
const TIME_FORMAT = "2006-01-02 15:04:05 -0700 MST"

Variables

View Source
var (
	GroupJoinStatusJoined  = 0
	GroupJoinStatusInvited = 1
	GroupJoinStatusDeleted = 2
)
View Source
var ActiveSessionID int64

ActiveSessionID represents the currently opend chat

View Source
var AllGroups []*GroupRecord
View Source
var (
	GroupRecipientsID = -1
)
View Source
var GroupV2sModel = GroupV2s{
	Groups: []GroupV2{},
}
View Source
var Groups = map[string]*GroupRecord{}
View Source
var RecipientsModel = &Recipients{
	Recipients: make([]*Recipient, 0),
}
View Source
var SessionsV2Model = &SessionsV2{
	Sess: make([]*SessionV2, 0),
}

Functions

func AddDevice

func AddDevice(url string) error

func CopyAttachment

func CopyAttachment(src string) (string, error)

CopyAttachment makes a copy of a file that is in the volatile content hub cache

func DeleteGroup

func DeleteGroup(hexid string) error

DeleteGroup deletes a group from the database

func DeleteMessage

func DeleteMessage(id int64) error

func FindQuotedMessage added in v0.9.0

func FindQuotedMessage(quote *signalservice.DataMessage_Quote) (error, int64)

FindQuotedMessage searches the equivalent message of DataMessage_Quote in our DB and returns the local message id

func GetContactForTel

func GetContactForTel(tel string) *textsecureContacts.Contact

func GetContactForUUID added in v0.9.9

func GetContactForUUID(uuid string) *textsecureContacts.Contact

func GetUnreadMessageCounterForSession added in v1.6.0

func GetUnreadMessageCounterForSession(id int64) (int64, error)

GetUnreadMessageCounterForSession returns an int for the unread messages for a session

func GroupUpdateMsg

func GroupUpdateMsg(tels []string, title string) string

func IsEncrypted

func IsEncrypted(filename string) (bool, error)

IsEncrypted returns true, if the database with the given filename is encrypted, and false otherwise. If the database header cannot be read properly an error is returned.

func LoadGroups added in v0.7.5

func LoadGroups() error

func Migrate added in v1.6.0

func Migrate() error

func RefreshContacts

func RefreshContacts() error

func TelToName

func TelToName(tel string) string

func UpdateMessageRead

func UpdateMessageRead(m *Message) error

func UpdateMessageReceipt added in v0.9.0

func UpdateMessageReceipt(m *Message) error

func UpdateMessageReceiptSent added in v0.8.3

func UpdateMessageReceiptSent(m *Message) error

func UpdateMessageSent

func UpdateMessageSent(m *Message) error

func UpdateSessionTable_v_0_9_0 added in v0.9.0

func UpdateSessionTable_v_0_9_0() error

UpdateSessionTable_v_0_9_0 adds support for quoted messages

func UpdateSessionTable_v_0_9_5 added in v0.9.6

func UpdateSessionTable_v_0_9_5() error

UpdateSessionTable_v_0_9_5 adds support uuids

Types

type Attachment added in v0.8.0

type Attachment struct {
	File     string
	FileName string
	CType    int
}

func SaveAttachment

func SaveAttachment(a *textsecure.Attachment) (Attachment, error)

type Contacts

type Contacts struct {
	Contacts []textsecureContacts.Contact
	Len      int
}
var ContactsModel *Contacts = &Contacts{}

func (*Contacts) GetContact

func (c *Contacts) GetContact(i int) textsecureContacts.Contact

type DataStore

type DataStore struct {
	Dbx *sqlx.DB
}
var DS *DataStore

func NewDataStore

func NewDataStore(dbPath, saltPath, password string) (*DataStore, error)

func NewStorage

func NewStorage(password string) (*DataStore, error)

func (*DataStore) Convert

func (ds *DataStore) Convert(password string) error

func (*DataStore) DBX

func (ds *DataStore) DBX() *sqlx.DB

func (*DataStore) Decrypt

func (ds *DataStore) Decrypt(dbPath string) error

Decrypt database and closes connection

func (*DataStore) DecryptDb

func (ds *DataStore) DecryptDb(password string) bool

func (*DataStore) Encrypt

func (ds *DataStore) Encrypt(dbFile string, password string) error

func (*DataStore) EncryptDb

func (ds *DataStore) EncryptDb(password string) bool

func (*DataStore) ResetDb

func (ds *DataStore) ResetDb()

ResetDb removes the database file and resets the config for encrypted database.

func (*DataStore) SetupDb

func (ds *DataStore) SetupDb(password string) bool

SetupDb tries to decrypt the database and runs the migrations

type GroupRecord

type GroupRecord struct {
	ID         int64
	Uuid       string
	GroupID    string
	Name       string
	Members    string
	Avatar     []byte
	Active     bool
	Type       int
	JoinStatus int
}

func GetGroupById added in v0.7.5

func GetGroupById(hexid string) *GroupRecord

func SaveGroup

func SaveGroup(g *GroupRecord) (*GroupRecord, error)

type GroupV2 added in v1.6.0

type GroupV2 struct {
	Id                          string `json:"id" db:"id"`
	Name                        string `json:"name" db:"name"`
	MasterKey                   string `json:"master_key" db:"master_key"`
	Revision                    int    `json:"revision" db:"revision"`
	InviteLinkPassword          string `json:"invite_link_password" db:"invite_link_password"`
	AccessRequiredForAttributes int    `json:"access_required_for_attributes" db:"access_required_for_attributes"`
	AccessRequiredForMembers    int    `json:"access_required_for_members" db:"access_required_for_members"`
	JoinStatus                  int    `json:"join_status" db:"join_status"`
}

GroupV2 is a group, groupsv1 are deprecated

func (*GroupV2) AddGroupMembers added in v1.6.0

func (g *GroupV2) AddGroupMembers(members []*signalservice.DecryptedMember) error

func (*GroupV2) AddMember added in v1.6.0

func (g *GroupV2) AddMember(recipient *Recipient) error

AddMember adds a new member to a group for this recipient

func (*GroupV2) Delete added in v1.6.0

func (g *GroupV2) Delete() error

Delete deletes a group

func (*GroupV2) DeleteGroupMembers added in v1.6.0

func (g *GroupV2) DeleteGroupMembers(members [][]byte) error

func (*GroupV2) DeleteMember added in v1.6.0

func (g *GroupV2) DeleteMember(recipient *Recipient) error

DeleteMember deletes a member from a group

func (*GroupV2) DeleteMembers added in v1.6.0

func (g *GroupV2) DeleteMembers() error

DeleteMembers deletes all members of a group

func (*GroupV2) GetGroupMembers added in v1.6.0

func (g *GroupV2) GetGroupMembers() ([]GroupV2Member, error)

GetGroupMembers returns all members of a group

func (*GroupV2) GetGroupMembersAsRecipients added in v1.6.0

func (g *GroupV2) GetGroupMembersAsRecipients() ([]*Recipient, error)

GetGroupMembersAsRecipients returns the recipient records for all group members

func (*GroupV2) IsMember added in v1.6.0

func (g *GroupV2) IsMember(recipient *Recipient) bool

IsMember returns true if the user is a member of the group

func (*GroupV2) UpdateGroup added in v1.6.0

func (g *GroupV2) UpdateGroup() error

UpdateGroup updates a group

func (*GroupV2) UpdateGroupAction added in v1.6.0

func (g *GroupV2) UpdateGroupAction(action *signalservice.DecryptedGroupChange) error

UpdateGroupAction updates a group with a new action

func (*GroupV2) UpdateGroupMembers added in v1.6.0

func (g *GroupV2) UpdateGroupMembers(members []GroupV2Member) error

UpdateGroupMembers updates all group members

type GroupV2Member added in v1.6.0

type GroupV2Member struct {
	Id               int    `json:"id" db:"id"`
	GroupV2Id        string `json:"group_v2_id" db:"group_v2_id"`
	RecipientId      int    `json:"recipient_id" db:"recipient_id"`
	MemberSince      string `json:"member_since" db:"member_since"`
	JoinedAtRevision int    `json:"joined_at_revision" db:"joined_at_revision"`
	Role             int    `json:"role" db:"role"`
}

GroupV2Member represents a group member

type GroupV2s added in v1.6.0

type GroupV2s struct {
	Groups []GroupV2 `json:"groups"`
}

func (GroupV2s) Create added in v1.6.0

func (GroupV2s) Create(group *GroupV2) (*GroupV2, error)

func (GroupV2s) GetGroupById added in v1.6.0

func (GroupV2s) GetGroupById(id string) (*GroupV2, error)

GetGroupById returns a group by id

func (GroupV2s) GetGroups added in v1.6.0

func (GroupV2s) GetGroups() ([]GroupV2, error)

GetGroups returns all groups

type LinkedDevices

type LinkedDevices struct {
	LinkedDevices []textsecure.DeviceInfo
	Len           int
}
var LinkedDevicesModel *LinkedDevices = &LinkedDevices{}

func RefreshDevices

func RefreshDevices() (*LinkedDevices, error)

func (*LinkedDevices) DeleteDevice

func (c *LinkedDevices) DeleteDevice() error

func (*LinkedDevices) GetDevice

func (c *LinkedDevices) GetDevice(i int) textsecure.DeviceInfo

func (*LinkedDevices) RefreshDevices

func (c *LinkedDevices) RefreshDevices() error

func (*LinkedDevices) UnlinkDevice

func (c *LinkedDevices) UnlinkDevice(id int) error

type Message

type Message struct {
	ID            int64 `db:"id"`
	SID           int64
	ChatID        string
	Source        string `db:"source"`
	SourceUUID    string `db:"srcUUID"`
	Message       string
	Outgoing      bool
	SentAt        uint64
	ReceivedAt    uint64
	HTime         string
	CType         int
	Attachment    string
	IsSent        bool `db:"issent"`
	IsRead        bool `db:"isread"`
	Flags         int
	ExpireTimer   uint32 `db:"expireTimer"`
	SendingError  bool   `db:"sendingError"`
	Receipt       bool   `db:"receipt"`
	StatusMessage bool   `db:"statusMessage"`
	QuoteID       int64  `db:"quoteId"`
	QuotedMessage *Message
}

func FindOutgoingMessage added in v0.9.0

func FindOutgoingMessage(timestamp uint64) (*Message, error)

FindOutgoingMessage returns a message that is found by it's timestamp

func GetLastMessagesForAllSessions added in v1.6.0

func GetLastMessagesForAllSessions() ([]Message, error)

func GetMessageById added in v0.9.0

func GetMessageById(id int64) (*Message, error)

GetMessageById returns a message by it's ID

func SaveMessage

func SaveMessage(m *Message) (*Message, error)

func (*Message) GetName

func (m *Message) GetName() string

type MessageList

type MessageList struct {
	ID       int64
	Session  *SessionV2
	Messages []*Message
}

type Recipient added in v1.6.0

type Recipient struct {
	Id                     int64  `db:"id"`
	E164                   string `db:"e164"`
	UUID                   string `db:"uuid"`
	Username               string `db:"username"`
	Email                  string `db:"email"`
	IsBlocked              bool   `db:"is_blocked"`
	ProfileKey             []byte `db:"profile_key"`
	ProfileKeyCredential   []byte `db:"profile_key_credential"`
	ProfileGivenName       string `db:"profile_given_name"`
	ProfileFamilyName      string `db:"profile_family_name"`
	ProfileJoinedName      string `db:"profile_joined_name"`
	SignalProfileAvatar    string `db:"signal_profile_avatar"`
	ProfileSharingEnabled  bool   `db:"profile_sharing_enabled"`
	LastProfileFetch       string `db:"last_profile_fetch"`
	UnidentifiedAccessMode bool   `db:"unidentified_access_mode"`
	StorageServiceId       []byte `db:"storage_service_id"`
	StorageProto           []byte `db:"storage_proto"`
	Capabilities           int    `db:"capabilities"`
	LastSessionReset       string `db:"last_session_reset"`
	About                  string `db:"about"`
	AboutEmoji             string `db:"about_emoji"`
}

func (*Recipient) SaveRecipient added in v1.6.0

func (r *Recipient) SaveRecipient() error

SaveRecipient saves a recipient

func (*Recipient) UpdateProfile added in v1.6.0

func (r *Recipient) UpdateProfile() error

UpdateProfile updates a recipient's profile

type Recipients added in v1.6.0

type Recipients struct {
	Recipients []*Recipient `db:"recipients"`
}

func (*Recipients) CreateRecipient added in v1.6.0

func (r *Recipients) CreateRecipient(recipient *Recipient) (*Recipient, error)

CreateRecipient creates a recipient

func (*Recipients) CreateRecipientWithoutProfileUpdate added in v1.6.0

func (r *Recipients) CreateRecipientWithoutProfileUpdate(recipient *Recipient) (*Recipient, error)

CreateRecipientWithoutProfileUpdate is only used in the v1.6.0 migration because we migrate before we initialize the signal server

func (*Recipients) GetOrCreateRecipient added in v1.6.0

func (r *Recipients) GetOrCreateRecipient(uuid string) *Recipient

GetOrCreateRecipient returns a recipient by uuid or creates a new one

func (*Recipients) GetOrCreateRecipientForContact added in v1.6.0

func (r *Recipients) GetOrCreateRecipientForContact(contact *contacts.Contact) *Recipient

GetOrCreateRecipientForContact returns a recipient for a contact

func (*Recipients) GetRecipientByE164 added in v1.6.0

func (*Recipients) GetRecipientByE164(e164 string) *Recipient

GetRecipientByE164 returns a recipient by e164

func (*Recipients) GetRecipientById added in v1.6.0

func (*Recipients) GetRecipientById(id int64) *Recipient

GetRecipientById returns a recipient by id

func (*Recipients) GetRecipientByUUID added in v1.6.0

func (*Recipients) GetRecipientByUUID(uuid string) *Recipient

GetRecipientByUUID returns a recipient by uuid

type Session

type Session struct {
	ID              int64
	UUID            string `db:"uuid"`
	Name            string
	Tel             string
	IsGroup         bool  `db:"isgroup"`
	Type            int32 // describes the type of the session, wether it's a private conversation or groupv1 or groupv2
	Last            string
	Timestamp       uint64
	When            string
	CType           int
	Messages        []*Message
	Unread          int
	Active          bool
	Len             int
	Notification    bool
	ExpireTimer     uint32 `db:"expireTimer"`
	GroupJoinStatus int    `db:"groupJoinStatus"`
}

Session is Deprecated: use store.SessionsV2Model instead It used to define how a session looks like

type SessionV2 added in v1.6.0

type SessionV2 struct {
	ID                       int64  `db:"id"`
	DirectMessageRecipientID int64  `db:"directMessageRecipientId"`
	ExpireTimer              int64  `db:"expireTimer"`
	IsArchived               bool   `db:"isArchived"`
	IsBlocked                bool   `db:"isBlocked"`
	IsPinned                 bool   `db:"isPinned"`
	IsSilenced               bool   `db:"isSilenced"`
	IsMuted                  bool   `db:"isMuted"`
	Draft                    string `db:"draft"`
	GroupV2ID                string `db:"groupV2Id"`
	GroupV1ID                string `db:"groupV1Id"`
	UnreadCounter            int64  `db:"unreadCounter"`
}

func (*SessionV2) GetMessageList added in v1.6.0

func (s *SessionV2) GetMessageList(limit int, offset int) ([]*Message, error)

GetMessageList returns a list of messages for a session

func (*SessionV2) GetName added in v1.6.0

func (s *SessionV2) GetName() (string, error)

GetName returns the name of the session

func (*SessionV2) IsGroup added in v1.6.0

func (s *SessionV2) IsGroup() bool

IsGroup returns true if the session is a group session

func (*SessionV2) MarkRead added in v1.6.0

func (s *SessionV2) MarkRead() error

MarkRead marks a session as read

func (*SessionV2) NotificationsToggle added in v1.6.0

func (s *SessionV2) NotificationsToggle() error

NotificationsToggle toggles the notifications for a session

type SessionV2Name added in v1.6.0

type SessionV2Name struct {
	ID   int64  `db:"id"`
	Name string `db:"name"`
}

type Sessions

type Sessions struct {
	Sess       []*Session
	ActiveChat string
	Len        int
	Type       string
}

type SessionsV2 added in v1.6.0

type SessionsV2 struct {
	Sess []*SessionV2
}

func (*SessionsV2) CreateSession added in v1.6.0

func (s *SessionsV2) CreateSession(session *SessionV2) (*SessionV2, error)

CreateSession inserts this session into the database

func (*SessionsV2) CreateSessionForDirectMessageRecipient added in v1.6.0

func (s *SessionsV2) CreateSessionForDirectMessageRecipient(recipient int64) (*SessionV2, error)

CreateSessionForDirectMessageRecipient creates a session for a direct message (one to one)

func (*SessionsV2) CreateSessionForGroupV1 added in v1.6.0

func (s *SessionsV2) CreateSessionForGroupV1(group string) (*SessionV2, error)

CreateSessionForGroupV1 creates a session for a group v1

func (*SessionsV2) CreateSessionForGroupV2 added in v1.6.0

func (s *SessionsV2) CreateSessionForGroupV2(groupID string) (*SessionV2, error)

CreateSessionForGroupV2 creates a session for a group v2

func (*SessionsV2) DeleteAllSessions added in v1.6.0

func (*SessionsV2) DeleteAllSessions() error

DeleteAllSessions deletes all sessions

func (*SessionsV2) DeleteSession added in v1.6.0

func (*SessionsV2) DeleteSession(session *SessionV2) error

DeleteSession deletes a session

func (*SessionsV2) GetAllSessions added in v1.6.0

func (*SessionsV2) GetAllSessions() ([]*SessionV2, error)

GetAllSessions returns all sessions

func (*SessionsV2) GetMoreMessageList added in v1.6.0

func (s *SessionsV2) GetMoreMessageList(ID int64, sentAt uint64) (*MessageList, error)

GetMoreMessageList loads more messages from before the timestamp sentAt

func (*SessionsV2) GetOrCreateSessionForDirectMessageRecipient added in v1.6.0

func (s *SessionsV2) GetOrCreateSessionForDirectMessageRecipient(recipient int64) (*SessionV2, error)

GetOrCreateSessionForDirectMessageRecipient returns a session for a direct message (one to one)

func (*SessionsV2) GetOrCreateSessionForGroupV2ID added in v1.6.0

func (s *SessionsV2) GetOrCreateSessionForGroupV2ID(group string) (*SessionV2, error)

GetOrCreateSessionForGroupV2ID returns a session for a group v2 id

func (*SessionsV2) GetSessionByDirectMessageRecipientID added in v1.6.0

func (*SessionsV2) GetSessionByDirectMessageRecipientID(recipient int64) (*SessionV2, error)

GetSessionByDirectMessageRecipientID returns a session by direct message recipient id

func (*SessionsV2) GetSessionByGroupV1ID added in v1.6.0

func (*SessionsV2) GetSessionByGroupV1ID(group string) (*SessionV2, error)

GetSessionByGroupV1ID returns a session by group v1 id

func (*SessionsV2) GetSessionByGroupV2ID added in v1.6.0

func (*SessionsV2) GetSessionByGroupV2ID(group string) (*SessionV2, error)

GetSessionByGroupV2ID returns a session by group v2 id

func (*SessionsV2) GetSessionByID added in v1.6.0

func (*SessionsV2) GetSessionByID(id int64) (*SessionV2, error)

GetSessionByID returns a session by id

func (*SessionsV2) GetSessionNames added in v1.6.0

func (s *SessionsV2) GetSessionNames() ([]SessionV2Name, error)

GetSessionNames returns all session names

func (*SessionsV2) SaveSession added in v1.6.0

func (*SessionsV2) SaveSession(session *SessionV2) (*SessionV2, error)

SaveSession saves a session to the database

func (*SessionsV2) UpdateAllUnreadCountersForSessions added in v1.6.0

func (s *SessionsV2) UpdateAllUnreadCountersForSessions() error

UpdateAllUnreadCountersForSessions updates all unread counters for all sessions

func (*SessionsV2) UpdateUnreadCounterForSession added in v1.6.0

func (*SessionsV2) UpdateUnreadCounterForSession(session *SessionV2) error

UpdateUnreadCounterForSession updates the unread counter for a session

Jump to

Keyboard shortcuts

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