How to display the status of the user?
you can use template_preprocess_user  like 



 /**
 * Implements hook_entity_presave().
 */
function mytemplate_preprocess_user(&$variables) {
  // get user object
  $user = $variables['elements']['#user'];
  //- The user has logged in at least once
  if ($user->getLastLoginTime()) {
    if (account_is_logged_in_less_then_thirty_minutes($user->id())) {
      $status = 'Online';
    }
    else {
      $status = 'Absent';
    }
  }
  else {
    $status = 'offline';
  }
  $variables['status'] = $status;
}

/**
 * @param $uid
 *
 * @return bool
 */
function account_is_logged_in_less_then_thirty_minutes($uid) {
  $connection = Database::getConnection();
  $query = $connection->select('sessions', 'sessions')
    ->fields('sessions', ['sid', 'uid', 'timestamp'])
    ->condition('sessions.uid', $uid, '=')
    //- chef if the user was online in 30 minutes (60 * 30)
    ->condition('sessions.timestamp', \Drupal::time()
        ->getRequestTime() - (60 * 30), '>')
    ->execute();
  //- Get result.
  $results = $query->fetchAll(\PDO::FETCH_OBJ);
  return (count($results) > 0) ? TRUE : FALSE;
}



In you template check on status variable like the following:

{% if status == 'Online' %}
  &lt;i class="user-online fa fa-circle fa-lg"&gt;&lt;/i&gt; Online
{% elseif status == 'Absent' %}
  &lt;i class="user-absent fa fa-circle fa-lg"&gt;&lt;/i&gt; Absent
{% else %}
  &lt;i class="user-offline fa fa-circle fa-lg"&gt;&lt;/i&gt; Offline
{% endif %}


Add use Drupal\Core\Database\Database; to the top of your file.