Bug fixes, code cleanup, debugging help all working together to make it so that I...
authorEd Page <eopage@byu.net>
Tue, 22 Dec 2009 01:02:58 +0000 (19:02 -0600)
committerEd Page <eopage@byu.net>
Tue, 22 Dec 2009 01:02:58 +0000 (19:02 -0600)
src/channel/text.py
src/connection.py
src/connection_manager.py
src/gvoice/conversations.py
src/gvoice/session.py
src/gvoice/state_machine.py
src/telepathy-theonering

index 4ad3fcb..37d3f6f 100644 (file)
@@ -48,6 +48,7 @@ class TextChannel(telepathy.server.ChannelTypeText):
                        raise telepathy.errors.NotImplemented("Unhandled message type: %r" % messageType)
 
                self._conn.session.backend.send_sms(self._otherHandle.phoneNumber, text)
+               self._conn.session.stateMachine.reset_timers()
 
                self.Sent(int(time.time()), messageType, text)
 
index 69ed50c..dc2c0b2 100644 (file)
@@ -219,6 +219,5 @@ class TheOneRingConnection(
                channelManager = self._channelManager
                for contactId, phoneNumber in conversationIds:
                        h = handle.create_handle(self, 'contact', contactId, phoneNumber)
-                       # if its new, __init__ will take care of things
-                       # if its old, its own update will take care of it
+                       # Just let the TextChannel decide whether it should be reported to the user or not
                        channel = channelManager.channel_for_text(h)
index ec64b0f..b392555 100644 (file)
@@ -1,9 +1,10 @@
 """
 Empathy Experience:
        .profile file needs to be updated with proper presence
-       Did not properly merge old conversation with an updated one
        Can't reopen a conversation for someone when I've already closed it
        Can't call
+       When first started, reports all read conversations when some might have been read
+       When first started, reports all of an SMS conversation even though some has been reported previously
 """
 
 import logging
index 10b11e0..4541608 100644 (file)
@@ -37,7 +37,8 @@ class Conversations(object):
                        try:
                                mergedConversations.append_conversation(conversation)
                                isConversationUpdated = True
-                       except RuntimeError:
+                       except RuntimeError, e:
+                               _moduleLogger.info("Skipping conversation for %r because '%s'" % (key, e))
                                isConversationUpdated = False
 
                        if isConversationUpdated:
@@ -70,7 +71,9 @@ class MergedConversations(object):
 
        def append_conversation(self, newConversation):
                self._validate(newConversation)
-               self._remove_repeats(newConversation)
+               for similarConversation in self._find_related_conversation(newConversation.id):
+                       self._update_previous_related_conversation(similarConversation, newConversation)
+                       self._remove_repeats(similarConversation, newConversation)
                self._conversations.append(newConversation)
 
        @property
@@ -90,21 +93,30 @@ class MergedConversations(object):
                if newConversation.time <= self._conversations[-1].time:
                        raise RuntimeError("Conversations got out of order")
 
-       def _remove_repeats(self, newConversation):
-               similarConversations = [
+       def _find_related_conversation(self, convId):
+               similarConversations = (
                        conversation
                        for conversation in self._conversations
-                       if conversation.id == newConversation.id
+                       if conversation.id == convId
+               )
+               return similarConversations
+
+       def _update_previous_related_conversation(self, relatedConversation, newConversation):
+               for commonField in ("isRead", "isSpam", "isTrash", "isArchived"):
+                       newValue = getattr(newConversation, commonField)
+                       setattr(relatedConversation, commonField, newValue)
+
+       def _remove_repeats(self, relatedConversation, newConversation):
+               newConversationMessages = newConversation.messages
+               newConversation.messages = [
+                       newMessage
+                       for newMessage in newConversationMessages
+                       if newMessage not in relatedConversation.messages
                ]
-
-               for similarConversation in similarConversations:
-                       for commonField in ("isRead", "isSpam", "isTrash", "isArchived"):
-                               newValue = getattr(newConversation, commonField)
-                               setattr(similarConversation, commonField, newValue)
-
-                       newConversation.messages = [
-                               newMessage
-                               for newMessage in newConversation.messages
-                               if newMessage not in similarConversation.messages
-                       ]
-                       assert 0 < len(newConversation.messages), "Everything shouldn't have been removed"
+               _moduleLogger.info("Found %d new messages in conversation %s (%d/%d)" % (
+                       len(newConversationMessages) - len(newConversation.messages),
+                       newConversation.id,
+                       len(newConversation.messages),
+                       len(newConversationMessages),
+               ))
+               assert 0 < len(newConversation.messages), "Everything shouldn't have been removed"
index 1f52bf9..d87f7ad 100644 (file)
@@ -81,3 +81,7 @@ class Session(object):
                Delay initialized addressbook
                """
                return self._conversations
+
+       @property
+       def stateMachine(self):
+               return self._stateMachine
index 2fb1d01..6e7d288 100644 (file)
@@ -101,6 +101,7 @@ class StateMachine(object):
                nextTimeout = int(nextTimeout)
                if nextTimeout != self._INFINITE_PERIOD:
                        self._timeoutId = gobject.timeout_add(nextTimeout, self._on_timeout)
+               _moduleLogger.info("Next update in %s ms" % (nextTimeout, ))
                self._currentPeriod = nextTimeout
 
        def _stop_update(self):
index 6d08aaa..6d6b537 100755 (executable)
@@ -82,7 +82,11 @@ def run_theonering(persist):
 
 if __name__ == '__main__':
        telepathy_utils.debug_divert_messages(os.getenv('THEONERING_LOGFILE'))
-       logging.basicConfig(level=logging.DEBUG)
+       logging.basicConfig(
+               level=logging.DEBUG,
+               format='(%(asctime)s) %(levelname)s:%(name)s:%(message)s',
+               datefmt='%H:%M:%S',
+       )
        logging.info("telepathy-theonering %s-%s" % (constants.__version__, constants.__build__))
        logging.info("OS: %s" % (os.uname()[0], ))
        logging.info("Kernel: %s (%s) for %s" % os.uname()[2:])