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