You are here

function privatemsg_service_get_thread in Privatemsg 6.2

Get all messages in a thread.

Parameters

<int> @thread_id: ID of the thread to be loaded.

<int> $offset: Optional: Message offset from the start of the thread.

Return value

An array of messages in a thread.

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

File

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

Code

function privatemsg_service_get_thread($thread_id, $offset = 0) {

  // Return if wrong paramters are passed.
  if (!$thread_id || !is_numeric($thread_id)) {
    return services_error(t('Invalid parameters passed'), 400);
  }

  // Make sure the user is logged in.
  global $user;
  $account = user_load($user->uid);
  if (!user_is_logged_in()) {
    return services_error(t('The user is not logged in.'), 403);
  }

  // Return the full thread.
  $thread = privatemsg_thread_load($thread_id, $account, $offset);

  // Simplify thread object and enhance messages.
  $thread = _privatemsg_service_process_thread($thread);

  // Resort the array keys for messages starting at 0.
  $thread['messages'] = array_values($thread['messages']);
  return $thread;
}