Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
Fix counting registered contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
aebruno committed Feb 22, 2017
1 parent f360ee6 commit c0bf38d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion model/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func (c *Contact) init() {
return c.contactStore.FindName(tel)
})
c.ConnectTotal(func() int {
return c.contactStore.Len()
if !c.settings.GetBool("share_contacts") {
return 0
}

return c.contactStore.RegisteredContacts()
})
c.ConnectRefresh(func() {
c.contactStore.Refresh(c.settings.GetString("country_code"))
Expand Down
22 changes: 22 additions & 0 deletions store/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ func (c *Contact) Len() int {
return len(c.contacts)
}

func (c *Contact) RegisteredContacts() int {
contacts, err := textsecure.GetRegisteredContacts()
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Error("Failed to fetch signal contacts")
return 0
}

count := 0
for _, l := range c.contacts {
for _, r := range contacts {
if l.Tel == r.Tel {
count++
break
}
}
}

return count
}

func (c *Contact) Refresh(country string) {
contacts, err := SailfishContacts(country)
if err != nil {
Expand Down

0 comments on commit c0bf38d

Please sign in to comment.