Lessons learned from looking at telepathy-python to better understand what it was...
[theonering] / src / channel / text.py
1 import time
2 import logger
3
4 import telepathy
5
6 import handle
7
8
9 _moduleLogger = logger.getLogger("channel.text")
10
11
12 class TextChannel(telepathy.server.ChannelTypeText):
13         """
14         Look into implementing ChannelInterfaceMessages for rich text formatting
15         """
16
17         def __init__(self, connection):
18                 h = None
19                 telepathy.server.ChannelTypeText.__init__(self, connection, h)
20                 self._nextRecievedId = 0
21
22                 handles = []
23                 # @todo Populate participants
24                 self.MembersChanged('', handles, [], [], [],
25                                 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
26
27         def Send(self, messageType, text):
28                 if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
29                         raise telepathy.NotImplemented("Unhandled message type")
30                 # @todo implement sending message
31                 self.Sent(int(time.time()), messageType, text)
32
33         def Close(self):
34                 telepathy.server.ChannelTypeText.Close(self)
35                 self.remove_from_connection()
36
37         def _on_message_received(self, sender, message):
38                 """
39                 @todo Attatch this to receiving a message
40                 """
41                 currentReceivedId = self._nextRecievedId
42
43                 timestamp = int(time.time())
44                 h = handle.create_handle(self._conn, "contact", sender.account)
45                 type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
46                 message = message.content
47
48                 _moduleLogger.info("Received message from User %r" % h)
49                 self.Received(id, timestamp, h, type, 0, message)
50
51                 self._nextRecievedId += 1