You are here

function privatemsg_thread_change_status in Privatemsg 6

Same name and namespace in other branches
  1. 6.2 privatemsg.module \privatemsg_thread_change_status()
  2. 7.2 privatemsg.module \privatemsg_thread_change_status()
  3. 7 privatemsg.module \privatemsg_thread_change_status()

Marks one or multiple threads as (un)read.

Parameters

$threads: Array with thread id's or a single thread id.

$status: Either PRIVATEMSG_READ or PRIVATEMSG_UNREAD, sets the new status.

$account: User object for which the threads should be deleted, defaults to the current user.

2 string references to 'privatemsg_thread_change_status'
hook_privatemsg_thread_operations in ./privatemsg.api.php
Expose operations/actions which can be executed on threads.
privatemsg_privatemsg_thread_operations in ./privatemsg.module
Implements hook_privatemsg_thread_operations().

File

./privatemsg.module, line 2223
Allows users to send private messages to other users.

Code

function privatemsg_thread_change_status($threads, $status, $account = NULL) {
  if (!is_array($threads)) {
    $threads = array(
      $threads,
    );
  }
  if (empty($account)) {
    global $user;
    $account = drupal_clone($user);
  }

  // Merge status and uid with the threads list. array_merge() will not overwrite/ignore thread_id 1.
  $params = array_merge(array(
    $status,
    $account->uid,
  ), $threads);
  db_query('UPDATE {pm_index} SET is_new = %d WHERE uid = %d AND thread_id IN (' . db_placeholders($threads) . ')', $params);
  if ($status == PRIVATEMSG_UNREAD) {
    drupal_set_message(format_plural(count($threads), 'Marked 1 thread as unread.', 'Marked @count threads as unread.'));
  }
  else {
    drupal_set_message(format_plural(count($threads), 'Marked 1 thread as read.', 'Marked @count threads as read.'));
  }
}