You are here

function _privatemsg_load_thread_participants in Privatemsg 6.2

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

Load all participants of a thread, optionally without author.

Parameters

$thread_id: Thread ID for wich the participants should be loaded.

$account: For which account should the messages be loaded. *

$ignore_hidden: Ignores hidden participants.

$access: Which access permission should be checked (write or view).

Return value

Array with all visible/writable participants for that thread.

3 calls to _privatemsg_load_thread_participants()
privatemsg_new_validate in ./privatemsg.pages.inc
privatemsg_reply in ./privatemsg.module
Send a reply message
privatemsg_thread_load in ./privatemsg.module
Load a thread with all the messages and participants.

File

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

Code

function _privatemsg_load_thread_participants($thread_id, $account, $ignore_hidden = TRUE, $access = 'write') {
  $query = _privatemsg_assemble_query('participants', $thread_id, $account);
  $result = db_query($query['query']);
  $participants = array();
  $to_load = array();
  while ($participant = db_fetch_object($result)) {
    if ($ignore_hidden && $participant->type == 'hidden') {
      continue;
    }
    if ($participant->type == 'user' || $participant->type == 'hidden') {
      if ($participant = privatemsg_user_load($participant->recipient)) {
        $participants[privatemsg_recipient_key($participant)] = $participant;
      }
    }
    elseif (privatemsg_recipient_access($participant->type, $access, $participant)) {
      $to_load[$participant->type][] = $participant->recipient;
    }
  }

  // Now, load all non-user recipients.
  foreach ($to_load as $type => $ids) {
    $type_info = privatemsg_recipient_get_type($type);
    if (isset($type_info['load']) && is_callable($type_info['load'])) {
      $loaded = $type_info['load']($ids);
      if (is_array($loaded)) {
        $participants += $loaded;
      }
    }
  }
  if ($access == 'write' && $account) {

    // Remove author if loading participants for writing and when he is not the
    // only recipient.
    if (isset($participants['user_' . $account->uid]) && count($participants) > 1) {
      unset($participants['user_' . $account->uid]);
    }
  }
  return $participants;
}