Fixing a tp bug preventing channels from closing
[theonering] / src / channel / debug_prompt.py
index bc0ea38..0adbece 100644 (file)
@@ -6,33 +6,29 @@ import logging
 
 import telepathy
 
+import tp
 import gtk_toolbox
 
 
 _moduleLogger = logging.getLogger("channel.text")
 
 
-class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
+class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
        """
        Look into implementing ChannelInterfaceMessages for rich text formatting
        """
 
        def __init__(self, connection, manager, props, contactHandle):
-               self._manager = manager
-               self._props = props
+               self.__manager = manager
+               self.__props = props
 
                cmd.Cmd.__init__(self, "Debug Prompt")
                self.use_rawinput = False
-               try:
-                       # HACK Older python-telepathy way
-                       telepathy.server.ChannelTypeText.__init__(self, connection, contactHandle)
-               except TypeError:
-                       # HACK Newer python-telepathy way
-                       telepathy.server.ChannelTypeText.__init__(self, connection, manager, props)
-               self._nextRecievedId = 0
-               self._lastMessageTimestamp = datetime.datetime(1, 1, 1)
+               tp.ChannelTypeText.__init__(self, connection, manager, props)
+               self.__nextRecievedId = 0
+               self.__lastMessageTimestamp = datetime.datetime(1, 1, 1)
 
-               self._otherHandle = contactHandle
+               self.__otherHandle = contactHandle
 
        @gtk_toolbox.log_exception(_moduleLogger)
        def Send(self, messageType, text):
@@ -56,21 +52,19 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                self.close()
 
        def close(self):
-               telepathy.server.ChannelTypeText.Close(self)
-               if self._manager.channel_exists(self._props):
-                       # HACK Older python-telepathy requires doing this manually
-                       self._manager.remove_channel(self)
+               _moduleLogger.info("Closing debug")
+               tp.ChannelTypeText.Close(self)
                self.remove_from_connection()
 
        def _report_new_message(self, message):
-               currentReceivedId = self._nextRecievedId
+               currentReceivedId = self.__nextRecievedId
 
                timestamp = int(time.time())
                type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
 
-               self.Received(currentReceivedId, timestamp, self._otherHandle, type, 0, message.strip())
+               self.Received(currentReceivedId, timestamp, self.__otherHandle, type, 0, message.strip())
 
-               self._nextRecievedId += 1
+               self.__nextRecievedId += 1
 
        def do_reset_state_machine(self, args):
                if args:
@@ -78,7 +72,8 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                        return
 
                try:
-                       self._conn.session.stateMachine.reset_timers()
+                       for machine in self._conn.session.stateMachine._machines:
+                               machine.reset_timers()
                except Exception, e:
                        self._report_new_message(str(e))
 
@@ -88,7 +83,7 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                        return
 
                try:
-                       state = self._conn.session.stateMachine.get_state()
+                       state = self._conn.session.stateMachine.state
                        self._report_new_message(str(state))
                except Exception, e:
                        self._report_new_message(str(e))