Joywork/ajax/chat/addUsersToChannel.php

28 lines
795 B
PHP
Raw Normal View History

2026-05-22 20:21:54 +02:00
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
if ($_SESSION['id'] && $_POST['channelId'] && $_POST['users']) {
$post = clearInputData($_POST);
$ids = explode(',', $post['users']);
foreach ($ids as $id) {
$user = new User();
$user->get($id);
$userSettings = RocketChat::getUserChatSettings($id);
if (!$userSettings['chat_login']) {
$result = RocketChat::createChatUser($user);
}
if (!RocketChat::checkUserInChannel($user, $post['channelId'])) {
//логиним, чтобы получить ИД в чате
RocketChat::loginUser($user->id);
//добавляем в канал
RocketChat::addUserToChannel($user, $post['channelId']);
}
}
}