Fixing a -T polling bug
[theonering] / src / gvoice / conversations.py
index f29f5e6..7fbe1ca 100644 (file)
@@ -109,9 +109,21 @@ class MergedConversations(object):
 
        def append_conversation(self, newConversation):
                self._validate(newConversation)
+               similarExist = False
                for similarConversation in self._find_related_conversation(newConversation.id):
                        self._update_previous_related_conversation(similarConversation, newConversation)
                        self._remove_repeats(similarConversation, newConversation)
+                       similarExist = True
+               if similarExist:
+                       # Hack to reduce a race window with GV marking messages as read
+                       # because it thinks we replied when really we replied to the
+                       # previous message.  Clients of this code are expected to handle
+                       # this gracefully.  Other race conditions may exist but clients are
+                       # responsible for them
+                       if newConversation.messages:
+                               newConversation.isRead = False
+                       else:
+                               newConversation.isRead = True
                self._conversations.append(newConversation)
 
        def to_dict(self):