From: Ed Page Date: Tue, 22 Dec 2009 01:02:58 +0000 (-0600) Subject: Bug fixes, code cleanup, debugging help all working together to make it so that I... X-Git-Url: http://git.maemo.org/git/?p=theonering;a=commitdiff_plain;h=b2b59a3eebb396e5663a50ef639b148fd2ac9c99 Bug fixes, code cleanup, debugging help all working together to make it so that I just had a conversation with someone over SMS --- diff --git a/src/channel/text.py b/src/channel/text.py index 4ad3fcb..37d3f6f 100644 --- a/src/channel/text.py +++ b/src/channel/text.py @@ -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) diff --git a/src/connection.py b/src/connection.py index 69ed50c..dc2c0b2 100644 --- a/src/connection.py +++ b/src/connection.py @@ -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) diff --git a/src/connection_manager.py b/src/connection_manager.py index ec64b0f..b392555 100644 --- a/src/connection_manager.py +++ b/src/connection_manager.py @@ -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 diff --git a/src/gvoice/conversations.py b/src/gvoice/conversations.py index 10b11e0..4541608 100644 --- a/src/gvoice/conversations.py +++ b/src/gvoice/conversations.py @@ -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" diff --git a/src/gvoice/session.py b/src/gvoice/session.py index 1f52bf9..d87f7ad 100644 --- a/src/gvoice/session.py +++ b/src/gvoice/session.py @@ -81,3 +81,7 @@ class Session(object): Delay initialized addressbook """ return self._conversations + + @property + def stateMachine(self): + return self._stateMachine diff --git a/src/gvoice/state_machine.py b/src/gvoice/state_machine.py index 2fb1d01..6e7d288 100644 --- a/src/gvoice/state_machine.py +++ b/src/gvoice/state_machine.py @@ -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): diff --git a/src/telepathy-theonering b/src/telepathy-theonering index 6d08aaa..6d6b537 100755 --- a/src/telepathy-theonering +++ b/src/telepathy-theonering @@ -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:])