Fixing initial display of letter count
[gc-dialer] / src / backends / gv_backend.py
index 49294e7..e820ffb 100644 (file)
@@ -41,8 +41,6 @@ class GVDialer(object):
        def __init__(self, cookieFile = None):
                self._gvoice = gvoice.GVoiceBackend(cookieFile)
 
-               self._contacts = None
-
        def is_quick_login_possible(self):
                """
                @returns True then is_authed might be enough to login, else full login is required
@@ -67,6 +65,9 @@ class GVDialer(object):
        def logout(self):
                return self._gvoice.logout()
 
+       def persist(self):
+               return self._gvoice.persist()
+
        def is_dnd(self):
                return self._gvoice.is_dnd()
 
@@ -145,46 +146,27 @@ class GVDialer(object):
                """
                @returns Iterable of (personsName, phoneNumber, exact date, relative date, action)
                """
-               return self._gvoice.get_recent()
+               return list(self._gvoice.get_recent())
 
        def get_contacts(self):
                """
-               @returns Iterable of (contact id, contact name)
-               """
-               self._update_contacts_cache()
-               contactsToSort = [
-                       (contactDetails["name"], contactId)
-                       for contactId, contactDetails in self._contacts.iteritems()
-               ]
-               contactsToSort.sort()
-               return (
-                       (contactId, contactName)
-                       for (contactName, contactId) in contactsToSort
-               )
-
-       def get_contact_details(self, contactId):
-               """
-               @returns Iterable of (Phone Type, Phone Number)
+               @returns Fresh dictionary of items
                """
-               if self._contacts is None:
-                       self._update_contacts_cache()
-               contactDetails = self._contacts[contactId]
-               # Defaulting phoneTypes because those are just things like faxes
-               return (
-                       (number.get("phoneType", ""), number["phoneNumber"])
-                       for number in contactDetails["numbers"]
-               )
+               return dict(self._gvoice.get_contacts())
 
        def get_messages(self):
+               return list(self._get_messages())
+
+       def _get_messages(self):
                voicemails = self._gvoice.get_voicemails()
                smss = self._gvoice.get_texts()
                conversations = itertools.chain(voicemails, smss)
                for conversation in conversations:
                        messages = conversation.messages
-                       messageParts = (
+                       messageParts = [
                                (message.whoFrom, self._format_message(message), message.when)
                                for message in messages
-                       )
+                       ]
 
                        messageDetails = {
                                "id": conversation.id,
@@ -224,9 +206,6 @@ class GVDialer(object):
        def factory_name():
                return "Google Voice"
 
-       def _update_contacts_cache(self):
-               self._contacts = dict(self._gvoice.get_contacts())
-
        def _format_message(self, message):
                messagePartFormat = {
                        "med1": "<i>%s</i>",