10 _moduleLogger = logging.getLogger("channel.text")
13 class TextChannel(telepathy.server.ChannelTypeText):
15 Look into implementing ChannelInterfaceMessages for rich text formatting
18 def __init__(self, connection, h):
19 telepathy.server.ChannelTypeText.__init__(self, connection, h)
20 self._nextRecievedId = 0
24 @gtk_toolbox.log_exception(_moduleLogger)
25 def Send(self, messageType, text):
26 if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
27 raise telepathy.errors.NotImplemented("Unhandled message type: %r" % messageType)
29 self._conn.session.backend.send_sms(self._otherHandle.phoneNumber, text)
31 self.Sent(int(time.time()), messageType, text)
33 @gtk_toolbox.log_exception(_moduleLogger)
35 telepathy.server.ChannelTypeText.Close(self)
36 self.remove_from_connection()
38 def _on_message_received(self, contactId, contactNumber, message):
40 @todo Attatch this to receiving a message signal
42 currentReceivedId = self._nextRecievedId
44 timestamp = int(time.time())
45 h = handle.create_handle(self._conn, "contact", contactId, contactNumber)
46 type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
47 message = message.content
49 _moduleLogger.info("Received message from User %r" % h)
50 self.Received(id, timestamp, h, type, 0, message)
52 self._nextRecievedId += 1