- assert self._data[constantField] == moreData[constantField], "Constant field changed, soemthing is seriously messed up: %r v %r" % (self._data, moreData)
-
- if moreData["time"] < self._data["time"]:
- # If its older, assuming it has nothing new to report
- return False
-
- for preferredMoreField in ("id", "name", "time", "relTime", "prettyNumber", "location"):
- preferredFieldValue = moreData[preferredMoreField]
- if preferredFieldValue:
- self._data[preferredMoreField] = preferredFieldValue
-
- messageAppended = False
-
- # @todo Handle No Transcription voicemails
- messageParts = self._data["messageParts"]
- for message in moreData["messageParts"]:
- messageWithTimestamp = self._append_time(message, moreData["time"])
- if messageWithTimestamp not in messageParts:
- messageParts.append(messageWithTimestamp)
- messageAppended = True
- messageParts.sort()
-
- return messageAppended
-
- @staticmethod
- def _append_time(message, exactWhen):
- whoFrom, message, when = message
- return exactWhen, whoFrom, message, when
+ assert getattr(self._conversations[0], constantField) == getattr(newConversation, constantField), "Constant field changed, soemthing is seriously messed up: %r v %r" % (
+ getattr(self._conversations[0], constantField),
+ getattr(newConversation, constantField),
+ )
+
+ if newConversation.time <= self._conversations[-1].time:
+ raise RuntimeError("Conversations got out of order")
+
+ def _find_related_conversation(self, convId):
+ similarConversations = (
+ conversation
+ for conversation in self._conversations
+ 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
+ ]
+ _moduleLogger.debug("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"