function privatemsg_thread_change_status

1 privatemsg.module privatemsg_thread_change_status($threads, $status, $account = NULL)
7-1 privatemsg.module privatemsg_thread_change_status($threads, $status, $account = NULL)
7-2 privatemsg.module privatemsg_thread_change_status($threads, $status, $account = NULL)
6-2 privatemsg.module privatemsg_thread_change_status($threads, $status, $account = NULL)

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'

File

./privatemsg.module, line 2121
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 = clone $user;
  }
  // Merge status and uid with the existing thread list.
  $params = array(
    ':status' => $status,
    ':recipient' => $account->uid,
    ':threads' => $threads,
  );

  // Record which messages will change status.
  $result = db_query("SELECT mid FROM {pm_index} WHERE is_new <> :status AND recipient = :recipient and type IN ('user', 'hidden') AND thread_id IN (:threads)", $params);
  $changed = $result->fetchCol();

  // Update the status of the threads.
  db_update('pm_index')->fields(array('is_new' => $status))->condition('thread_id', $threads)->condition('recipient', $account->uid)->condition('type', array('user', 'hidden'))->execute();

  // Allow modules to respond to the status changes.
  foreach ($changed as $mid) {
    module_invoke_all('privatemsg_message_status_changed', $mid, $status, $account);
  }

  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.'));
  }
}