1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00
Tims-Chat/files/lib/data/user/UserAction.class.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

141 lines
3.8 KiB
PHP
Raw Normal View History

2018-08-16 22:30:59 +00:00
<?php
2022-03-04 17:10:24 +00:00
2018-08-16 22:30:59 +00:00
/*
2022-03-04 17:10:24 +00:00
* Copyright (c) 2010-2022 Tim Düsterhus.
2018-08-16 22:30:59 +00:00
*
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
2022-09-17 14:23:02 +00:00
* Change Date: 2026-09-17
2018-08-16 22:30:59 +00:00
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
* or later of the General Public License.
*/
namespace chat\data\user;
2022-03-04 17:10:24 +00:00
use chat\data\room\Room;
use chat\data\room\RoomAction;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\cache\runtime\UserRuntimeCache;
use wcf\system\event\EventHandler;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\UserInputException;
2018-08-16 22:30:59 +00:00
/**
* Executes chat user-related actions.
*/
2022-03-04 17:10:24 +00:00
class UserAction extends AbstractDatabaseObjectAction
{
/**
* @inheritDoc
*/
protected $className = User::class;
/**
* Validates parameters and permissions.
*/
public function validateGetUsersByID()
{
if (!Room::canSeeAny()) {
throw new PermissionDeniedException();
}
$this->readIntegerArray('userIDs');
}
/**
* Returns information about the users identified by the given userIDs.
*/
public function getUsersByID()
{
$userList = UserProfileRuntimeCache::getInstance()->getObjects($this->parameters['userIDs']);
return \array_map(function ($user) {
if (!$user) {
return null;
}
$payload = [
'image16' => $user->getAvatar()->getImageTag(16),
'image24' => $user->getAvatar()->getImageTag(24),
'image32' => $user->getAvatar()->getImageTag(32),
'image48' => $user->getAvatar()->getImageTag(48),
'imageUrl' => $user->getAvatar()->getURL(),
'link' => $user->getLink(),
'anchor' => $user->getAnchorTag(),
'userID' => $user->userID,
'username' => $user->username,
'userTitle' => $user->getUserTitle(),
'userRankClass' => $user->getRank() ? $user->getRank()->cssClassName : null,
'formattedUsername' => $user->getFormattedUsername(),
'away' => $user->chatAway,
'color1' => $user->chatColor1,
'color2' => $user->chatColor2,
];
EventHandler::getInstance()->fireAction($this, 'getUsersByID', $payload);
return $payload;
}, $userList);
}
/**
* Clears dead clients.
*/
public function clearDeadSessions()
{
$sessions = User::getDeadSessions();
if ($sessions === []) {
2022-03-04 17:10:24 +00:00
return;
}
$userIDs = \array_map(static function ($item) {
return $item['userID'];
}, $sessions);
$users = UserRuntimeCache::getInstance()->getObjects($userIDs);
foreach ($sessions as $session) {
$parameters = [
'user' => $users[$session['userID']],
'roomID' => $session['roomID'],
'sessionID' => $session['sessionID'],
];
try {
(new RoomAction(
[ ],
'leave',
$parameters
))->executeAction();
} catch (UserInputException $e) {
// Probably some other request has been faster to remove this session, ignore
}
}
}
/**
* @inheritDoc
*/
public function create()
{
throw new \BadMethodCallException();
}
/**
* @inheritDoc
*/
public function update()
{
throw new \BadMethodCallException();
}
/**
* @inheritDoc
*/
public function delete()
{
throw new \BadMethodCallException();
}
2018-08-16 22:30:59 +00:00
}