Removing dead code
[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 class TextChannel(telepathy.server.ChannelTypeText):
14         """
15         Look into implementing ChannelInterfaceMessages for rich text formatting
16         """
17
18         def __init__(self, connection, h):
19                 telepathy.server.ChannelTypeText.__init__(self, connection, h)
20                 self._nextRecievedId = 0
21
22                 self._otherHandle = h
23
24         @gtk_toolbox.log_exception(_moduleLogger)
25         def Send(self, messageType, text):
26                 if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
27                         raise telepathy.NotImplemented("Unhandled message type: %r" % messageType)
28
29                 self._conn.session.backend.send_sms(self._otherHandle.phoneNumber, text)
30
31                 self.Sent(int(time.time()), messageType, text)
32
33         @gtk_toolbox.log_exception(_moduleLogger)
34         def Close(self):
35                 telepathy.server.ChannelTypeText.Close(self)
36                 self.remove_from_connection()
37
38         def _on_message_received(self, contactId, contactNumber, message):
39                 """
40                 @todo Attatch this to receiving a message
41                 """
42                 currentReceivedId = self._nextRecievedId
43
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
48
49                 _moduleLogger.info("Received message from User %r" % h)
50                 self.Received(id, timestamp, h, type, 0, message)
51
52                 self._nextRecievedId += 1