- channel = None
- channelManager = self._channelManager
- handle = self.handle(handleType, handleId)
-
- if type == telepathy.CHANNEL_TYPE_CONTACT_LIST:
- _moduleLogger.info("RequestChannel ContactList")
- channel = channelManager.channel_for_list(handle, suppressHandler)
- elif type == telepathy.CHANNEL_TYPE_TEXT:
- _moduleLogger.info("RequestChannel Text")
- channel = channelManager.channel_for_text(handle, suppressHandler)
- elif type == telepathy.CHANNEL_TYPE_STREAMED_MEDIA:
- _moduleLogger.info("RequestChannel Media")
- channel = channelManager.channel_for_call(handle, suppressHandler)
- else:
- raise telepathy.errors.NotImplemented("unknown channel type %s" % type)
+ h = self.get_handle_by_id(handleType, handleId) if handleId != 0 else None
+ props = self._generate_props(type, h, suppressHandler)
+ self._validate_handle(props)
+
+ chan = self.__channelManager.channel_for_props(props, signal=True)
+ path = chan._object_path
+ _moduleLogger.info("RequestChannel Object Path: %s" % path)
+ return path
+
+ def _generate_props(self, channelType, handle, suppressHandler, initiatorHandle=None):
+ targetHandle = 0 if handle is None else handle.get_id()
+ targetHandleType = telepathy.HANDLE_TYPE_NONE if handle is None else handle.get_type()
+ props = {
+ telepathy.CHANNEL_INTERFACE + '.ChannelType': channelType,
+ telepathy.CHANNEL_INTERFACE + '.TargetHandle': targetHandle,
+ telepathy.CHANNEL_INTERFACE + '.TargetHandleType': targetHandleType,
+ telepathy.CHANNEL_INTERFACE + '.Requested': suppressHandler
+ }
+
+ if initiatorHandle is not None:
+ props[telepathy.CHANNEL_INTERFACE + '.InitiatorHandle'] = initiatorHandle.id
+
+ return props
+
+ def _disconnect(self):
+ _moduleLogger.info("Disconnecting")
+ self.session.voicemails.updateSignalHandler.unregister_sink(
+ self.__callback
+ )
+ self.session.texts.updateSignalHandler.unregister_sink(
+ self.__callback
+ )
+ self.__callback = None
+
+ self.__channelManager.close()
+ self.session.save(self.__cachePath)
+ self.session.logout()
+ self.session.close()
+ self.__session = None
+ if self.__connection is not None:
+ self.__connection.disconnect(self.__connectionEventId)
+ self.__connectionEventId = None