You are here

function privatemsg_load_recipients in Privatemsg 6.2

Same name and namespace in other branches
  1. 7.2 privatemsg.pages.inc \privatemsg_load_recipients()
  2. 7 privatemsg.pages.inc \privatemsg_load_recipients()

Batch processing function for rebuilding the index.

1 string reference to 'privatemsg_load_recipients'
_privatemsg_handle_recipients in ./privatemsg.module
Handle the non-user recipients of a new message.

File

./privatemsg.pages.inc, line 789
User menu callbacks for Privatemsg.

Code

function privatemsg_load_recipients($mid, $recipient, &$context) {

  // Get type information.
  $type = privatemsg_recipient_get_type($recipient->type);

  // First run, initialize sandbox.
  if (!isset($context['sandbox']['current_offset'])) {
    $context['sandbox']['current_offset'] = 0;
    $count_function = $type['count'];
    $context['sandbox']['count'] = $count_function($recipient);
  }

  // Fetch the 10 next recipients.
  $load_function = $type['generate recipients'];
  $uids = $load_function($recipient, 10, $context['sandbox']['current_offset']);
  if (!empty($uids)) {
    foreach ($uids as $uid) {
      privatemsg_message_change_recipient($mid, $uid, 'hidden');
    }
    $context['sandbox']['current_offset'] += 10;

    // Set finished based on sandbox.
    $context['finished'] = empty($context['sandbox']['count']) ? 1 : $context['sandbox']['current_offset'] / $context['sandbox']['count'];
  }
  else {

    // If no recipients were returned, mark as finished too.
    $context['sandbox']['finished'] = 1;
  }

  // If we are finished, mark the recipient as read.
  if ($context['finished'] >= 1) {
    db_query("UPDATE {pm_index} SET is_new = %d WHERE mid = %d AND recipient = %d AND type = '%s'", PRIVATEMSG_READ, $mid, $recipient->recipient, $recipient->type);
  }
}