except ImportError:
import pickle
+import constants
import util.coroutines as coroutines
import util.misc as util_misc
assert not self._conversations
try:
with open(path, "rb") as f:
- self._conversations = pickle.load(f)
+ fileVersion, fileBuild, convs = pickle.load(f)
except (pickle.PickleError, IOError):
_moduleLogger.exception("While loading for %s" % self._name)
+ return
+
+ if fileVersion == constants.__version__ and fileBuild == constants.__build__:
+ self._conversations = convs
+ else:
+ _moduleLogger.debug(
+ "%s Skipping cache due to version mismatch (%s-%s)" % (self._name, fileVersion, fileBuild)
+ )
def save(self, path):
try:
+ dataToDump = (constants.__version__, constants.__build__, self._conversations)
with open(path, "wb") as f:
- pickle.dump(self._conversations, f, pickle.HIGHEST_PROTOCOL)
+ pickle.dump(dataToDump, f, pickle.HIGHEST_PROTOCOL)
except (pickle.PickleError, IOError):
_moduleLogger.exception("While saving for %s" % self._name)
isConversationUpdated = True
except RuntimeError, e:
if False:
- _moduleLogger.info("%s Skipping conversation for %r because '%s'" % (self._name, key, e))
+ _moduleLogger.debug("%s Skipping conversation for %r because '%s'" % (self._name, key, e))
isConversationUpdated = False
if isConversationUpdated:
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):
+ selfDict = {}
+ selfDict["conversations"] = [conv.to_dict() for conv in self._conversations]
+ return selfDict
+
@property
def conversations(self):
return self._conversations
return similarConversations
def _update_previous_related_conversation(self, relatedConversation, newConversation):
- for commonField in ("isRead", "isSpam", "isTrash", "isArchived"):
+ for commonField in ("isSpam", "isTrash", "isArchived"):
newValue = getattr(newConversation, commonField)
setattr(relatedConversation, commonField, newValue)
for newMessage in newConversationMessages
if newMessage not in relatedConversation.messages
]
- _moduleLogger.debug("%s Found %d new messages in conversation %s (%d/%d)" % (
- self._name,
+ _moduleLogger.debug("Found %d new messages in conversation %s (%d/%d)" % (
len(newConversationMessages) - len(newConversation.messages),
newConversation.id,
len(newConversation.messages),