mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
Adding away-command
This commit is contained in:
parent
f58b518963
commit
e7598d14f7
@ -312,6 +312,13 @@ consoleMock ?=
|
||||
if element[0]
|
||||
console.log '[be.bastelstu.WCF.Chat Moving User: "' + user.username + '"'
|
||||
element = element.detach()
|
||||
if user.awayStatus?
|
||||
element.addClass 'timsChatAway'
|
||||
element.attr 'title', user.awayStatus
|
||||
else
|
||||
element.removeClass 'timsChatAway'
|
||||
element.removeAttr 'title'
|
||||
element.data 'tooltip', ''
|
||||
$('#timsChatUserList').append element
|
||||
# Insert the user
|
||||
else
|
||||
@ -319,6 +326,10 @@ consoleMock ?=
|
||||
li = $ '<li></li>'
|
||||
li.attr 'id', id
|
||||
li.addClass 'timsChatUser'
|
||||
li.addClass 'jsTooltip'
|
||||
if user.awayStatus?
|
||||
li.addClass 'timsChatAway'
|
||||
li.attr 'title', user.awayStatus
|
||||
li.data 'username', user.username
|
||||
a = $ '<a href="javascript:;">'+user.username+'</a>'
|
||||
a.click $.proxy (event) ->
|
||||
|
@ -22,7 +22,7 @@ class ChatRoom extends \wcf\data\DatabaseObject implements \wcf\system\request\I
|
||||
* @see \wcf\data\DatabaseObject::$databaseTableIndexName
|
||||
*/
|
||||
protected static $databaseTableIndexName = 'roomID';
|
||||
|
||||
|
||||
/**
|
||||
* Caches rooms.
|
||||
*
|
||||
@ -43,21 +43,18 @@ public function __toString() {
|
||||
* @return integer
|
||||
*/
|
||||
public function countUsers() {
|
||||
$packageID = \wcf\util\ChatUtil::getPackageID();
|
||||
|
||||
$sql = "SELECT
|
||||
count(*) as count
|
||||
COUNT(*)
|
||||
FROM
|
||||
wcf".WCF_N."_user_storage
|
||||
WHERE
|
||||
field = 'roomID'
|
||||
AND packageID = ".intval($packageID)."
|
||||
AND fieldValue = ".intval($this->roomID);
|
||||
field = ?
|
||||
AND packageID = ?
|
||||
AND fieldValue = ?";
|
||||
$stmt = WCF::getDB()->prepareStatement($sql);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetchArray();
|
||||
$stmt->execute(array('roomID', \wcf\util\ChatUtil::getPackageID(), $this->roomID));
|
||||
|
||||
return $row['count'];
|
||||
return $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,32 +98,42 @@ public function getTitle() {
|
||||
*/
|
||||
public function getUsers() {
|
||||
$packageID = \wcf\util\ChatUtil::getPackageID();
|
||||
|
||||
|
||||
$sql = "SELECT
|
||||
userID
|
||||
FROM
|
||||
wcf".WCF_N."_user_storage
|
||||
WHERE
|
||||
field = 'roomID'
|
||||
AND packageID = ".intval($packageID)."
|
||||
AND fieldValue = ".intval($this->roomID);
|
||||
field = ?
|
||||
AND packageID = ?
|
||||
AND fieldValue = ?";
|
||||
$stmt = WCF::getDB()->prepareStatement($sql);
|
||||
$stmt->execute();
|
||||
$stmt->execute(array('roomID', $packageID, $this->roomID));
|
||||
$userIDs = array();
|
||||
while ($row = $stmt->fetchArray()) $userIDs[] = $row['userID'];
|
||||
|
||||
if (!count($userIDs)) return;
|
||||
|
||||
while ($userIDs[] = $stmt->fetchColumn());
|
||||
|
||||
if (!count($userIDs)) return array();
|
||||
|
||||
$sql = "SELECT
|
||||
*
|
||||
u.*,
|
||||
s.fieldValue AS awayStatus
|
||||
FROM
|
||||
wcf".WCF_N."_user
|
||||
wcf".WCF_N."_user u
|
||||
LEFT JOIN
|
||||
wcf".WCF_N."_user_storage s
|
||||
ON (
|
||||
u.userID = s.userID
|
||||
AND s.field = ?
|
||||
AND s.packageID = ?
|
||||
)
|
||||
WHERE
|
||||
userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').")
|
||||
u.userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').")
|
||||
ORDER BY
|
||||
username ASC";
|
||||
u.username ASC";
|
||||
$stmt = WCF::getDB()->prepareStatement($sql);
|
||||
array_unshift($userIDs, 'away', $packageID);
|
||||
$stmt->execute($userIDs);
|
||||
|
||||
return $stmt->fetchObjects('\wcf\data\user\User');
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ class ChatForm extends AbstractForm {
|
||||
public function readData() {
|
||||
$this->userData['color'] = \wcf\util\ChatUtil::readUserData('color');
|
||||
$this->userData['roomID'] = \wcf\util\ChatUtil::readUserData('roomID');
|
||||
$this->userData['away'] = \wcf\util\ChatUtil::readUserData('away');
|
||||
|
||||
$this->room = chat\room\ChatRoom::getCache()->search($this->userData['roomID']);
|
||||
if (!$this->room) throw new \wcf\system\exception\IllegalLinkException();
|
||||
@ -70,6 +71,7 @@ public function validate() {
|
||||
public function save() {
|
||||
parent::save();
|
||||
|
||||
\wcf\util\ChatUtil::writeUserData(array('away' => null));
|
||||
$commandHandler = new \wcf\system\chat\commands\CommandHandler($this->message);
|
||||
if ($commandHandler->isCommand()) {
|
||||
try {
|
||||
@ -101,6 +103,23 @@ public function save() {
|
||||
$receiver = null;
|
||||
}
|
||||
|
||||
// mark user as back
|
||||
if ($this->userData['away'] !== null) {
|
||||
$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_BACK,
|
||||
'message' => '',
|
||||
'color1' => $this->userData['color'][1],
|
||||
'color2' => $this->userData['color'][2]
|
||||
)
|
||||
));
|
||||
$messageAction->executeAction();
|
||||
}
|
||||
|
||||
$messageAction = new chat\message\ChatMessageAction(array(), 'create', array(
|
||||
'data' => array(
|
||||
'roomID' => $this->room->roomID,
|
||||
@ -124,7 +143,7 @@ public function save() {
|
||||
* @see \wcf\page\IPage::show()
|
||||
*/
|
||||
public function show() {
|
||||
header("HTTP/1.0 204 No Content");
|
||||
//header("HTTP/1.0 204 No Content");
|
||||
parent::show();
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,8 @@ public function show() {
|
||||
foreach ($this->users as $user) {
|
||||
$json['users'][] = array(
|
||||
'userID' => $user->userID,
|
||||
'username' => $user->username
|
||||
'username' => $user->username,
|
||||
'awayStatus' => $user->awayStatus
|
||||
);
|
||||
}
|
||||
|
||||
|
43
file/lib/system/chat/commands/commands/Away.class.php
Normal file
43
file/lib/system/chat/commands/commands/Away.class.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace wcf\system\chat\commands\commands;
|
||||
use \wcf\util\StringUtil;
|
||||
|
||||
/**
|
||||
* Marks the user as away.
|
||||
*
|
||||
* @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>
|
||||
* @package timwolla.wcf.chat
|
||||
* @subpackage system.chat.commands.commands
|
||||
*/
|
||||
class Away extends \wcf\system\chat\commands\AbstractCommand {
|
||||
public $enableSmilies = \wcf\system\chat\commands\ICommand::SMILEY_OFF;
|
||||
|
||||
public function __construct(\wcf\system\chat\commands\CommandHandler $commandHandler) {
|
||||
parent::__construct($commandHandler);
|
||||
|
||||
\wcf\util\ChatUtil::writeUserData(array('away' => $commandHandler->getParameters()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \wcf\system\chat\commands\ICommand::getType()
|
||||
*/
|
||||
public function getType() {
|
||||
return \wcf\data\chat\message\ChatMessage::TYPE_AWAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \wcf\system\chat\commands\ICommand::getMessage()
|
||||
*/
|
||||
public function getMessage() {
|
||||
return $this->commandHandler->getParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \wcf\system\chat\commands\ICommand::getReceiver()
|
||||
*/
|
||||
public function getReceiver() {
|
||||
return \wcf\system\WCF::getUser()->userID;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user