Пример #1
0
 /**
  * @group bp_messages_filter_starred_message_threads
  */
 public function test_get_starred_threads_should_not_include_deleted_thread()
 {
     $old_current_user = get_current_user_id();
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     // create three threads
     $t1 = $this->factory->message->create(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'A'));
     $t2 = $this->factory->message->create(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'B'));
     $t3 = $this->factory->message->create(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'C'));
     // grab the message ids as individual variables
     list($m1) = $this->get_message_ids($t1);
     list($m2) = $this->get_message_ids($t2);
     list($m3) = $this->get_message_ids($t3);
     // star all threads
     bp_messages_star_set_action(array('user_id' => $u2, 'message_id' => $m1));
     bp_messages_star_set_action(array('user_id' => $u2, 'message_id' => $m2));
     bp_messages_star_set_action(array('user_id' => $u2, 'message_id' => $m3));
     // delete the second thread
     $this->set_current_user($u2);
     messages_delete_thread($t2);
     // load the starred threads loop
     global $messages_template;
     add_filter('bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads');
     bp_has_message_threads();
     remove_filter('bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads');
     // assert that second thread isn't in starred thread loop
     $thread_ids = wp_list_pluck($messages_template->threads, 'thread_id');
     $this->assertFalse(in_array($t2, $thread_ids));
     // reset
     $this->set_current_user($old_current_user);
 }
Пример #2
0
 /**
  * Update a single message
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function update_item($request)
 {
     $id = (int) $request['id'];
     if (!messages_check_thread_access($id)) {
         return new WP_Error('bp_json_message_invalid_id', __('Message ID is invalid.'), array('status' => 400));
     }
     switch ($request['action']) {
         case 'read':
             messages_mark_thread_read($id);
             break;
         case 'unread':
             messages_mark_thread_unread($id);
             break;
         case 'star':
             $thread = new BP_Messages_thread($id);
             $mids = wp_list_pluck($thread->messages, 'id');
             bp_messages_star_set_action(array('action' => 'star', 'message_id' => $mids[0]));
             break;
         case 'unstar':
             bp_messages_star_set_action(array('action' => 'unstar', 'thread_id' => $id, 'bulk' => true));
             break;
             /* Single message */
             //            case 'star_single':
             //                bp_messages_star_set_action( array(
             //                    'action'     => 'star',
             //                    'message_id' => $id,
             //                ) );
             //                break;
             //            case 'unstar_single':
             //                bp_messages_star_set_action( array(
             //                    'action'     => 'unstar',
             //                    'message_id' => $id,
             //                ) );
             //                break;
     }
     $response = $this->get_item(array('id' => $id, 'context' => 'edit'));
     return rest_ensure_response($response);
 }
Пример #3
0
/**
 * AJAX callback to set a message's star status.
 *
 * @since BuddyPress (2.3.0)
 */
function bp_legacy_theme_ajax_messages_star_handler()
{
    if (false === bp_is_active('messages', 'star') || empty($_POST['message_id'])) {
        return;
    }
    // Check nonce
    check_ajax_referer('bp-messages-star-' . (int) $_POST['message_id'], 'nonce');
    // Check capability
    if (!is_user_logged_in() || !bp_core_can_edit_settings()) {
        return;
    }
    if (true === bp_messages_star_set_action(array('action' => $_POST['star_status'], 'message_id' => (int) $_POST['message_id'], 'bulk' => !empty($_POST['bulk']) ? true : false))) {
        echo '1';
        die;
    }
    echo '-1';
    die;
}
Пример #4
0
 function bp_course_messages_star()
 {
     if (function_exists('bp_messages_star_set_action') && is_numeric($_POST['message_id']) && in_array($_POST['star_status'], array('star', 'unstar'))) {
         echo bp_messages_star_set_action(array('action' => $_POST['star_status'], 'message_id' => $_POST['message_id'], 'bulk' => false));
     }
     die;
 }
/**
 * Bulk manage handler to set the star status for multiple messages.
 *
 * @since 2.3.0
 */
function bp_messages_star_bulk_manage_handler()
{
    if (empty($_POST['messages_bulk_nonce'])) {
        return;
    }
    // Check the nonce.
    if (!wp_verify_nonce($_POST['messages_bulk_nonce'], 'messages_bulk_nonce')) {
        return;
    }
    // Check capability.
    if (!is_user_logged_in() || !bp_core_can_edit_settings()) {
        return;
    }
    $action = !empty($_POST['messages_bulk_action']) ? $_POST['messages_bulk_action'] : '';
    $threads = !empty($_POST['message_ids']) ? $_POST['message_ids'] : '';
    $threads = wp_parse_id_list($threads);
    // Bail if action doesn't match our star actions or no IDs.
    if (false === in_array($action, array('star', 'unstar'), true) || empty($threads)) {
        return;
    }
    // It's star time!
    switch ($action) {
        case 'star':
            $count = count($threads);
            // If we're starring a thread, we only star the first message in the thread.
            foreach ($threads as $thread) {
                $thread = new BP_Messages_thread($thread);
                $mids = wp_list_pluck($thread->messages, 'id');
                bp_messages_star_set_action(array('action' => 'star', 'message_id' => $mids[0]));
            }
            bp_core_add_message(sprintf(_n('%s message was successfully starred', '%s messages were successfully starred', $count, 'buddypress'), $count));
            break;
        case 'unstar':
            $count = count($threads);
            foreach ($threads as $thread) {
                bp_messages_star_set_action(array('action' => 'unstar', 'thread_id' => $thread, 'bulk' => true));
            }
            bp_core_add_message(sprintf(_n('%s message was successfully unstarred', '%s messages were successfully unstarred', $count, 'buddypress'), $count));
            break;
    }
    // Redirect back to message box.
    bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/');
    die;
}