2012-02-18 14:48:58 +00:00
|
|
|
<?php
|
|
|
|
namespace wcf\action;
|
|
|
|
use \wcf\data\chat;
|
|
|
|
use \wcf\system\WCF;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes the user leave Tims Chat.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
|
|
|
* @copyright 2010-2012 Tim Düsterhus
|
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
2012-03-12 16:18:15 +00:00
|
|
|
* @package be.bastelstu.wcf.chat
|
2012-02-18 14:48:58 +00:00
|
|
|
* @subpackage action
|
|
|
|
*/
|
|
|
|
class ChatLeaveAction extends AbstractAction {
|
2012-02-26 16:55:44 +00:00
|
|
|
/**
|
|
|
|
* @see \wcf\action\AbstractAction::$neededModules
|
|
|
|
*/
|
2012-02-18 14:48:58 +00:00
|
|
|
public $neededModules = array('CHAT_ACTIVE');
|
2012-06-04 19:34:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\AbstractPage::$neededPermissions
|
|
|
|
*/
|
2012-03-23 16:45:26 +00:00
|
|
|
public $neededPermissions = array('user.chat.canEnter');
|
2012-06-04 19:34:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current room.
|
|
|
|
*
|
|
|
|
* @var \wcf\data\chat\room\ChatRoom
|
|
|
|
*/
|
2012-02-18 14:48:58 +00:00
|
|
|
public $room = null;
|
2012-06-04 19:34:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Values read from the UserStorage of the current user.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2012-02-18 14:48:58 +00:00
|
|
|
public $userData = array();
|
|
|
|
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\action\IAction::execute()
|
2012-02-18 14:48:58 +00:00
|
|
|
*/
|
|
|
|
public function execute() {
|
|
|
|
parent::execute();
|
|
|
|
|
|
|
|
if (!WCF::getUser()->userID) {
|
|
|
|
throw new IllegalLinkException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->userData['roomID'] = \wcf\util\ChatUtil::readUserData('roomID');
|
|
|
|
|
|
|
|
$this->room = chat\room\ChatRoom::getCache()->search($this->userData['roomID']);
|
|
|
|
if (!$this->room) throw new \wcf\system\exception\IllegalLinkException();
|
|
|
|
if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
|
|
|
|
|
|
|
|
if (CHAT_DISPLAY_JOIN_LEAVE) {
|
|
|
|
$this->userData['color'] = \wcf\util\ChatUtil::readUserData('color');
|
|
|
|
|
2012-06-04 19:34:07 +00:00
|
|
|
// leave message
|
2012-02-18 14:48:58 +00:00
|
|
|
$messageAction = new chat\message\ChatMessageAction(array(), 'create', array(
|
|
|
|
'data' => array(
|
|
|
|
'roomID' => $this->room->roomID,
|
|
|
|
'sender' => WCF::getUser()->userID,
|
|
|
|
'username' => WCF::getUser()->username,
|
|
|
|
'time' => TIME_NOW,
|
|
|
|
'type' => chat\message\ChatMessage::TYPE_LEAVE,
|
|
|
|
'message' => '',
|
|
|
|
'color1' => $this->userData['color'][1],
|
|
|
|
'color2' => $this->userData['color'][2]
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$messageAction->executeAction();
|
|
|
|
}
|
|
|
|
|
2012-06-04 19:34:07 +00:00
|
|
|
// set current room to null
|
2012-02-18 14:48:58 +00:00
|
|
|
\wcf\util\ChatUtil::writeUserData(array('roomID' => null));
|
|
|
|
|
|
|
|
$this->executed();
|
2012-03-03 22:18:52 +00:00
|
|
|
header("HTTP/1.0 204 No Content");
|
2012-02-18 14:48:58 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|