Random bug fixes, advancing the channels, unit tests, seperating contacts not just...
[theonering] / src / channel / text.py
1 import time
2 import logging
3
4 import telepathy
5
6 import handle
7
8
9 _moduleLogger = logging.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, h):
18                 telepathy.server.ChannelTypeText.__init__(self, connection, h)
19                 self._nextRecievedId = 0
20
21                 handles = []
22                 # @todo Populate participants
23                 self.MembersChanged('', handles, [], [], [],
24                                 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
25
26         def Send(self, messageType, text):
27                 if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
28                         raise telepathy.NotImplemented("Unhandled message type")
29                 # @todo implement sending message
30                 self.Sent(int(time.time()), messageType, text)
31
32         def Close(self):
33                 telepathy.server.ChannelTypeText.Close(self)
34                 self.remove_from_connection()
35
36         def _on_message_received(self, contactId, contactNumber, message):
37                 """
38                 @todo Attatch this to receiving a message
39                 """
40                 currentReceivedId = self._nextRecievedId
41
42                 timestamp = int(time.time())
43                 h = handle.create_handle(self._conn, "contact", contactId, contactNumber)
44                 type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
45                 message = message.content
46
47                 _moduleLogger.info("Received message from User %r" % h)
48                 self.Received(id, timestamp, h, type, 0, message)
49
50                 self._nextRecievedId += 1