You are here

function heartbeat_activity_poll in Heartbeat 6.4

Same name and namespace in other branches
  1. 7 heartbeat.pages.inc \heartbeat_activity_poll()

Callback to poll for newer messages.

1 string reference to 'heartbeat_activity_poll'
heartbeat_menu in ./heartbeat.module
Implementation of hook_menu().

File

./heartbeat.pages.inc, line 115
Separate codefile for page displays

Code

function heartbeat_activity_poll() {

  // if no stream is defined or the user does not have access
  if (!isset($_REQUEST['stream']) || !user_access('view heartbeat messages')) {
    return drupal_json(array(
      'status' => FALSE,
      'data' => '',
    ));
  }
  $latest_uaid = $_REQUEST['latestUaid'];
  $access_type = $_REQUEST['stream'];
  $context = heartbeat_stream_view($access_type, TRUE, 0, TRUE);
  if (!isset($context)) {
    return drupal_json(array(
      'status' => TRUE,
      'data' => '',
    ));
  }
  $heartbeataccess = $context
    ->getState();
  $heartbeataccess->stream->latest_uaid = $latest_uaid;

  // change the language with the post value
  if (isset($_REQUEST['language'])) {

    //$heartbeataccess->stream->language = $_REQUEST['language'];
  }
  $context
    ->updateState($heartbeataccess);

  // Get the messages
  $messages = $context
    ->execute();
  $json = array(
    'status' => TRUE,
    'stream' => $heartbeataccess->stream->name,
    'data' => theme('heartbeat_messages', $messages, $context
      ->getState()),
    'time_updates' => array(),
  );

  // Get the times to update to the current time
  if (!empty($_REQUEST['uaids'])) {
    $uaids = explode(',', $_REQUEST['uaids']);
    $placeholders = implode(',', array_fill(0, count($uaids), "%d"));
    $result = db_query("SELECT uaid, timestamp FROM {heartbeat_activity} WHERE uaid IN({$placeholders}) ", $uaids);
    while ($row = db_fetch_object($result)) {
      $json['time_updates'][$row->uaid] = theme('heartbeat_time_ago', $row);
    }
  }
  return drupal_json($json);
}