You are here

function privatemsg_service_unread_count in Privatemsg 6.2

Get the number of unread private messages of the logged-in user.

Return value

The unread count.

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

File

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

Code

function privatemsg_service_unread_count($uid = '') {

  // User needs to be authenticated to proceed.
  global $user;
  if (!user_is_logged_in()) {
    return services_error(t('This user is not logged in.'), 403);
  }

  // If a user id other than the current user's ID is passed,
  // validate that the authenticated user has the correct
  // permissions to read another user's messages.
  if (is_numeric($uid) && $uid != $user->uid) {
    if (user_access("read all private messages")) {
      $account = user_load($uid);
    }
    else {
      return services_error(t('This user does not have permissions to use this service.'), 403);
    }
  }
  else {
    $account = $user;
  }

  // Return unread count.
  return privatemsg_unread_count($account);
}