You are here

function privatemsg_service_reply in Privatemsg 6.2

Reply to an existing thread.

Parameters

$body: String. A message body

$thread_id: Integer. A thread ID.

Return value

Boolean. Return TRUE if replying to a thread was successful.

1 string reference to 'privatemsg_service_reply'
privatemsg_service_service in privatemsg_service/privatemsg_service.module
Implementation of hook_service().

File

privatemsg_service/privatemsg_service.inc, line 225
Link general private message module functionalities to services module.

Code

function privatemsg_service_reply($body, $thread_id) {

  // Make sure the message author is logged in.
  if (!user_is_logged_in()) {
    return services_error(t('Author is not logged in.'), 403);
  }

  // Make sure the body is not empty.
  if ($body == '') {
    return services_error(t('Please specify a body for this reply.'), 400);
  }

  // Verify that a thread id has been specified.
  if ($thread_id == '') {
    return services_error(t('Please specify a thread ID for this reply.'), 400);
  }

  // Load the full user object.
  global $user;
  $account = user_load($user->uid);

  // Attempt to send a reply.
  $result = privatemsg_reply($thread_id, $body, array(
    'author' => $account,
  ));

  // Return success status.
  if ($result['success']) {
    return TRUE;
  }
  elseif (!empty($result[0])) {
    return services_error($result[0], 404);
  }
  else {
    return services_error(implode("\n", $result['messages']['error']), 400);
  }
}