1
0
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:
Tim Düsterhus 2012-03-22 18:45:36 +01:00
parent f58b518963
commit e7598d14f7
5 changed files with 106 additions and 25 deletions

View File

@ -312,6 +312,13 @@ consoleMock ?=
if element[0] if element[0]
console.log '[be.bastelstu.WCF.Chat Moving User: "' + user.username + '"' console.log '[be.bastelstu.WCF.Chat Moving User: "' + user.username + '"'
element = element.detach() 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 $('#timsChatUserList').append element
# Insert the user # Insert the user
else else
@ -319,6 +326,10 @@ consoleMock ?=
li = $ '<li></li>' li = $ '<li></li>'
li.attr 'id', id li.attr 'id', id
li.addClass 'timsChatUser' li.addClass 'timsChatUser'
li.addClass 'jsTooltip'
if user.awayStatus?
li.addClass 'timsChatAway'
li.attr 'title', user.awayStatus
li.data 'username', user.username li.data 'username', user.username
a = $ '<a href="javascript:;">'+user.username+'</a>' a = $ '<a href="javascript:;">'+user.username+'</a>'
a.click $.proxy (event) -> a.click $.proxy (event) ->

View File

@ -43,21 +43,18 @@ public function __toString() {
* @return integer * @return integer
*/ */
public function countUsers() { public function countUsers() {
$packageID = \wcf\util\ChatUtil::getPackageID();
$sql = "SELECT $sql = "SELECT
count(*) as count COUNT(*)
FROM FROM
wcf".WCF_N."_user_storage wcf".WCF_N."_user_storage
WHERE WHERE
field = 'roomID' field = ?
AND packageID = ".intval($packageID)." AND packageID = ?
AND fieldValue = ".intval($this->roomID); AND fieldValue = ?";
$stmt = WCF::getDB()->prepareStatement($sql); $stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(); $stmt->execute(array('roomID', \wcf\util\ChatUtil::getPackageID(), $this->roomID));
$row = $stmt->fetchArray();
return $row['count']; return $stmt->fetchColumn();
} }
/** /**
@ -107,26 +104,36 @@ public function getUsers() {
FROM FROM
wcf".WCF_N."_user_storage wcf".WCF_N."_user_storage
WHERE WHERE
field = 'roomID' field = ?
AND packageID = ".intval($packageID)." AND packageID = ?
AND fieldValue = ".intval($this->roomID); AND fieldValue = ?";
$stmt = WCF::getDB()->prepareStatement($sql); $stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(); $stmt->execute(array('roomID', $packageID, $this->roomID));
$userIDs = array(); $userIDs = array();
while ($row = $stmt->fetchArray()) $userIDs[] = $row['userID']; while ($userIDs[] = $stmt->fetchColumn());
if (!count($userIDs)) return; if (!count($userIDs)) return array();
$sql = "SELECT $sql = "SELECT
* u.*,
s.fieldValue AS awayStatus
FROM 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 WHERE
userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').") u.userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').")
ORDER BY ORDER BY
username ASC"; u.username ASC";
$stmt = WCF::getDB()->prepareStatement($sql); $stmt = WCF::getDB()->prepareStatement($sql);
array_unshift($userIDs, 'away', $packageID);
$stmt->execute($userIDs); $stmt->execute($userIDs);
return $stmt->fetchObjects('\wcf\data\user\User'); return $stmt->fetchObjects('\wcf\data\user\User');
} }

View File

@ -31,6 +31,7 @@ class ChatForm extends AbstractForm {
public function readData() { public function readData() {
$this->userData['color'] = \wcf\util\ChatUtil::readUserData('color'); $this->userData['color'] = \wcf\util\ChatUtil::readUserData('color');
$this->userData['roomID'] = \wcf\util\ChatUtil::readUserData('roomID'); $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']); $this->room = chat\room\ChatRoom::getCache()->search($this->userData['roomID']);
if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); if (!$this->room) throw new \wcf\system\exception\IllegalLinkException();
@ -70,6 +71,7 @@ public function validate() {
public function save() { public function save() {
parent::save(); parent::save();
\wcf\util\ChatUtil::writeUserData(array('away' => null));
$commandHandler = new \wcf\system\chat\commands\CommandHandler($this->message); $commandHandler = new \wcf\system\chat\commands\CommandHandler($this->message);
if ($commandHandler->isCommand()) { if ($commandHandler->isCommand()) {
try { try {
@ -101,6 +103,23 @@ public function save() {
$receiver = null; $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( $messageAction = new chat\message\ChatMessageAction(array(), 'create', array(
'data' => array( 'data' => array(
'roomID' => $this->room->roomID, 'roomID' => $this->room->roomID,
@ -124,7 +143,7 @@ public function save() {
* @see \wcf\page\IPage::show() * @see \wcf\page\IPage::show()
*/ */
public function show() { public function show() {
header("HTTP/1.0 204 No Content"); //header("HTTP/1.0 204 No Content");
parent::show(); parent::show();
} }
} }

View File

@ -79,7 +79,8 @@ public function show() {
foreach ($this->users as $user) { foreach ($this->users as $user) {
$json['users'][] = array( $json['users'][] = array(
'userID' => $user->userID, 'userID' => $user->userID,
'username' => $user->username 'username' => $user->username,
'awayStatus' => $user->awayStatus
); );
} }

View 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;
}
}