From c0bf38d8bc8b0ef13c9d2c5d15796e91f3f8862b Mon Sep 17 00:00:00 2001 From: "Andrew E. Bruno" Date: Mon, 20 Feb 2017 18:45:30 -0500 Subject: [PATCH] Fix counting registered contacts --- model/contact.go | 6 +++++- store/contact.go | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/model/contact.go b/model/contact.go index bd50f1571..8d673304b 100644 --- a/model/contact.go +++ b/model/contact.go @@ -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")) diff --git a/store/contact.go b/store/contact.go index 88cd5cf21..1bdef5c43 100644 --- a/store/contact.go +++ b/store/contact.go @@ -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 {