Making it possible to do partial message refreshes
authorEd Page <eopage@byu.net>
Sun, 27 Feb 2011 00:05:19 +0000 (18:05 -0600)
committerEd Page <eopage@byu.net>
Tue, 19 Apr 2011 23:49:27 +0000 (18:49 -0500)
src/backends/gv_backend.py
src/session.py

index a6da313..2414049 100644 (file)
@@ -40,8 +40,14 @@ _moduleLogger = logging.getLogger(__name__)
 
 class GVDialer(object):
 
+       MESSAGE_TEXTS = "Text"
+       MESSAGE_VOICEMAILS = "Voicemail"
+       MESSAGE_ALL = "All"
+
        def __init__(self, cookieFile = None):
                self._gvoice = gvoice.GVoiceBackend(cookieFile)
+               self._texts = []
+               self._voicemails = []
 
        def is_quick_login_possible(self):
                """
@@ -145,14 +151,19 @@ class GVDialer(object):
                """
                return list(self._gvoice.get_recent())
 
-       def get_messages(self):
-               messages = list(self._get_messages())
+       def get_messages(self, messageType):
+               messages = list(self._get_messages(messageType))
                messages.sort(key=lambda message: message["time"])
                return messages
 
-       def _get_messages(self):
-               voicemails = self._gvoice.get_voicemails()
-               smss = self._gvoice.get_texts()
+       def _get_messages(self, messageType):
+               if messageType in [self.MESSAGE_VOICEMAILS, self.MESSAGE_ALL] or not self._voicemails:
+                       self._voicemails = list(self._gvoice.get_voicemails())
+               voicemails = self._voicemails
+               if messageType in [self.MESSAGE_TEXTS, self.MESSAGE_ALL] or not self._texts:
+                       self._texts = list(self._gvoice.get_texts())
+               smss = self._texts
+
                conversations = itertools.chain(voicemails, smss)
                for conversation in conversations:
                        messages = conversation.messages
index e6cd68f..bc682f7 100644 (file)
@@ -609,7 +609,7 @@ class Session(QtCore.QObject):
                        with qui_utils.notify_busy(self._errorLog, "Updating Messages"):
                                self._messages = yield (
                                        self._backend[0].get_messages,
-                                       (),
+                                       (self._backend[0].MESSAGE_ALL, ),
                                        {},
                                )
                except Exception, e: