Example #1
1
 /**
  * Get all messages
  *
  * @param WP_REST_Request $request
  * @return array|WP_Error
  */
 public function get_items($request)
 {
     /* filter messages */
     $args = array();
     $args['box'] = $request['box'];
     if ($request['box'] == 'starred') {
         $args['meta_query'] = array(array('key' => 'starred_by_user', 'value' => bp_loggedin_user_id()));
     }
     if (isset($request['filter'])) {
         $args = array_merge($args, $request['filter']);
         unset($args['filter']);
     }
     global $messages_template;
     $data = array();
     if (bp_has_message_threads($args)) {
         while (bp_message_threads()) {
             bp_message_thread();
             $single_msg = array('thread_id' => $messages_template->thread->thread_id, 'read' => bp_message_thread_has_unread() ? false : true, 'total_messages' => bp_get_message_thread_total_count($messages_template->thread->thread_id), 'unread_messages' => bp_get_message_thread_unread_count($messages_template->thread->thread_id), 'avatar' => bp_core_fetch_avatar(array('item_id' => $messages_template->thread->last_sender_id, 'width' => 25, 'height' => 25, 'html' => false)), 'from' => bp_core_get_username($messages_template->thread->last_sender_id), 'from_id' => $messages_template->thread->last_sender_id, 'last_message_date' => $messages_template->thread->last_message_date, 'subject' => bp_get_message_thread_subject(), 'excerpt' => bp_get_message_thread_excerpt(), 'content' => bp_get_message_thread_content());
             if (bp_is_active('messages', 'star')) {
                 $single_msg['star'] = strpos(bp_get_the_message_star_action_link(array('thread_id' => bp_get_message_thread_id())), 'unstar') ? true : false;
             }
             if ($args['box'] == 'sentbox') {
                 foreach ($messages_template->thread->recipients as $user => $userdata) {
                     if ((int) $user !== bp_loggedin_user_id()) {
                         $single_msg['to'][$user]['name'] = bp_core_get_username($user);
                     }
                 }
             }
             $links['self'] = array('href' => rest_url(sprintf(BP_API_SLUG . '/messages/%d', $messages_template->thread->thread_id)));
             if ($args['box'] == 'sentbox') {
                 $links['collection'] = array('href' => rest_url(BP_API_SLUG . '/messages?box=sentbox'));
             } else {
                 $links['collection'] = array('href' => rest_url(BP_API_SLUG . '/messages/'));
             }
             $single_msg['_links'] = $links;
             $data[] = $single_msg;
         }
     } else {
         return new WP_Error('bp_json_messages', __('No Messages Found.', BP_API_PLUGIN_SLUG), array('status' => 200));
     }
     $data = apply_filters('bp_json_prepare_messages', $data);
     return new WP_REST_Response($data, 200);
 }
function bp_message_thread_unread_count()
{
    echo bp_get_message_thread_unread_count();
}
/**
 * Get markup for the current thread's total and unread count.
 *
 * @param int|bool $thread_id Optional. ID of the thread. Default: current thread ID.
 * @return string Markup displaying the total and unread count for the thread.
 */
function bp_get_message_thread_total_and_unread_count($thread_id = false)
{
    if (false === $thread_id) {
        $thread_id = bp_get_message_thread_id();
    }
    $total = bp_get_message_thread_total_count($thread_id);
    $unread = bp_get_message_thread_unread_count($thread_id);
    return sprintf('<span class="thread-count">(%1$s)</span> <span class="bp-screen-reader-text">%2$s</span>', number_format_i18n($total), sprintf(_n('%d unread', '%d unread', $unread, 'buddypress'), number_format_i18n($unread)));
}
Example #4
0
            ?>
					</td>
				<?php 
        } else {
            ?>
					<td class="thread-from">
						<?php 
            bp_message_thread_to();
            ?>
<br />
						<span class="activity"><?php 
            bp_message_thread_last_post_date();
            ?>
</span>
						<?php 
            if (bp_get_message_thread_unread_count() != 0) {
                ?>
							<span class="x-bp-count"><?php 
                bp_message_thread_unread_count();
                ?>
</span>
						<?php 
            }
            ?>
					</td>
				<?php 
        }
        ?>

				<td class="thread-info">
					<a href="<?php 
Example #5
0
        if (bp_message_thread_has_unread()) {
            ?>
 unread <?php 
        } else {
            ?>
 read<?php 
        }
        ?>
">
                           
                            <div class="message-metadata">
				<span class="thread-avatar"><?php 
        bp_message_thread_avatar();
        ?>
                                    <span class="unread-count"><?php 
        $count = bp_get_message_thread_unread_count();
        if (empty($count)) {
            $count = 0;
        }
        echo $count;
        ?>
</span>
                                </span>

				<?php 
        if ('sentbox' != bp_current_action()) {
            ?>
					<strong  class="thread-from">
						 <?php 
            bp_message_thread_from();
            ?>