Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Feature/0.8.2 support (#47)
Browse files Browse the repository at this point in the history
* support for recipients-store in signal-cli 0.8.2

* no longer can use inboxPosition

* bumped signal-cli version req to 0.8.2
  • Loading branch information
derricw authored Jul 31, 2021
1 parent 42242f4 commit 1f5914b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A terminal ui for signal-cli, written in Go.

### Dependencies

* [signal-cli](https://github.com/AsamK/signal-cli). (>=0.7.4)
* [signal-cli](https://github.com/AsamK/signal-cli). (>=0.8.2)

siggo uses the dbus daemon feature of signal-cli, so `libunixsocket-java` (Debian), `libmatthew-java` (Fedora) or `libmatthew-unix-java` (AUR) is required. There seems to be a `brew` [forumla](https://formulae.brew.sh/formula/dbus) for dbus on MacOS.

Expand Down
38 changes: 17 additions & 21 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,28 +849,24 @@ func (s *Siggo) getContacts() ContactList {
return list
}
for _, c := range contacts {
if c.InboxPosition != nil {
// strip the weird-ass unicode that we seem to be reading
// for some unknown reason
name := strings.Trim(c.Name, "\u2068\u2069")
alias := ""
if s.config.ContactAliases != nil {
alias = s.config.ContactAliases[name]
}
// check if we have a color for this contact
color := s.config.ContactColors[name]
contact := &Contact{
Number: c.Number,
Name: name,
Index: *c.InboxPosition,
alias: alias,
color: color,
}
list[c.Number] = contact
if *c.InboxPosition > highestIndex {
highestIndex = *c.InboxPosition
}
// strip the weird-ass unicode that we seem to be reading
// for some unknown reason
name := strings.Trim(c.Name, "\u2068\u2069")
alias := ""
if s.config.ContactAliases != nil {
alias = s.config.ContactAliases[name]
}
// check if we have a color for this contact
color := s.config.ContactColors[name]
contact := &Contact{
Number: c.Number,
Name: name,
Index: highestIndex,
alias: alias,
color: color,
}
list[c.Number] = contact
highestIndex++
}

// get all groups from disk
Expand Down
80 changes: 78 additions & 2 deletions signal/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func GetSignalAvatarsFolder() (string, error) {
}

// SignalContact is the data signal-cli saves for each contact
// in SignalDataDir/<phonenumber>
// in SignalDataDir/<phonenumber>.
// This structure no longer exists as of signal-cli >= 0.8.2
type SignalContact struct {
Name string `json:"name"`
Number string `json:"number"`
Expand All @@ -57,6 +58,48 @@ type SignalContact struct {
Archived bool `json:"archived"`
}

// SignalRecipient is the format used in the `recipients-store` file.
type SignalRecipient struct {
ID int `json:"id"`
Number string `json:"number"`
UUID string `json:"uuid"`
Profile interface{} `json:"profile"`
ProfileKey string `json:"profileKey"`
ProfileKeyCredential interface{} `json:"profileKeyCredential"`
Contact struct {
Name string `json:"name"`
Color string `json:"color"`
MessageExpirationTime int `json:"messageExpirationTime"`
Blocked bool `json:"blocked"`
Archived bool `json:"archived"`
} `json:"contact"`
}

func (r *SignalRecipient) AsContact() *SignalContact {
return &SignalContact{
Name: r.Contact.Name,
Number: r.Number,
Color: r.Contact.Color,
MessageExpirationTime: r.Contact.MessageExpirationTime,
ProfileKey: r.ProfileKey,
Blocked: r.Contact.Blocked,
Archived: r.Contact.Archived,
}
}

// SignalRecipientStore
type SignalRecipientStore struct {
Recipients []*SignalRecipient `json:"recipients"`
}

func (r *SignalRecipientStore) AsContacts() []*SignalContact {
contacts := make([]*SignalContact, 0)
for _, c := range r.Recipients {
contacts = append(contacts, c.AsContact())
}
return contacts
}

// SignalGroup is the data that signal-cli saves for each group
// in SignalDataDir/<phonenumber>
type SignalGroup struct {
Expand Down Expand Up @@ -352,6 +395,7 @@ func (s *Signal) Link(deviceName string) error {
}

// GetUserData returns the user data for the current user.
// this is where the contact list is kept for signal-cli < 0.8.2
func (s *Signal) GetUserData() (*SignalUserData, error) {
usr, err := user.Current()
if err != nil {
Expand All @@ -370,13 +414,45 @@ func (s *Signal) GetUserData() (*SignalUserData, error) {
return userData, nil
}

// GetRecipientStore gets the recipient store. This is where the contacts list is kept in
// signal-cli >= 0.8.2
func (s *Signal) GetRecipientStore() (*SignalRecipientStore, error) {
usr, err := user.Current()
if err != nil {
return nil, err
}
homeDir := usr.HomeDir
dataFile := fmt.Sprintf("%s/%s/%s.d/recipients-store", homeDir, SignalDataDir, s.uname)
b, err := ioutil.ReadFile(dataFile)
if err != nil {
return nil, err
}
store := &SignalRecipientStore{}
if err = json.Unmarshal(b, store); err != nil {
return nil, err
}
return store, nil
}

// GetContactList attempts to read an existing contact list from the signal user directory.
func (s *Signal) GetContactList() ([]*SignalContact, error) {
userData, err := s.GetUserData()
if err != nil {
return nil, err
}
return userData.ContactStore.Contacts, nil
c := userData.ContactStore.Contacts
if len(c) > 0 {
// contacts stored in user data
// signal-cli <=0.8.1
return c, nil
}

recipients, err := s.GetRecipientStore()
if err != nil {
return nil, err
}
// recipients stored in `recipients-store` file
return recipients.AsContacts(), nil
}

// GetGroupList attempts to read an existing contact list from the signal user directory.
Expand Down

0 comments on commit 1f5914b

Please sign in to comment.