Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/03/2014 08:52:05 PM (10 years ago)
Author:
djpaul
Message:

Activity: introducing @mentions auto-suggestions.

Activity has long-supported @mentions, where you can mention the name of another user to get their attention in a conversation. You've always had to know the exact username of the person you're trying to mention, or you've been forced to go look it up. Now, when leaving an activity update or reply, press @ and then start typing someone's diaply name (or user_nicename), and username suggestions will automatically appear below where you're typing.

If the Friends component is active, and if the logged-in user has any friends, those friends' details are used to pre-prime the username suggestions for super-fast snappy suggestions. Suggestions are also provided when writing a blog post comment.

This change has mostly been implemented using two third-party libraries, At.js (https://github.com/ichord/At.js) and Caret.js (https://github.com/ichord/Caret.js). Big thanks to those projects' authors for their fine work, and also to Automattic's O2 team, who made a number of CSS+JS tweaks/adaptions to At.js, which we've adopted. Props also to karmatosed for design suggestions on the earliest implementation of this feature, three years ago. :)

Fixes #3278

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-actions.php

    r8662 r8754  
    648648    $bp->activity->akismet = new BP_Akismet();
    649649}
     650
     651/**
     652 * AJAX endpoint for Suggestions API lookups.
     653 *
     654 * @since BuddyPress (2.1.0)
     655 */
     656function bp_ajax_get_suggestions() {
     657    if ( ! bp_is_user_active() || empty( $_GET['term'] ) || empty( $_GET['type'] ) ) {
     658        wp_send_json_error( 'missing_parameter' );
     659        exit;
     660    }
     661
     662    $results = bp_core_get_suggestions( array(
     663        'term' => sanitize_text_field( $_GET['term'] ),
     664        'type' => sanitize_text_field( $_GET['type'] ),
     665    ) );
     666
     667    if ( is_wp_error( $results ) ) {
     668        wp_send_json_error( $results->get_error_message() );
     669        exit;
     670    }
     671
     672    wp_send_json_success( $results );
     673}
     674add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' );
Note: See TracChangeset for help on using the changeset viewer.