function messaging_message_send_user in Messaging 6.2
Same name and namespace in other branches
- 5 messaging.module \messaging_message_send_user()
- 6.4 messaging.module \messaging_message_send_user()
- 6 messaging.module \messaging_message_send_user()
- 6.3 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 168
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
$message = (object) $message;
$params = array(
'message' => $message,
// Get default sending method, or default for this user account
'method' => $method ? $method : messaging_method_default($account),
'queue' => $queue,
'account' => $account,
'log' => TRUE,
);
// Check user and availability if there's a callback for that. Depending on the sending method,
// when user is not available it may just be discarded / queued / redirected through other method
if ($callback = messaging_method_info($method, 'user callback')) {
$params = _messaging_callback_invoke($callback, $params);
}
// Set the parameters back into variables. I don't like extract()
$method = $params['method'];
$queue = $params['queue'];
// Now check that we have a destination for this user account. If set to FALSE we just don't try anymore
if (isset($params['destination'])) {
$destination = $params['destination'];
}
elseif ($account) {
$destination = messaging_user_destination($account, $method, $message);
}
// Set some values into the message
$message->method = $method;
$message->account = $account;
// Send the message or, if no destination, abort the message sending
if (!empty($destination)) {
messaging_debug('Found destination for user, sending message', array(
'method' => $method,
'destination' => $destination,
));
return messaging_message_send(array(
$destination,
), $message, $method, $queue);
}
elseif (!empty($params['log'])) {
// Save the message, let it there for further reference
messaging_log('Destination not available for user account', array(
'method' => $method,
'account' => $account,
));
$message->destination = 'ERROR';
if ($info = messaging_method_info($method)) {
$message = messaging_message_prepare($message, $info);
$message = messaging_message_render($message, $info);
}
else {
$message->subject = $message->body = '';
}
$message->cron = $message->queue = 0;
$message->log = 1;
$message->success = FALSE;
$message = messaging_store('save', $message);
}
return FALSE;
}