10 _moduleLogger = logging.getLogger("channel.text")
13 # @todo Get receiving of texts to work
14 class TextChannel(telepathy.server.ChannelTypeText):
16 Look into implementing ChannelInterfaceMessages for rich text formatting
19 def __init__(self, connection, h):
20 telepathy.server.ChannelTypeText.__init__(self, connection, h)
21 self._nextRecievedId = 0
25 @gtk_toolbox.log_exception(_moduleLogger)
26 def Send(self, messageType, text):
27 if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
28 raise telepathy.errors.NotImplemented("Unhandled message type: %r" % messageType)
30 self._conn.session.backend.send_sms(self._otherHandle.phoneNumber, text)
32 self.Sent(int(time.time()), messageType, text)
34 @gtk_toolbox.log_exception(_moduleLogger)
36 telepathy.server.ChannelTypeText.Close(self)
37 self.remove_from_connection()
39 def _on_message_received(self, contactId, contactNumber, message):
41 @todo Attatch this to receiving a message
43 currentReceivedId = self._nextRecievedId
45 timestamp = int(time.time())
46 h = handle.create_handle(self._conn, "contact", contactId, contactNumber)
47 type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
48 message = message.content
50 _moduleLogger.info("Received message from User %r" % h)
51 self.Received(id, timestamp, h, type, 0, message)
53 self._nextRecievedId += 1