/**
  */
 protected function getMessages()
 {
     /**
      * @var $ilAccess ilAccessHandler
      * @var $ilUser   ilObjUser
      * @var $lng	  ilLanguage
      */
     global $ilAccess, $ilUser, $lng;
     $result = new stdClass();
     $result->ok = false;
     if (!(int) $_REQUEST['ref_id']) {
         echo ilJsonUtil::encode($result);
         exit;
     }
     /**
      * @var $object ilObjChatroom
      */
     $object = ilObjectFactory::getInstanceByRefId((int) $_REQUEST['ref_id'], false);
     if (!$object || !$ilAccess->checkAccess('read', '', $_REQUEST['ref_id'])) {
         ilObjUser::_writePref($ilUser->getId(), 'chatviewer_last_selected_room', 0);
         $result->errormsg = $lng->txt('msg_no_perm_read');
         echo ilJsonUtil::encode($result);
         exit;
     }
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     $room = ilChatroom::byObjectId($object->getId());
     $block = new ilChatroomBlock();
     $msg = $block->getMessages($room);
     $ilUser->setPref('chatviewer_last_selected_room', $object->getRefId());
     ilObjUser::_writePref($ilUser->getId(), 'chatviewer_last_selected_room', $object->getRefId());
     $result->messages = array_reverse($msg);
     $result->ok = true;
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     echo ilJsonUtil::encode($result);
     exit;
 }