예제 #1
0
    def open_chat(self, jid, account, message):
        """
        Shows the tabbed window for new message to 'jid', using account (optional)
        'account'
        """
        if not jid:
            raise dbus_support.MissingArgument()
        jid = self._get_real_jid(jid, account)
        try:
            jid = helpers.parse_jid(jid)
        except Exception:
            # Jid is not conform, ignore it
            return DBUS_BOOLEAN(False)

        minimized_control = None
        if account:
            accounts = [account]
        else:
            accounts = gajim.connections.keys()
            if len(accounts) == 1:
                account = accounts[0]
        connected_account = None
        first_connected_acct = None
        for acct in accounts:
            if gajim.connections[acct].connected > 1:  # account is  online
                contact = gajim.contacts.get_first_contact_from_jid(acct, jid)
                if gajim.interface.msg_win_mgr.has_window(jid, acct):
                    connected_account = acct
                    break
                # jid is in roster
                elif contact:
                    minimized_control = \
                        jid in gajim.interface.minimized_controls[acct]
                    connected_account = acct
                    break
                # we send the message to jid not in roster, because account is
                # specified, or there is only one account
                elif account:
                    connected_account = acct
                elif first_connected_acct is None:
                    first_connected_acct = acct

        # if jid is not a conntact, open-chat with first connected account
        if connected_account is None and first_connected_acct:
            connected_account = first_connected_acct

        if minimized_control:
            gajim.interface.roster.on_groupchat_maximized(
                None, jid, connected_account)

        if connected_account:
            gajim.interface.new_chat_from_jid(connected_account, jid, message)
            # preserve the 'steal focus preservation'
            win = gajim.interface.msg_win_mgr.get_window(
                jid, connected_account).window
            if win.get_property('visible'):
                win.window.focus(Gtk.get_current_event_time())
            return DBUS_BOOLEAN(True)
        return DBUS_BOOLEAN(False)
예제 #2
0
    def contact_info(self, jid):
        """
        Get vcard info for a contact. Return cached value of the vcard
        """
        if not isinstance(jid, str):
            jid = str(jid)
        if not jid:
            raise dbus_support.MissingArgument()
        jid = self._get_real_jid(jid)

        cached_vcard = list(gajim.connections.values())[0].get_cached_vcard(jid)
        if cached_vcard:
            return get_dbus_struct(cached_vcard)

        # return empty dict
        return DBUS_DICT_SV()