Fixing a bug where telepathy-theonering wasn't included in packages
[theonering] / src / channel_manager.py
index c513b11..d1e9942 100644 (file)
@@ -1,4 +1,5 @@
 import weakref
+import itertools
 import logging
 
 import telepathy
@@ -18,19 +19,20 @@ class ChannelManager(object):
                self._callChannels = weakref.WeakValueDictionary()
 
        def close(self):
-               for chan in self._listChannels.values():
-                       chan.remove_from_connection()# so that dbus lets it die.
-               for chan in self._textChannels.values():
-                       chan.Close()
-               for chan in self._callChannels.values():
-                       chan.Close()
+               for chan in itertools.chain(
+                       self._listChannels.values(), self._textChannels.values(), self._callChannels.values()
+               ):
+                       try:
+                               chan.close()
+                       except Exception:
+                               _moduleLogger.exception("Shutting down %r" % (chan, ))
 
        def channel_for_list(self, handle, suppress_handler=False):
                try:
                        chan = self._listChannels[handle]
                except KeyError, e:
                        if handle.get_type() != telepathy.HANDLE_TYPE_LIST:
-                               raise telepathy.NotImplemented("Only server lists are allowed")
+                               raise telepathy.errors.NotImplemented("Only server lists are allowed")
                        _moduleLogger.debug("Requesting new contact list channel")
 
                        chan = channel.contact_list.create_contact_list_channel(self._connRef(), handle)
@@ -43,10 +45,10 @@ class ChannelManager(object):
                        chan = self._textChannels[handle]
                except KeyError, e:
                        if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT:
-                               raise telepathy.NotImplemented("Only Contacts are allowed")
+                               raise telepathy.errors.NotImplemented("Only Contacts are allowed")
                        _moduleLogger.debug("Requesting new text channel")
 
-                       chan = channel.text.TextChannel(self._connRef(), None)
+                       chan = channel.text.TextChannel(self._connRef(), handle)
                        self._textChannels[handle] = chan
                        self._connRef().add_channel(chan, handle, suppress_handler)
                return chan
@@ -55,11 +57,12 @@ class ChannelManager(object):
                try:
                        chan = self._callChannels[handle]
                except KeyError, e:
-                       if handle.get_type() != telepathy.HANDLE_TYPE_NONE:
-                               raise telepathy.NotImplemented("Using deprecated means to create a call")
+                       if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT:
+                               _moduleLogger.warning("Using deprecated means to create a call")
+                               raise telepathy.errors.NotImplemented("Not implementing depcrecated means")
                        _moduleLogger.debug("Requesting new call channel")
 
-                       chan = channel.call.CallChannel(self._connRef())
+                       chan = channel.call.CallChannel(self._connRef(), handle)
                        self._callChannels[handle] = chan
                        self._connRef().add_channel(chan, handle, suppress_handler)
                return chan