You are here

function messaging_message_prepare in Messaging 6

Same name and namespace in other branches
  1. 6.2 messaging.module \messaging_message_prepare()

Message default callback: preprocessing

Decide on queue, log, cron and send options, prepare parameters

2 calls to messaging_message_prepare()
Messaging_API_Tests::testMessagingBasicAPI in tests/messaging_api.test
Exercise basic API functions
messaging_message_send_user in ./messaging.module
Send message to user represented by account

File

./messaging.module, line 287

Code

function messaging_message_prepare($message, $info) {
  global $user;

  // Set some default values if not already set
  foreach (array(
    'sent' => 0,
    'queue' => 0,
    'cron' => 0,
    'log' => (bool) variable_get('messaging_log', 0),
    'sender' => $user->uid,
  ) as $field => $value) {
    if (!isset($message->{$field})) {
      $message->{$field} = $value;
    }
  }

  // If the messaging method is of type push, cron processing will be enabled
  if ($message->queue && $info['type'] & MESSAGING_TYPE_PUSH) {
    $message->cron = 1;
  }

  // It will be queued always for pull methods, cron disabled though so it will wait till it's pulled
  if (!$message->queue && $info['type'] & MESSAGING_TYPE_PULL) {
    $message->queue = 1;
    $message->cron = 0;
  }

  // Provides a hook for other modules to modify the message before sending
  foreach (module_implements('message_alter') as $module) {
    $function = $module . '_message_alter';
    $function($message, $info);
  }
  return $message;
}