19 declare(strict_types=1);
39 $this->gui->switchToVisibleMode();
45 $custom_username =
false;
52 $custom_username =
true;
61 $username = $chat_user->{
68 if (!$failure && trim($username) !==
'') {
69 if (!$room->isSubscribed($chat_user->getUserId())) {
70 $chat_user->setUsername($chat_user->buildUniqueUsername($username));
71 $chat_user->setProfilePictureVisible(!$custom_username);
76 $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'no_username_given'));
87 $this->mainTpl->addJavaScript(
'assets/js/socket.io.min.js');
88 $this->mainTpl->addJavaScript(
'assets/js/Chatroom.min.js');
89 $this->mainTpl->addJavaScript(
'assets/js/AdvancedSelectionList.js');
91 $this->mainTpl->setPermanentLink($this->gui->getObject()->getType(), $this->gui->getObject()->getRefId());
106 $this->
ilCtrl->getLinkTargetByClass(ilRepositoryGUI::class,
'view'),
111 $this->
cancelJoin($this->ilLng->txt(
'banned'));
116 $connector = $this->gui->getConnector();
120 $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'unable_to_connect'),
true);
121 $this->
ilCtrl->redirectByClass(ilInfoScreenGUI::class,
'showSummary');
130 $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'unable_to_connect'),
true);
131 $this->
ilCtrl->redirectByClass(ilInfoScreenGUI::class,
'showSummary');
136 fn($entry) => $entry->type !==
'notice' 140 $show_auto_messages = !$this->ilUser->getPref(
'chat_hide_automsg_' . $room->
getRoomId());
144 $room_tpl = $build->template(
false, $build->initialData(
147 $this->
ilCtrl->getLinkTarget($this->gui,
'view-lostConnection',
'',
false),
149 'moderator' => $is_moderator,
156 ), $this->
panel($this->ilLng->txt(
'write_message'), $this->
sendMessageForm()), $this->
panel($this->ilLng->txt(
'messages'), $this->
legacy(
'<div id="chat_messages"></div>')));
158 $this->mainTpl->setContent($room_tpl->get());
159 $this->mainTpl->setRightContent($this->
userList() . $this->
chatFunctions($show_auto_messages, $is_moderator));
166 return $build->template(
true, $build->initialData([],
true,
null, [
167 'moderator' =>
false,
170 'broadcast_typing' =>
false,
171 ], $messages), $this->
panel($this->ilLng->txt(
'messages'), $this->
legacy(
'<div id="chat_messages"></div>')),
'');
176 $template =
new ilTemplate(
'tpl.chatroom_send_message_form.html',
true,
true,
'components/ILIAS/Chatroom');
179 return $this->
legacy($template->get());
184 $roomRightTpl =
new ilTemplate(
'tpl.chatroom_right.html',
true,
true,
'components/ILIAS/Chatroom');
187 return $this->
panel($this->ilLng->txt(
'users'), $this->
legacy($roomRightTpl->get()));
190 private function chatFunctions(
bool $show_auto_messages,
bool $is_moderator): string
192 $txt = $this->ilLng->txt(...);
193 $js_escape = json_encode(...);
194 $format = fn($format, ...$args) => sprintf($format, ...
array_map($js_escape, $args));
195 $register = fn($name,
$c) =>
$c->withOnLoadCode(fn(
$id) => $format(
196 'il.Chatroom.bus.send(%s, document.getElementById(%s));',
201 $b = $this->uiFactory->button();
202 $toggle = fn($label, $enabled) =>
$b->toggle($label,
'#',
'#', $enabled)->withAriaLabel($label);
204 $bind = fn($key, $m) => $m->withAdditionalOnLoadCode(fn(
string $id) => $format(
205 '$(() => il.Chatroom.bus.send(%s, { 206 node: document.getElementById(%s), 207 showModal: () => $(document).trigger(%s, {}), 208 closeModal: () => $(document).trigger(%s, {}) 212 $m->getShowSignal()->getId(),
213 $m->getCloseSignal()->getId()
216 $interrupt = fn($key, $label, $text, $button =
null) => $bind($key, $this->uiFactory->modal()->interruptive(
220 ))->withActionButtonLabel($button ?? $label);
222 $auto_scroll = $register(
'auto-scroll-toggle', $toggle(
$txt(
'auto_scroll'),
true));
223 $messages = $register(
'system-messages-toggle', $toggle(
$txt(
'chat_show_auto_messages'), $show_auto_messages));
225 $invite = $bind(
'invite-modal', $this->uiFactory->modal()->roundtrip(
$txt(
'chat_invite'), $this->
legacy(
$txt(
'invite_to_private_room')), [
226 $this->uiFactory->input()->field()->text(
$txt(
'chat_invite')),
227 ])->withSubmitLabel(
$txt(
'chat_invite')));
230 $buttons[] = $register(
'invite-button',
$b->shy(
$txt(
'invite_to_private_room'),
''));
232 $buttons[] = $register(
'clear-history-button',
$b->shy(
$txt(
'clear_room_history'),
''));
235 return $this->
panel(
$txt(
'chat_functions'), [
236 $this->
legacy(
'<div id="chat_function_list">'),
239 $interrupt(
'kick-modal',
$txt(
'chat_kick'),
$txt(
'kick_question')),
240 $interrupt(
'ban-modal',
$txt(
'chat_ban'),
$txt(
'ban_question')),
241 $interrupt(
'clear-history-modal',
$txt(
'clear_room_history'),
$txt(
'clear_room_history_question')),
249 return sprintf(
'<div class="chatroom-centered-checkboxes">%s</div>', $this->uiRenderer->render($component));
254 return $this->uifactory->legacy()->content($html);
260 private function panel(
string $title, $body): string
262 if (is_array($body)) {
263 $body = $this->uiFactory->legacy()->content(join(
'',
array_map($this->uiRenderer->render(...), $body)));
265 $panel = $this->uiFactory->panel()->secondary()->legacy($title, $body);
267 return $this->uiRenderer->render($panel);
277 if ($this->
http->wrapper()->post()->has(
'state')) {
278 $state = $this->
http->wrapper()->post()->retrieve(
'state', $this->
refinery->kindlyTo()->int());
282 $this->ilUser->getId(),
283 'chat_hide_automsg_' . $room->getRoomId(),
284 (string) ((
int) (!(bool) $state))
287 $this->
http->saveResponse(
288 $this->
http->response()
289 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
290 ->withBody(Streams::ofString(json_encode([
'success' =>
true], JSON_THROW_ON_ERROR)))
292 $this->
http->sendResponse();
293 $this->
http->close();
301 $this->mainTpl->setOnScreenMessage(
'failure', $message);
306 $roomTpl->
setVariable(
'PLACEHOLDER', $this->ilLng->txt(
'chat_osc_write_a_msg'));
307 $roomTpl->
setVariable(
'LBL_SEND', $this->ilLng->txt(
'send'));
312 $roomTpl->
setVariable(
'LBL_NO_FURTHER_USERS', $this->ilLng->txt(
'no_further_users'));
319 $selectionForm = $formFactory->getUserChatNameSelectionForm($name_options);
321 $this->
ilCtrl->saveParameter($this->gui,
'sub');
323 $selectionForm->addCommandButton(
'view-joinWithCustomName', $this->ilLng->txt(
'enter'));
324 $selectionForm->setFormAction(
325 $this->
ilCtrl->getFormAction($this->gui,
'view-joinWithCustomName')
328 $this->mainTpl->setVariable(
'ADM_CONTENT', $selectionForm->getHTML());
341 $this->gui->switchToVisibleMode();
344 $chatSettings =
new ilSetting(
'chatroom');
345 if (!$chatSettings->get(
'chat_enabled',
'0')) {
346 $this->
ilCtrl->redirect($this->gui,
'settings-general');
351 if (!$room->getSetting(
'allow_anonymous') && $this->ilUser->isAnonymous()) {
352 $this->
cancelJoin($this->ilLng->txt(
'chat_anonymous_not_allowed'));
358 if ($room->getSetting(
'allow_custom_usernames')) {
359 if ($room->isSubscribed($chat_user->getUserId())) {
360 $chat_user->setUsername($chat_user->getUsername());
366 $chat_user->setUsername($this->ilUser->getPublicName());
367 $chat_user->setProfilePictureVisible(
true);
374 $pid = $this->tree->getParentId($this->gui->getRefId());
375 $this->
ilCtrl->setParameterByClass(ilRepositoryGUI::class,
'ref_id', $pid);
376 $this->
ilCtrl->redirectByClass(ilRepositoryGUI::class);
381 if ($this->
http->wrapper()->query()->has(
'msg')) {
382 match ($this->
http->wrapper()->query()->retrieve(
'msg', $this->
refinery->kindlyTo()->string())) {
383 'kicked' => $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'kicked'),
true),
384 'banned' => $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'banned'),
true),
385 default => $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'lost_connection'),
true),
388 $this->mainTpl->setOnScreenMessage(
'failure', $this->ilLng->txt(
'lost_connection'),
true);
391 $this->
ilCtrl->redirectByClass(ilInfoScreenGUI::class,
'showSummary');
394 public function getUserProfileImages():
void 400 $request = json_decode($this->
http->request()->getBody()->getContents(),
true, 512, JSON_THROW_ON_ERROR);
405 $this->refinery->kindlyTo()->recordOf([
406 'id' => $this->
refinery->kindlyTo()->int(),
407 'username' => $this->
refinery->kindlyTo()->string(),
408 'profile_picture_visible' => $this->
refinery->kindlyTo()->bool(),
410 $this->
refinery->kindlyTo()->recordOf([
411 'id' => $this->
refinery->kindlyTo()->int(),
412 'username' => $this->
refinery->kindlyTo()->string(),
414 ]))->
transform($request[
'profiles'] ?? []);
416 $user_ids = array_column($users,
'id');
420 foreach ($users as $user) {
421 if ($user[
'profile_picture_visible'] ??
false) {
422 $public_image = $public_data[$user[
'id']][
'img'] ??
'';
425 $avatar = $DIC[
"user.avatar.factory"]->avatar(
'xsmall');
428 $public_image = $avatar->getUrl();
431 $response[json_encode($user, JSON_THROW_ON_ERROR)] = $public_image;
441 $kindly = $this->
refinery->kindlyTo();
442 $s = $kindly->string();
443 $int = $kindly->int();
444 $get = $this->
http->wrapper()->query()->retrieve(...);
445 $get_or = fn($k, $t,
$d =
null) => $get($k, $this->
refinery->byTrying([$t, $this->refinery->always(
$d)]));
447 $ref_id = $get(
'ref_id', $int);
449 $username = $get(
'username', $s);
450 $actions = $get_or(
'actions', $kindly->dictOf($s), []);
452 $avatar = $DIC[
"user.avatar.factory"]->avatar(
'xsmall');
455 $public_image = $avatar->getUrl();
456 $item = $this->uiFactory->item()->standard($username)->withLeadImage($this->uiFactory->image()->standard(
458 'Profile image of ' . $username
462 $item = $item->withProperties([
463 $this->ilLng->txt(
'role') => $this->ilLng->txt(
'il_chat_moderator'),
469 $this->
sendResponse($this->uiRenderer->renderAsync($item),
'text/html');
478 $chat_settings =
new ilSetting(
'chatroom');
479 $osc_enabled = $chat_settings->get(
'chat_enabled') && $chat_settings->get(
'enable_osc');
481 'kick' => $this->ilLng->txt(
'chat_kick'),
482 'ban' => $this->ilLng->txt(
'chat_ban'),
486 $translations[
'chat'] = $this->ilLng->txt(
'start_private_chat');
490 foreach ($actions as $key => $bus_id) {
491 $label = $translations[$key] ??
false;
493 $buttons[] = $this->uiFactory->button()->shy($label,
'')->withAdditionalOnLoadCode(fn(
string $id):
string => (
494 'il.Chatroom.bus.send(' . json_encode(
497 ) .
', document.getElementById(' . json_encode($id, JSON_THROW_ON_ERROR) .
'));' 507 return new BuildChat($this->
ilCtrl, $this->ilLng, $this->gui, $room, $settings, $this->ilUser, $this->uiFactory, $this->uiRenderer);
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
getUserId()
Returns Ilias User ID.
panel(string $title, $body)
redirectIfNoPermission($permission)
Checks for requested permissions and redirects if the permission check failed.
static initLinkify(?ilGlobalTemplateInterface $a_tpl=null)
getRequestValue(string $key, Transformation $trafo, $default=null)
getLastMessages(int $number, ilChatroomUser $chatuser)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
renderSendMessageBox(ilTemplate $roomTpl)
isProfilePictureVisible()
static _lookupPref(int $a_usr_id, string $a_keyword)
static subStr(string $a_str, int $a_start, ?int $a_length=null)
getConnectedUsers(bool $only_data=true)
static setTokenMaxLifetimeInSeconds(int $token_max_lifetime_in_seconds)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
sendResponse(string $content, string $type)
Sends a response and exits the php process.
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.
buildChat(ilChatroom $room, ilChatroomServerSettings $settings)
static checkPermissionsOfUser(int $usr_id, $permissions, int $ref_id)
Checks user permissions in question for a given user id in relation to a given ref_id.
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)
sendJSONResponse($response)
Sends a json encoded response and exits the php process.
getChatNameSuggestions()
Returns an array of chat-name suggestions.
executeDefault(string $requestedMethod)
Chatroom and Chatuser get prepared before $this->showRoom method is called.
chatFunctions(bool $show_auto_messages, bool $is_moderator)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static byObjectId(int $object_id)
showNameSelection(ilChatroomUser $chat_user)
static _writePref(int $a_usr_id, string $a_keyword, string $a_value)
getUsername()
Returns username from Object or SESSION.
buildUserActions(int $user_id, array $actions)
readOnlyChatWindow(ilChatroom $room, array $messages)
renderRightUsersBlock(ilTemplate $roomTpl)
checkbox(Component $component)
toggleAutoMessageDisplayState()