[telepathy-butterfly/master] Remove closed text channel from the list (fd.o #22250)

Olivier Le Thanh Duong olivier at lethanh.be
Tue Jun 16 09:54:26 PDT 2009


Remove closed text channel from the text channels list
of the channel manager. Fix the bug which prevented
discussions windows to be reopened.
---
 butterfly/channel/text.py    |    4 +++-
 butterfly/channel_manager.py |   11 +++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/butterfly/channel/text.py b/butterfly/channel/text.py
index fe93b4b..cbcfd74 100644
--- a/butterfly/channel/text.py
+++ b/butterfly/channel/text.py
@@ -39,10 +39,11 @@ class ButterflyTextChannel(
         telepathy.server.ChannelInterfaceChatState,
         pymsn.event.ConversationEventInterface):
 
-    def __init__(self, connection, conversation):
+    def __init__(self, connection, conversation, chan_manager):
         self._recv_id = 0
         self._conversation = conversation
         self._conn_ref = weakref.ref(connection)
+        self._chan_manager_ref = weakref.ref(chan_manager)
 
         telepathy.server.ChannelTypeText.__init__(self, connection, None)
         telepathy.server.ChannelInterfaceGroup.__init__(self)
@@ -70,6 +71,7 @@ class ButterflyTextChannel(
 
     def Close(self):
         self._conversation.leave()
+        self._chan_manager_ref().remove_text_channel(self)
         telepathy.server.ChannelTypeText.Close(self)
         self.remove_from_connection()
 
diff --git a/butterfly/channel_manager.py b/butterfly/channel_manager.py
index f5130e8..8592586 100644
--- a/butterfly/channel_manager.py
+++ b/butterfly/channel_manager.py
@@ -66,7 +66,14 @@ class ChannelManager(object):
             if conversation is None:
                 client = self._conn_ref().msn_client
                 conversation = pymsn.Conversation(client, [contact])
-            channel = ButterflyTextChannel(self._conn_ref(), conversation)
+            channel = ButterflyTextChannel(self._conn_ref(), conversation, self)
             self._text_channels[handle] = channel
             self._conn_ref().add_channel(channel, handle, suppress_handler)
-        return channel
\ No newline at end of file
+        return channel
+
+    def remove_text_channel(self, text_channel):
+        logger.debug("Removing channel %s" % text_channel)
+        for handle, chan in self._text_channels.items():
+            if chan == text_channel:
+                del self._text_channels[handle]
+
-- 
1.5.6.5



More information about the telepathy-commits mailing list