You are here

function privatemsg_rules_reply in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg_rules/privatemsg_rules.rules.inc \privatemsg_rules_reply()
  2. 7.2 privatemsg_rules/privatemsg_rules.rules.inc \privatemsg_rules_reply()

Helper function for replying to a thread.

File

privatemsg_rules/privatemsg_rules.rules.inc, line 311
Hooks and callback functions for rules.module integration.

Code

function privatemsg_rules_reply($args, $element) {
  $args['body'] = privatemsg_rules_replace_tokens($args['body']);
  rules_log('Writing reply to thread %thread_id from %author', array(
    '%thread_id' => $args['thread_id'],
    '%author' => $args['author']->name,
  ));
  $result = privatemsg_reply($args['thread_id'], $args['body'], $args);
  if ($result['success']) {
    rules_log('New message sucessfully sent, !link', array(
      '!link' => l(drupal_substr($args['body'], 0, 15), 'messages/view/' . $result['message']->thread_id),
    ));
  }
  else {
    foreach ($result['messages']['error'] as $message) {
      rules_log('Message not sent, reported error: !error', array(
        '!error' => $message,
      ), RulesLog::ERROR);
    }
  }
  foreach ($result['messages']['warning'] as $message) {
    rules_log('Warning message reported when trying to send message: !warning', array(
      '!warning' => $message,
    ), RulesLog::WARN);
  }
}