Ejemplo n.º 1
0
    def __init__(self, conn, manager, conversation, props, object_path=None):
        GlitterTextChannel.__init__(self, conn, manager, conversation, props, object_path)

        _, _, handle = manager._get_type_requested_handle(props)

        if handle.contact is None:
            raise telepathy.NotAvailable('Contact not available')

        self._pending_offline_messages = {}
        contact = handle.contact
        if conversation is None:
            if contact.presence != papyon.Presence.OFFLINE:
                client = conn.msn_client
                conversation = papyon.Conversation(client, [contact])
            self._conversation = conversation

        if self._conversation:
            self._offline_contact = None
            self._offline_handle = None
            papyon.event.ConversationEventInterface.__init__(self, self._conversation)
        else:
            self._offline_handle = handle
            self._offline_contact = contact

        self._initial_handle = handle

        self._oim_box_ref = weakref.ref(conn.msn_client.oim_box)
    def _get_media_channel(self, props, call=None):
        _, surpress_handler, handle = self._get_type_requested_handle(props)

        if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT:
            raise telepathy.NotImplemented('Only contacts are allowed')

        contact = handle.contact

        if contact.presence == papyon.Presence.OFFLINE:
            raise telepathy.NotAvailable('Contact not available')

        logger.debug('New media channel')

        if call is None:
            client = self._conn.msn_client
            call = client.call_manager.create_call(contact)

        path = "MediaChannel/%d" % self.__media_channel_id
        self.__media_channel_id += 1

        return ButterflyMediaChannel(self._conn,
                                     self,
                                     call,
                                     handle,
                                     props,
                                     object_path=path)
Ejemplo n.º 3
0
 def Close(self):
     logger.debug("Deleting group %s" % self._handle.name)
     ab = self._conn.msn_client.address_book
     group = self._handle.group
     if len(ab.contacts.search_by_groups(group)) == 0:
         raise telepathy.NotAvailable("Can't delete non-empty group")
     ab.delete_group(group)
    def _invite_initial_invitees(self, props, ic):
        # Invite all other participants in other channels from InitialChannels
        while ic:
            channel = ic.pop()
            if channel._conversation is None:
                continue

            for contact in channel.get_participants():
                if contact not in self._conversation.participants:
                    logger.info('Inviting %s into channel' % contact.id)
                    self._conversation.invite_user(contact)

        self._conference_initial_invitees = []

        # Get IntitialInviteeHandles
        for invitee_handle in props.get(
                CHANNEL_INTERFACE_CONFERENCE + '.InitialInviteeHandles', []):
            handle = self._conn_ref().handle(telepathy.HANDLE_TYPE_CONTACT,
                                             invitee_handle)

            if handle is None or handle.contact is None:
                raise telepathy.NotAvailable(
                    'Contact with handle %u not available' % invitee_handle)

            if handle not in self._conference_initial_invitees:
                self._conference_initial_invitees.append(handle)

        # Get InitialInviteeIDs
        for invitee_id in props.get(
                CHANNEL_INTERFACE_CONFERENCE + '.InitialInviteeIDs', []):
            handle = self._conn_ref().ensure_handle(
                telepathy.HANDLE_TYPE_CONTACT, invitee_id)

            if handle is None or handle.contact is None:
                raise telepathy.NotAvailable('Contact "%s" not available' %
                                             invitee_id)

            if handle not in self._conference_initial_invitees:
                self._conference_initial_invitees.append(handle)

        # Actually invite all the initial invitees
        for handle in self._conference_initial_invitees:
            logger.info('Inviting initial invitee, %s into channel' %
                        handle.account)
            self._conversation.invite_user(handle.contact)
Ejemplo n.º 5
0
 def create_handle(self, handle_type, handle_name, **kwargs):
     """Create new handle with given type and name."""
     handle_id = self.get_handle_id()
     handle = ButterflyHandleFactory(self, handle_type, handle_id,
                                     handle_name, **kwargs)
     if handle is None:
         raise telepathy.NotAvailable('Handle type unsupported %d' %
                                      handle_type)
     logger.info("New Handle %s" % unicode(handle))
     self._handles[handle_type, handle_id] = handle
     return handle
    def _get_ft_channel(self, props, session=None):
        _, surpress_handler, handle = self._get_type_requested_handle(props)

        if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT:
            raise telepathy.NotImplemented('Only contacts are allowed')

        contact = handle.contact

        if contact.presence == papyon.Presence.OFFLINE:
            raise telepathy.NotAvailable('Contact not available')

        logger.debug('New file transfer channel')

        path = "FileTransferChannel%d" % self.__ft_channel_id
        self.__ft_channel_id += 1

        return ButterflyFileTransferChannel(self._conn,
                                            self,
                                            session,
                                            handle,
                                            props,
                                            object_path=path)
Ejemplo n.º 7
0
    def RequestHandles(self, handle_type, names, sender):
        logger.info(
            "Method RequestHandles called, handle type: %s, names: %s" %
            (str(handle_type), str(names)))
        self.check_connected()
        self.check_handle_type(handle_type)

        handles = []
        for name in names:
            if handle_type == telepathy.HANDLE_TYPE_CONTACT:
                contact_name = name

                try:
                    int(str(contact_name))
                except:
                    raise InvalidHandle

                handle_id = self.get_handle_id_by_name(
                    telepathy.constants.HANDLE_TYPE_CONTACT, str(contact_name))

                if handle_id != 0:
                    handle = self.handle(
                        telepathy.constants.HANDLE_TYPE_CONTACT, handle_id)
                else:
                    handle = SunshineHandleFactory(self, 'contact',
                                                   str(contact_name), None)
            elif handle_type == telepathy.HANDLE_TYPE_ROOM:
                handle = SunshineHandleFactory(self, 'room', name)
            elif handle_type == telepathy.HANDLE_TYPE_LIST:
                handle = SunshineHandleFactory(self, 'list', name)
            elif handle_type == telepathy.HANDLE_TYPE_GROUP:
                handle = SunshineHandleFactory(self, 'group', name)
            else:
                raise telepathy.NotAvailable('Handle type unsupported %d' %
                                             handle_type)
            handles.append(handle.id)
            self.add_client_handle(handle, sender)
        return handles