8fe4a5f76cdbe86031478820f9bfb1066140c0e1
[theonering] / src / channel / text.py
1 import time
2 import weakref
3
4 import telepathy
5
6
7 class TextChannel(telepathy.server.ChannelTypeText):
8         """
9         Look into implementing ChannelInterfaceMessages for rich text formatting
10         """
11
12         def __init__(self, connection, conversation):
13                 self._recv_id = 0
14                 self._conversation = conversation
15                 self._connRef = weakref.ref(connection)
16
17                 telepathy.server.ChannelTypeText.__init__(self, connection, None)
18
19                 self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD, 0)
20                 self.__add_initial_participants()
21
22         def Send(self, messageType, text):
23                 if messageType == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
24                         self._conversation.send_text_message(text)
25                 elif messageType == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_ACTION and text == u"nudge":
26                         self._conversation.send_nudge()
27                 else:
28                         raise telepathy.NotImplemented("Unhandled message type")
29                 self.Sent(int(time.time()), messageType, text)
30
31         def Close(self):
32                 self._conversation.leave()
33                 telepathy.server.ChannelTypeText.Close(self)
34                 self.remove_from_connection()