19 declare(strict_types=1);
37 $this->gui->switchToVisibleMode();
57 $username = $chat_user->{
64 if (!$failure && trim($username) !==
'') {
65 if (!$room->isSubscribed($chat_user->getUserId())) {
66 $chat_user->setUsername($chat_user->buildUniqueUsername($username));
71 $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'no_username_given'));
81 $this->mainTpl->addJavaScript(
'Modules/Chatroom/js/chat.js');
82 $this->mainTpl->addJavaScript(
'Modules/Chatroom/js/iliaschat.jquery.js');
83 $this->mainTpl->addJavaScript(
'node_modules/jquery-outside-events/jquery.ba-outside-events.js');
84 $this->mainTpl->addJavaScript(
'./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js');
86 $this->mainTpl->addCss(
'Modules/Chatroom/templates/default/style.css');
88 $this->mainTpl->setPermanentLink($this->gui->getObject()->getType(), $this->gui->getObject()->getRefId());
103 $this->
ilCtrl->getLinkTargetByClass(ilRepositoryGUI::class,
'view'),
108 $this->
cancelJoin($this->ilLng->txt(
'banned'));
113 $connector = $this->gui->getConnector();
117 $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'unable_to_connect'),
true);
118 $this->
ilCtrl->redirectByClass(ilInfoScreenGUI::class,
'info');
127 $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'unable_to_connect'),
true);
128 $this->
ilCtrl->redirectByClass(
'ilinfoscreengui',
'info');
135 $initial->redirect_url = $this->
ilCtrl->getLinkTarget($this->gui,
'view-lostConnection',
'',
false);
136 $initial->profile_image_url = $this->
ilCtrl->getLinkTarget($this->gui,
'view-getUserProfileImages',
'',
true);
138 $initial->subdirectory =
$settings->getSubDirectory();
140 $initial->userinfo = [
147 $initial->messages = [];
149 if ((
int) $room->
getSetting(
'display_past_msgs')) {
150 $initial->messages = array_merge(
156 $roomTpl =
new ilTemplate(
'tpl.chatroom.html',
true,
true,
'Modules/Chatroom');
157 $roomTpl->setVariable(
'BASEURL',
$settings->generateClientUrl());
158 $roomTpl->setVariable(
'INSTANCE',
$settings->getInstance());
159 $roomTpl->setVariable(
'SCOPE',
$scope);
160 $roomTpl->setVariable(
'POSTURL', $this->
ilCtrl->getLinkTarget($this->gui,
'postMessage',
'',
true));
162 $roomTpl->setVariable(
'ACTIONS', $this->ilLng->txt(
'actions'));
163 $roomTpl->setVariable(
'LBL_USER', $this->ilLng->txt(
'user'));
164 $roomTpl->setVariable(
'LBL_USER_TEXT', $this->ilLng->txt(
'invite_username'));
165 $showAutoMessages =
true;
166 if ($this->ilUser->getPref(
'chat_hide_automsg_' . $room->
getRoomId())) {
167 $showAutoMessages =
false;
171 $initial->state->scrolling =
true;
172 $initial->state->show_auto_msg = $showAutoMessages;
174 $roomTpl->setVariable(
'INITIAL_DATA', json_encode($initial, JSON_THROW_ON_ERROR));
175 $roomTpl->setVariable(
'INITIAL_USERS', json_encode($room->
getConnectedUsers(), JSON_THROW_ON_ERROR));
176 $roomTpl->setVariable(
'CHAT_OUTPUT', $this->
panel($this->ilLng->txt(
'messages'), $this->
legacy(
'<div id="chat_messages"></div>')));
177 $roomTpl->setVariable(
'CHAT_INPUT', $this->
panel($this->ilLng->txt(
'write_message'), $this->
sendMessageForm()));
183 $this->mainTpl->setContent($roomTpl->get());
189 $template =
new ilTemplate(
'tpl.chatroom_send_message_form.html',
true,
true,
'Modules/Chatroom');
192 return $this->
legacy($template->get());
197 $roomRightTpl =
new ilTemplate(
'tpl.chatroom_right.html',
true,
true,
'Modules/Chatroom');
200 return $this->
panel($this->ilLng->txt(
'users'), $this->
legacy($roomRightTpl->get()));
209 $this->ilLng->txt(
'auto_scroll'),
214 ->withAriaLabel($this->ilLng->txt(
'auto_scroll'))
216 return '$("#' . $id .
'").on("click", function(e) { 217 let t = $(this), msg = $("#chat_messages"); 218 if (t.hasClass("on")) { 219 msg.trigger("msg-scrolling:toggle", [true]); 221 msg.trigger("msg-scrolling:toggle", [false]); 226 $toggleUrl = $this->
ilCtrl->getFormAction($this->gui,
'view-toggleAutoMessageDisplayState',
'',
true,
false);
231 $this->ilLng->txt(
'chat_show_auto_messages'),
236 ->withAriaLabel($this->ilLng->txt(
'chat_show_auto_messages'))
237 ->
withOnLoadCode(
static function (
string $id) use ($toggleUrl):
string {
238 return '$("#' . $id .
'").on("click", function(e) { 239 let t = $(this), msg = $("#chat_messages"); 240 if (t.hasClass("on")) { 241 msg.trigger("auto-message:toggle", [true, "' . $toggleUrl .
'"]); 243 msg.trigger("auto-message:toggle", [false, "' . $toggleUrl .
'"]); 248 return $this->
panel($this->ilLng->txt(
'chat_functions'), [
249 $this->
legacy(
'<div id="chat_function_list"></div>'),
256 return sprintf(
'<div class="chatroom-centered-checkboxes">%s</div>', $this->uiRenderer->render($component));
261 return $this->uiFactory->legacy($html);
264 private function panel(
string $title, $body): string
266 $panel = $this->uiFactory->panel()->standard($title, $body);
268 return $this->uiRenderer->render($panel);
278 if ($this->
http->wrapper()->post()->has(
'state')) {
279 $state = $this->
http->wrapper()->post()->retrieve(
'state', $this->
refinery->kindlyTo()->int());
283 $this->ilUser->getId(),
284 'chat_hide_automsg_' . $room->getRoomId(),
285 (string) ((
int) (!(bool) $state))
288 $this->
http->saveResponse(
289 $this->
http->response()
290 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
291 ->withBody(Streams::ofString(json_encode([
'success' =>
true], JSON_THROW_ON_ERROR)))
293 $this->
http->sendResponse();
294 $this->
http->close();
302 $this->mainTpl->setOnScreenMessage(
'failure', $message);
307 $roomTpl->
setVariable(
'LBL_TOALL', $this->ilLng->txt(
'chat_message_to_all'));
308 $roomTpl->
setVariable(
'LBL_SEND', $this->ilLng->txt(
'send'));
314 'LBL_MAINROOM' =>
'chat_mainroom',
315 'LBL_LEFT_PRIVATE_ROOM' =>
'left_private_room',
316 'LBL_JOIN' =>
'chat_join',
317 'LBL_INVITE_TO_PRIVATE_ROOM' =>
'invite_to_private_room',
318 'LBL_KICK' =>
'chat_kick',
319 'LBL_BAN' =>
'chat_ban',
320 'LBL_KICK_QUESTION' =>
'kick_question',
321 'LBL_BAN_QUESTION' =>
'ban_question',
322 'LBL_ADDRESS' =>
'chat_address',
323 'LBL_WHISPER' =>
'chat_whisper',
324 'LBL_CONNECT' =>
'chat_connection_established',
325 'LBL_DISCONNECT' =>
'chat_connection_disconnected',
326 'LBL_TO_MAINROOM' =>
'chat_to_mainroom',
327 'LBL_WELCOME_TO_CHAT' =>
'welcome_to_chat',
328 'LBL_USER_INVITED' =>
'user_invited',
329 'LBL_USER_KICKED' =>
'user_kicked',
330 'LBL_USER_INVITED_SELF' =>
'user_invited_self',
331 'LBL_PRIVATE_ROOM_CLOSED' =>
'private_room_closed',
332 'LBL_PRIVATE_ROOM_ENTERED' =>
'private_room_entered',
333 'LBL_PRIVATE_ROOM_LEFT' =>
'private_room_left',
334 'LBL_PRIVATE_ROOM_ENTERED_USER' =>
'private_room_entered_user',
335 'LBL_KICKED_FROM_PRIVATE_ROOM' =>
'kicked_from_private_room',
337 'LBL_DELETE' =>
'delete',
338 'LBL_INVITE' =>
'chat_invite',
339 'LBL_CANCEL' =>
'cancel',
340 'LBL_WHISPER_TO' =>
'whisper_to',
341 'LBL_SPEAK_TO' =>
'speak_to',
342 'LBL_HISTORY_CLEARED' =>
'history_cleared',
343 'LBL_CLEAR_ROOM_HISTORY' =>
'clear_room_history',
344 'LBL_CLEAR_ROOM_HISTORY_QUESTION' =>
'clear_room_history_question',
345 'LBL_END_WHISPER' =>
'end_whisper',
346 'LBL_TIMEFORMAT' =>
'lang_timeformat_no_sec',
347 'LBL_DATEFORMAT' =>
'lang_dateformat',
349 foreach ($js_translations as $placeholder => $lng_variable) {
350 $roomTpl->
setVariable($placeholder, json_encode($this->ilLng->txt($lng_variable), JSON_THROW_ON_ERROR));
352 $this->ilLng->toJSMap([
353 'chat_user_x_is_typing' => $this->ilLng->txt(
'chat_user_x_is_typing'),
354 'chat_users_are_typing' => $this->ilLng->txt(
'chat_users_are_typing'),
357 $roomTpl->
setVariable(
'LBL_LAYOUT', $this->ilLng->txt(
'layout'));
358 $roomTpl->
setVariable(
'LBL_SHOW_SETTINGS', $this->ilLng->txt(
'show_settings'));
359 $roomTpl->
setVariable(
'LBL_USER_IN_ROOM', $this->ilLng->txt(
'user_in_room'));
360 $roomTpl->
setVariable(
'LBL_USER_IN_ILIAS', $this->ilLng->txt(
'user_in_ilias'));
361 $roomTpl->
setVariable(
'LBL_NO_USER', $this->ilLng->txt(
'msg_no_search_result'));
367 $roomTpl->
setVariable(
'LBL_NO_FURTHER_USERS', $this->ilLng->txt(
'no_further_users'));
374 $selectionForm = $formFactory->getUserChatNameSelectionForm($name_options);
376 $this->
ilCtrl->saveParameter($this->gui,
'sub');
378 $selectionForm->addCommandButton(
'view-joinWithCustomName', $this->ilLng->txt(
'enter'));
379 $selectionForm->setFormAction(
380 $this->
ilCtrl->getFormAction($this->gui,
'view-joinWithCustomName')
383 $this->mainTpl->setVariable(
'ADM_CONTENT', $selectionForm->getHTML());
396 $this->gui->switchToVisibleMode();
399 $chatSettings =
new ilSetting(
'chatroom');
400 if (!$chatSettings->get(
'chat_enabled',
'0')) {
401 $this->
ilCtrl->redirect($this->gui,
'settings-general');
406 if (!$room->getSetting(
'allow_anonymous') && $this->ilUser->isAnonymous()) {
407 $this->
cancelJoin($this->ilLng->txt(
'chat_anonymous_not_allowed'));
413 if ($room->getSetting(
'allow_custom_usernames')) {
414 if ($room->isSubscribed($chat_user->getUserId())) {
415 $chat_user->setUsername($chat_user->getUsername());
421 $chat_user->setUsername($this->ilUser->getLogin());
428 $pid = $this->tree->getParentId($this->gui->getRefId());
429 $this->
ilCtrl->setParameterByClass(ilRepositoryGUI::class,
'ref_id', $pid);
430 $this->
ilCtrl->redirectByClass(ilRepositoryGUI::class);
435 if ($this->
http->wrapper()->query()->has(
'msg')) {
436 match ($this->
http->wrapper()->query()->retrieve(
'msg', $this->
refinery->kindlyTo()->string())) {
437 'kicked' => $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'kicked'),
true),
438 'banned' => $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'banned'),
true),
439 default => $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'lost_connection'),
true),
442 $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'lost_connection'),
true);
445 $this->
ilCtrl->redirectByClass(ilInfoScreenGUI::class,
'info');
448 public function getUserProfileImages():
void 458 if (null === $usr_ids ||
'' === $usr_ids) {
462 $this->ilLng->loadLanguageModule(
'user');
466 $user_ids = array_filter(array_map(
'intval', array_map(
'trim', explode(
',', (
string) $usr_ids))));
470 $chatRoomUserDetailsByUsrId = array_combine(
472 static function (
stdClass $userData):
int {
473 return (
int) $userData->id;
483 foreach ($user_ids as $usr_id) {
484 if (!array_key_exists($usr_id, $chatRoomUserDetailsByUsrId)) {
488 if ($room->getSetting(
'allow_custom_usernames')) {
490 $avatar = $DIC[
"user.avatar.factory"]->avatar(
'xsmall');
494 $public_name = $chatRoomUserDetailsByUsrId[$usr_id]->login;
495 $public_image = $avatar->getUrl();
497 $public_image = $public_data[$usr_id][
'img'] ??
'';
499 if (isset($public_names[$usr_id])) {
500 $public_name = $public_names[$usr_id];
501 if (isset($public_data[$usr_id][
'login']) &&
'unknown' === $public_name) {
502 $public_name = $public_data[$usr_id][
'login'];
508 'public_name' => $public_name,
509 'profile_image' => $public_image,
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
getUserId()
Returns Ilias User ID.
renderLanguageVariables(ilTemplate $roomTpl)
panel(string $title, $body)
chatFunctions(bool $showAutoMessages)
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static initJS(ilGlobalTemplateInterface $a_main_tpl=null)
getRequestValue(string $key, Transformation $trafo, $default=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLastMessages(int $number, ilChatroomUser $chatuser)
renderSendMessageBox(ilTemplate $roomTpl)
static subStr(string $a_str, int $a_start, ?int $a_length=null)
getConnectedUsers(bool $only_data=true)
static getUserInformation(array $usrIds, ?int $roomId=null)
static setTokenMaxLifetimeInSeconds(int $token_max_lifetime_in_seconds)
withOnLoadCode(Closure $binder)
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cancelJoin(string $message)
Calls ilUtil::sendFailure method using given $message as parameter.
static http()
Fetches the global http state from ILIAS.
setVariable($variable, $value='')
Sets a variable value.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path='ilpublicuserprofilegui')
Default behaviour is:
hasRequestValue(string $key)
Class ilChatroomGUIHandler.
setupTemplate()
Adds CSS and JavaScript files that should be included in the header.
isSubscribed(int $chat_userid)
isUserBanned(int $user_id)
showRoom(ilChatroom $room, ilChatroomUser $chat_user)
Prepares and displays chatroom and connects user to it.
connectUser(ilChatroomUser $user)
getChatNameSuggestions()
Returns an array of chat-name suggestions.
executeDefault(string $requestedMethod)
Chatroom and Chatuser get prepared before $this->showRoom method is called.
sendResponse($response, bool $isJson=false)
Sends a json encoded response and exits the php process.
static byObjectId(int $object_id)
showNameSelection(ilChatroomUser $chat_user)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static _writePref(int $a_usr_id, string $a_keyword, string $a_value)
getUsername()
Returns username from Object or SESSION.
renderRightUsersBlock(ilTemplate $roomTpl)
checkbox(Component $component)
toggleAutoMessageDisplayState()