Getting start on this here em code
[theonering] / src / channel / text.py
1 import time
2 import weakref
3
4 import telepathy
5
6 import handle
7
8
9 class ButterflyTextChannel(
10                 telepathy.server.ChannelTypeText,
11                 telepathy.server.ChannelInterfaceGroup,
12                 telepathy.server.ChannelInterfaceChatState
13         ):
14
15         def __init__(self, connection, conversation):
16                 self._recv_id = 0
17                 self._conversation = conversation
18                 self._conn_ref = weakref.ref(connection)
19
20                 telepathy.server.ChannelTypeText.__init__(self, connection, None)
21                 telepathy.server.ChannelInterfaceGroup.__init__(self)
22                 telepathy.server.ChannelInterfaceChatState.__init__(self)
23
24                 self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD, 0)
25                 self.__add_initial_participants()
26
27         def SetChatState(self, state):
28                 if state == telepathy.CHANNEL_CHAT_STATE_COMPOSING:
29                         self._conversation.send_typing_notification()
30                 h = handle.create_handle(self._conn_ref(), 'self')
31                 self.ChatStateChanged(h, state)
32
33         def Send(self, messageType, text):
34                 if messageType == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
35                         self._conversation.send_text_message(text)
36                 elif messageType == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_ACTION and text == u"nudge":
37                         self._conversation.send_nudge()
38                 else:
39                         raise telepathy.NotImplemented("Unhandled message type")
40                 self.Sent(int(time.time()), messageType, text)
41
42         def Close(self):
43                 self._conversation.leave()
44                 telepathy.server.ChannelTypeText.Close(self)
45                 self.remove_from_connection()