+ try:
+ # Clear since the user has seen it all and it should start a new conversation
+ self._conn.session.conversations.clear_conversation(self._contactKey)
+
+ self._conn.session.conversations.updateSignalHandler.unregister_sink(
+ self._on_conversations_updated
+ )
+ finally:
+ telepathy.server.ChannelTypeText.Close(self)
+ self.remove_from_connection()
+
+ @property
+ def _contactKey(self):
+ contactKey = self._otherHandle.contactID, self._otherHandle.phoneNumber
+ return contactKey
+
+ @coroutines.func_sink
+ @coroutines.expand_positional
+ @gobject_utils.async
+ @gtk_toolbox.log_exception(_moduleLogger)
+ def _on_conversations_updated(self, conversationIds):
+ if self._contactKey not in conversationIds:
+ return
+ _moduleLogger.info("Incoming messages from %r for existing conversation" % (self._contactKey, ))
+ conversation = self._conn.session.conversations.get_conversation(self._contactKey)
+ self._report_conversation(conversation)
+
+ def _report_conversation(self, conversation):
+ # @bug? Check if messages sent need to be filtered out
+ completeMessageHistory = conversation["messageParts"]
+ messages = self._filter_seen_messages(completeMessageHistory)
+ self._lastMessageTimestamp = messages[-1][0]
+ formattedMessage = self._format_messages(messages)
+ self._report_new_message(formattedMessage)
+
+ def _filter_seen_messages(self, messages):
+ return (
+ message
+ for message in messages
+ if self._lastMessageTimestamp < message[0]
+ )
+
+ def _format_messages(self, messages):
+ return "\n".join(message[1] for message in messages)
+
+ def _report_new_message(self, message):
+ currentReceivedId = self._nextRecievedId
+
+ timestamp = int(time.time())
+ type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
+ message = message.content
+
+ _moduleLogger.info("Received message from User %r" % self._otherHandle)
+ self.Received(id, timestamp, self._otherHandle, type, 0, message)
+
+ self._nextRecievedId += 1