self.updateSignalHandler = coroutines.CoTee()
- def update(self):
+ def update(self, force=False):
+ if not force and self._contacts:
+ return
oldContacts = self._contacts
oldContactIds = set(self.get_contacts())
if self._has_contact_changed(contactId, oldContacts)
)
- message = self, self._addedContacts, self._removedContacts, self._changedContacts
- self.updateSignalHandler.send(message)
+ if self._addedContacts or self._removedContacts or self._changedContacts:
+ message = self, self._addedContacts, self._removedContacts, self._changedContacts
+ self.updateSignalHandler.stage.send(message)
def get_contacts(self):
return self._contacts.iterkeys()
if self._contacts:
return
contacts = self._backend.get_contacts()
- for contactId, contactName in contacts:
- self._contacts[contactId] = (contactName, {})
+ for contactId, contactDetails in contacts:
+ contactName = contactDetails["name"]
+ contactNumbers = [
+ (numberDetails.get("phoneType", "Mobile"), numberDetails["phoneNumber"])
+ for numberDetails in contactDetails["numbers"]
+ ]
+ self._contacts[contactId] = (contactName, contactNumbers)
def _populate_contact_details(self, contactId):
if self._get_contact_details(contactId):
return
- self._get_contact_details(contactId).update(
+ self._get_contact_details(contactId).extend(
self._backend.get_contact_details(contactId)
)
oldContactDetails = oldContact[1]
if oldContactName != self.get_contact_name(contactId):
return True
- if not oldContactDetails[1]:
+ if not oldContactDetails:
return False
# if its already in the old cache, purposefully add it into the new cache
return oldContactDetails != self.get_contact_details(contactId)