You are here

function messaging_message_send_user in Messaging 6.3

Same name and namespace in other branches
  1. 5 messaging.module \messaging_message_send_user()
  2. 6.4 messaging.module \messaging_message_send_user()
  3. 6 messaging.module \messaging_message_send_user()
  4. 6.2 messaging.module \messaging_message_send_user()

Send message to user represented by account

We are applying same output filter for everybody, depending on send method

The final rendering of the message depends on send method too. I.e. a mail messaging method may want to insert '--' before the body footer.

@ TODO Consider whether it makes sense to allow users decide on formatting

Parameters

$account: User object to recieve message.

$message: Array of message parts that will be compiled depending on send method. Mandatory message parts, which may have nexted parts are:

  • 'type'
  • 'subject'
  • 'body'. The message body may have 'header', 'content', 'footer', 'etc'

$method: Optional send method. Defaults to the user account predefined method

3 calls to messaging_message_send_user()
Messaging_API_Tests::testMessagingSendingAPI in tests/messaging_api.test
Play with creating, retrieving, deleting a pair messages
messaging_debug_post_form_submit in messaging_debug/messaging_debug.module
Post test message
Messaging_Methods_Tests::testMessagingMethods in tests/messaging_methods.test
Test message sending callbacks for enabled plug-ins

File

./messaging.module, line 179

Code

function messaging_message_send_user($account, $message, $method = NULL, $queue = 0) {
  messaging_debug('Sending message to user', array(
    'account' => $account,
    'message' => $message,
    'method' => $method,
  ));

  // Build array of parameters so they can be overridden by callbacks
  $method = $method ? $method : messaging_method_default($account);
  $message = messaging_message_build($message);
  $message->method = $method;
  $message->queue = $queue;

  // Now check that we have a destination for this user account. If set to FALSE we just don't try anymore
  $message->destination = messaging_user_destination($account, $method);
  $message
    ->set_user($account);

  // Send the message or, if no destination, abort the message sending
  if (!empty($message->destination)) {
    messaging_debug('Found destination for user, sending message', array(
      'method' => $method,
      'destination' => $message->destination,
    ));
    return $message
      ->send();
  }
  else {

    // Save the message, let it there for further reference
    messaging_log('Destination not available for user account', array(
      'method' => $method,
      'account' => $account,
    ));
    $message
      ->set_error('Destination not available for user account');
  }
  return FALSE;
}