Exemple #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);
 }
Exemple #2
0
 /**
  * @group bp_messages_delete_meta
  * @group messages_delete_thread
  */
 public function test_bp_messages_delete_metadata_cache_on_thread_delete()
 {
     $this->old_current_user = get_current_user_id();
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     // create the thread
     $t1 = $this->factory->message->create(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'Oy'));
     // create a reply
     $this->factory->message->create(array('thread_id' => $t1, 'sender_id' => $u2, 'recipients' => array($u1), 'content' => 'Yo'));
     // add message meta
     list($m1, $m2) = $this->get_message_ids($t1);
     bp_messages_update_meta($m1, 'yolo', 'gah');
     bp_messages_update_meta($m2, 'yolo', 'bah');
     // prime message meta cache
     bp_messages_get_meta($m1, 'yolo');
     bp_messages_get_meta($m2, 'yolo');
     // delete thread
     // to outright delete a thread, both recipients must delete it
     $this->set_current_user($u1);
     messages_delete_thread($t1);
     $this->set_current_user($u2);
     messages_delete_thread($t1);
     // assert empty meta cache
     $this->assertEmpty(wp_cache_get($m1, 'message_meta'));
     $this->assertEmpty(wp_cache_get($m2, 'message_meta'));
     // cleanup
     $this->set_current_user($this->old_current_user);
 }
function messages_action_bulk_delete()
{
    if (!bp_is_messages_component() || !bp_is_action_variable('bulk-delete', 0)) {
        return false;
    }
    $thread_ids = $_POST['thread_ids'];
    if (!$thread_ids || !messages_check_thread_access($thread_ids)) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action()));
    } else {
        if (!check_admin_referer('messages_delete_thread')) {
            return false;
        }
        if (!messages_delete_thread($thread_ids)) {
            bp_core_add_message(__('There was an error deleting messages.', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Messages deleted.', 'buddypress'));
        }
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action()));
    }
}
Exemple #4
0
function messages_action_bulk_delete() {
	global $bp, $thread_ids;

	if ( $bp->current_component != $bp->messages->slug || $bp->action_variables[0] != 'bulk-delete' )
		return false;

	$thread_ids = $_POST['thread_ids'];

	if ( !$thread_ids || !messages_check_thread_access($thread_ids) ) {
		bp_core_redirect( $bp->displayed_user->domain . $bp->current_component . '/' . $bp->current_action );
	} else {
		if ( !check_admin_referer( 'messages_delete_thread' ) )
			return false;

		if ( !messages_delete_thread( $thread_ids ) ) {
			bp_core_add_message( __('There was an error deleting messages.', 'buddypress'), 'error' );
		} else {
			bp_core_add_message( __('Messages deleted.', 'buddypress') );
		}
		bp_core_redirect( $bp->loggedin_user->domain . $bp->current_component . '/' . $bp->current_action );
	}
}
/**
 * Delete a private message(s) in your inbox via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_legacy_theme_ajax_messages_delete()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    if (!isset($_POST['thread_ids'])) {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem deleting messages.', 'buddypress') . '</p></div>';
    } else {
        $thread_ids = wp_parse_id_list($_POST['thread_ids']);
        messages_delete_thread($thread_ids);
        _e('Messages deleted.', 'buddypress');
    }
    exit;
}
 /**
  * @group get_recipients
  * @group cache
  */
 public function test_get_recipients_cache_should_be_busted_when_array_of_threads_is_deleted()
 {
     global $wpdb;
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $t1 = $this->factory->message->create(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'Foo'));
     $thread = new BP_Messages_Thread($t1);
     $recipients = $thread->get_recipients();
     // Verify that the cache is populated.
     $num_queries = $wpdb->num_queries;
     $recipients_cached = $thread->get_recipients();
     $this->assertEquals($num_queries, $wpdb->num_queries);
     messages_delete_thread(array($t1));
     // Cache should be empty.
     $this->assertFalse(wp_cache_get('thread_recipients_' . $t1, 'bp_messages'));
 }
Exemple #7
0
 /**
  * Delete a single message
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function delete_item($request)
 {
     $id = (int) $request['id'];
     if (!bp_thread_has_messages(array('thread_id' => $id))) {
         return new WP_Error('bp_json_message', __('Message Not Found.', BP_API_PLUGIN_SLUG), array('status' => 404));
     }
     $deleted = messages_delete_thread($id);
     if (!$deleted) {
         return new WP_Error('bp_json_message_cannot_be_deleted', __('The message cannot be deleted.', BP_API_PLUGIN_SLUG), array('status' => 500));
     }
     return new WP_Error('bp_json_message_deleted', __('Message deleted successfully.', BP_API_PLUGIN_SLUG), array('status' => 200));
 }
 /**
  * @ticket BP6329
  */
 public function test_messages_notifications_should_be_deleted_when_corresponding_message_is_deleted()
 {
     if (!bp_is_active('messages')) {
         $this->markTestSkipped(__METHOD__ . ' requires the Messages component.');
     }
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $t1 = messages_new_message(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'A new message', 'content' => 'Hey there!'));
     // Verify that a notification has been created for the message.
     $n1 = BP_Notifications_Notification::get(array('component' => 'messages', 'user_id' => $u2));
     $this->assertNotEmpty($n1);
     $this->assertTrue(messages_delete_thread($t1));
     $n2 = BP_Notifications_Notification::get(array('component' => 'messages', 'user_id' => $u2));
     $this->assertSame(array(), $n2);
 }