Marking all of the current TODOs
[theonering] / src / channel / text.py
1 import time
2 import logging
3
4 import telepathy
5
6 import gtk_toolbox
7 import handle
8
9
10 _moduleLogger = logging.getLogger("channel.text")
11
12
13 # @todo Get receiving of texts to work
14 class TextChannel(telepathy.server.ChannelTypeText):
15         """
16         Look into implementing ChannelInterfaceMessages for rich text formatting
17         """
18
19         def __init__(self, connection, h):
20                 telepathy.server.ChannelTypeText.__init__(self, connection, h)
21                 self._nextRecievedId = 0
22
23                 self._otherHandle = h
24
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)
29
30                 self._conn.session.backend.send_sms(self._otherHandle.phoneNumber, text)
31
32                 self.Sent(int(time.time()), messageType, text)
33
34         @gtk_toolbox.log_exception(_moduleLogger)
35         def Close(self):
36                 telepathy.server.ChannelTypeText.Close(self)
37                 self.remove_from_connection()
38
39         def _on_message_received(self, contactId, contactNumber, message):
40                 """
41                 @todo Attatch this to receiving a message
42                 """
43                 currentReceivedId = self._nextRecievedId
44
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
49
50                 _moduleLogger.info("Received message from User %r" % h)
51                 self.Received(id, timestamp, h, type, 0, message)
52
53                 self._nextRecievedId += 1