Ejemplo n.º 1
0
    def __init__(self, core, conv_manager, conv = None, contacts_uid = None):
        """
        @type core: aMSNCore
        @type conv_manager: aMSNConversationManager
        @type conv: papyon.conversation.SwitchboardConversation
        @type contacts_uid: list of str
        """

        if (contacts_uid is None):
            raise ValueError, InvalidArgument

        self._core = core
        self._conversation_manager = conv_manager
        self._contacts_uid = contacts_uid
        if conv is None:
            #New conversation
            papyon_contacts = [core._contactlist_manager.getContact(uid) for uid in contacts_uid]
            papyon_contacts = [c._papyon_contact for c in papyon_contacts if c is not None]
            #if c was None.... wtf?
            self._conv = papyon.Conversation(self._core._account.client, papyon_contacts)
        else:
            #From an existing conversation
            self._conv = conv

        self._win = self._conversation_manager.getConversationWindow(self)
        self._convo_events = conversation.ConversationEvents(self)
        self._convWidget = core._gui.gui.aMSNChatWidget(self, self._win, contacts_uid)
        self._win.addChatWidget(self._convWidget)
        self._win.show()
Ejemplo n.º 2
0
    def _send_text_message(self, message_type, text):
        if self._conversation is None and self._offline_contact.presence != papyon.Presence.OFFLINE:
            contact = self._offline_contact
            logger.info(
                'Contact %s still connected, inviting him to the text channel before sending message'
                % unicode(contact))
            client = self._conn_ref().msn_client
            self._conversation = papyon.Conversation(client, [contact])
            papyon.event.ConversationEventInterface.__init__(
                self, self._conversation)
            self._offline_contact = None
            self._offline_handle = None

        if self._conversation is not None:
            # Actually send the message.
            return ButterflyTextChannel._send_text_message(
                self, message_type, text)
        else:
            if message_type == telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
                logger.info("Sending offline message : %s" % unicode(text))
                self._oim_box_ref().send_message(self._offline_contact,
                                                 text.encode("utf-8"))
                #FIXME : Check if the message was sent correctly?
            else:
                raise telepathy.NotImplemented(
                    "Unhandled message type for offline contact")
            return True
Ejemplo n.º 3
0
    def __init__(self, conn, manager, conversation, props, object_path=None):
        ButterflyTextChannel.__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)
Ejemplo n.º 4
0
 def on_contact_presence_changed(self, contact):
     handle = self._conn.ensure_contact_handle(contact)
     # Recreate a conversation if our contact join
     if self._offline_contact == contact and contact.presence != papyon.Presence.OFFLINE:
         logger.info(
             'Contact %s connected, inviting him to the text channel' %
             unicode(handle))
         client = self._conn_ref().msn_client
         self._conversation = papyon.Conversation(client, [contact])
         papyon.event.ConversationEventInterface.__init__(
             self, self._conversation)
         self._offline_contact = None
         self._offline_handle = None
Ejemplo n.º 5
0
    def __init__(self, core, conv_manager, conv=None, contacts_uid=None):
        """
        @type core: L{amsn2.core.amsn.aMSNCore}
        @type conv_manager: L{amsn2.core.conversation_manager.aMSNConversationManager}
        @type conv: L{papyon.papyon.conversation.SwitchboardConversation}
        @type contacts_uid: list of str
        """

        if (contacts_uid is None):
            raise ValueError("aMSNConversation: contacts_uid is None")

        self._core = core
        self._conversation_manager = conv_manager
        self._contacts_uid = contacts_uid
        if conv is None:
            #New conversation
            papyon_contacts = [
                core._contactlist_manager.get_contact(uid)
                for uid in contacts_uid
            ]
            papyon_contacts = [
                c._papyon_contact for c in papyon_contacts if c is not None
            ]
            #if c was None.... wtf?
            self._conv = papyon.Conversation(self._core._account.client,
                                             papyon_contacts)
        else:
            #From an existing conversation
            self._conv = conv

        self._win = self._conversation_manager.get_conversation_window(self)
        self._convo_events = conversation.ConversationEvents(self)
        self._conv_widget = core._ui_manager.load_chat_widget(
            self, self._win, contacts_uid)
        self._win.add_chat_widget(self._conv_widget)
        self._win.show()
        if contacts_uid:
            if len(contacts_uid) > 1:
                self._win.set_title("aMSN2 - Multi Chat")
            else:
                c = self._core._contactlist_manager.get_contact(
                    contacts_uid[0])
                self._win.set_title("Chat with " + unicode(c.nickname))
        else:
            self._win.set_title("aMSN2 - Chat")
Ejemplo n.º 6
0
    def connected(self):
        self.profile.presence = papyon.profile.Presence.ONLINE

        # parse and search participants for conversation
        contacts = []
        for account in self.arguments["participants"]:
            network = papyon.profile.NetworkID.MSN
            if ':' in account:
                account, network = account.split(":")
                network = int(network)
            contact = self.address_book.search_or_build_contact(
                account, network)
            contacts.append(contact)

        self._conversation = papyon.Conversation(self, contacts)
        self._conversation_handler = ConversationHandler(
            self, self._conversation)
        if self.options.send:
            gobject.timeout_add_seconds(2, self.send)
        if self.options.nudge:
            gobject.timeout_add_seconds(2, self.nudge)