Activity

  • Ricochet replied to the question Inbox issue sends message to many users in the forum BuddyBoss Inbox 7 years, 11 months ago

    This works for us. It does two things: 1. search all users not just friends 2. clear input field after you select from autosuggest list.

    I’ll put it here in case it helps anyone else. No promises, though!

    if(function_exists("bp_is_messages_component")) {
    define( 'BP_MESSAGES_AUTOCOMPLETE_ALL', false );
    $current_url = bp_get_requested_url();

    if (strpos($current_url, 'compose') > 0) {

    // Include the autocomplete JS for composing a message.

    remove_action( 'wp_head', 'messages_autocomplete_init_jsblock' );
    add_action( 'wp_head','messages_autocomplete_init_jsblock_custom',99,0);
    }
    }

    function messages_autocomplete_init_jsblock_custom() {

    ?>

    <script type="text/javascript">
    window.user_profiles = Array();
    jQuery(document).ready(function() {
    var obj = jQuery(".send-to-input").autocomplete({
    source: function(request, response) {
    jQuery("body").data("ac-item-p","even");
    var term = request.term;
    if (term in window.user_profiles) {
    response(window.user_profiles[term]);
    return;
    }
    var data = {
    'action': 'messages_autocomplete_results',
    'search_term': request.term
    };
    jQuery.ajax({
    url: ajaxurl + '?q=' + request.term + '&limit=10',
    data: data,
    success: function(data) {
    var new_data = Array();
    d = data.split("n");
    jQuery.each(d, function(i, item) {
    new_data[new_data.length] = item;
    });
    if (data != "") {
    response(new_data);
    }
    }
    });
    },
    minLength: 1,
    select: function(event, ui) {
    sel_item = ui.item;
    var d = String(sel_item.label).split(' (');
    var un = d[1].substr(0, d[1].length - 1);
    //check if it already exists;
    if (0 === jQuery('.acfb-holder').find('#un-' + un).length) {
    var ln = '#link-' + un;
    var l = jQuery(ln).attr('href');
    var v = '<li class="selected-user friend-tab" id="un-' + un + '"><span><a href="' + l + '">' + d[0] + '</a></span> <span class="p">X</span></li>';
    if (jQuery(".acfb-holder").find(".friend-tab").length == 0) {
    var x = jQuery('.acfb-holder').prepend(v);
    } else {
    var x = jQuery('.acfb-holder').find(".friend-tab").last().after(v);
    }
    jQuery('#send-to-usernames').addClass(un);
    jQuery("#send-to-input").val("");
    }
    return false;
    },
    focus: function(event, ui) {
    jQuery(".ui-autocomplete li").removeClass("ui-state-hover");
    jQuery(".ui-autocomplete").find("li:has(a.ui-state-focus)").addClass("ui-state-hover");
    return false;
    }
    });

    obj.data("ui-autocomplete")._renderItem = function(ul, item) {
    ul.addClass("ac_results");
    if (jQuery("body").data("ac-item-p") == "even"){
    c = "ac_event";
    jQuery("body").data("ac-item-p","odd");
    } else {
    c = "ac_odd";
    jQuery("body").data("ac-item-p","even");
    }
    return jQuery("<li class='"+c+"'>").append("<a>" + item.label + "</a>").appendTo(ul);
    };

    obj.data("ui-autocomplete")._resizeMenu = function () {
    var ul = this.menu.element;
    ul.outerWidth(this.element.outerWidth());
    };

    jQuery(document).on("click", ".selected-user", function() {
    jQuery(this).remove();
    });
    jQuery('#send_message_form').submit(function() {
    tosend = Array();
    jQuery(".acfb-holder").find(".friend-tab").each(function(i, item) {
    un = jQuery(this).attr("id");
    un = un.replace('un-', '');
    tosend[tosend.length] = un;
    });
    document.getElementById('send-to-usernames').value = tosend.join(" ");
    });
    });
    </script>

    <?php
    }