mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-10-31 14:10:08 +00:00
Handle whisper formatting on the client side.
Add additionalData to messages
This commit is contained in:
parent
f49384991a
commit
63321dd0bd
@ -43,6 +43,17 @@ class Message extends \chat\data\CHATDatabaseObject {
|
||||
*/
|
||||
protected static $users = array();
|
||||
|
||||
/**
|
||||
* @see \wcf\data\DatabaseObject::handleData()
|
||||
*/
|
||||
protected function handleData($data) {
|
||||
parent::handleData($data);
|
||||
|
||||
if ($this->data['additionalData'] !== null) {
|
||||
$this->data['additionalData'] = unserialize($this->data['additionalData']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \chat\data\message\Message::getFormattedMessage()
|
||||
*/
|
||||
@ -65,8 +76,10 @@ public function getFormattedMessage($type = 'text/html') {
|
||||
case self::TYPE_JOIN:
|
||||
case self::TYPE_LEAVE:
|
||||
case self::TYPE_BACK:
|
||||
$message = WCF::getLanguage()->getDynamicVariable('chat.message.'.$this->type, $this->data['additionalData'] ?: array());
|
||||
break;
|
||||
case self::TYPE_AWAY:
|
||||
$message = WCF::getLanguage()->getDynamicVariable('chat.message.'.$this->type, unserialize($message) ?: array());
|
||||
$message = WCF::getLanguage()->getDynamicVariable('chat.message.'.$this->type, array('message' => $message));
|
||||
break;
|
||||
case self::TYPE_MODERATE:
|
||||
$message = unserialize($message);
|
||||
@ -75,8 +88,6 @@ public function getFormattedMessage($type = 'text/html') {
|
||||
$message = $messageParser->parse($message, false, false, true, false);
|
||||
break;
|
||||
case self::TYPE_WHISPER:
|
||||
$message = unserialize($message);
|
||||
$message = $message['message'];
|
||||
case self::TYPE_NORMAL:
|
||||
case self::TYPE_ME:
|
||||
default:
|
||||
@ -103,11 +114,6 @@ public function getUsername($colored = false) {
|
||||
$username = \chat\util\ChatUtil::gradient($username, $this->color1, $this->color2);
|
||||
}
|
||||
|
||||
if ($this->type == self::TYPE_WHISPER) {
|
||||
$message = unserialize($this->message);
|
||||
$username .= ' -> '.$message['username'];
|
||||
}
|
||||
|
||||
return $username;
|
||||
}
|
||||
|
||||
@ -119,9 +125,9 @@ public function getUsername($colored = false) {
|
||||
*/
|
||||
public function jsonify($raw = false) {
|
||||
switch ($this->type) {
|
||||
case self::TYPE_WHISPER:
|
||||
case self::TYPE_NORMAL:
|
||||
case self::TYPE_INFORMATION:
|
||||
case self::TYPE_WHISPER:
|
||||
$separator = ':';
|
||||
break;
|
||||
default:
|
||||
@ -141,7 +147,8 @@ public function jsonify($raw = false) {
|
||||
'receiver' => (int) $this->receiver,
|
||||
'type' => (int) $this->type,
|
||||
'roomID' => (int) $this->roomID,
|
||||
'messageID' => (int) $this->messageID
|
||||
'messageID' => (int) $this->messageID,
|
||||
'additionalData' => $this->additionalData
|
||||
);
|
||||
|
||||
if ($raw) return $array;
|
||||
|
@ -117,6 +117,7 @@ public function validateSend() {
|
||||
$this->parameters['type'] = $command->getType();
|
||||
$this->parameters['text'] = $command->getMessage();
|
||||
$this->parameters['receiver'] = $command->getReceiver();
|
||||
$this->parameters['additionalData'] = $command->getAdditionalData();
|
||||
}
|
||||
catch (\chat\system\command\NotFoundException $e) {
|
||||
throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('chat.error.notFound', array('exception' => $e)));
|
||||
@ -128,6 +129,7 @@ public function validateSend() {
|
||||
else {
|
||||
$this->parameters['type'] = Message::TYPE_NORMAL;
|
||||
$this->parameters['receiver'] = null;
|
||||
$this->parameters['additionalData'] = null;
|
||||
|
||||
$this->parameters['text'] = \wcf\system\bbcode\PreParser::getInstance()->parse($this->parameters['text'], explode(',', WCF::getSession()->getPermission('user.chat.allowedBBCodes')));
|
||||
}
|
||||
@ -149,7 +151,8 @@ public function send() {
|
||||
'enableSmilies' => $this->parameters['enableSmilies'] ? 1 : 0,
|
||||
'enableHTML' => $this->parameters['enableHTML'] ? 1 : 0,
|
||||
'color1' => $this->parameters['userData']['color1'],
|
||||
'color2' => $this->parameters['userData']['color2']
|
||||
'color2' => $this->parameters['userData']['color2'],
|
||||
'additionalData' => serialize($this->parameters['additionalData'])
|
||||
)
|
||||
));
|
||||
$this->objectAction->executeAction();
|
||||
|
@ -192,9 +192,10 @@ public function join() {
|
||||
'username' => $this->parameters['user']->username,
|
||||
'time' => TIME_NOW,
|
||||
'type' => message\Message::TYPE_LEAVE,
|
||||
'message' => serialize(array('room' => $room)),
|
||||
'message' => '',
|
||||
'color1' => $this->parameters['user']->chatColor1,
|
||||
'color2' => $this->parameters['user']->chatColor2
|
||||
'color2' => $this->parameters['user']->chatColor2,
|
||||
'additionalData' => serialize(array('room' => $room))
|
||||
)
|
||||
));
|
||||
$messageAction->executeAction();
|
||||
@ -211,9 +212,10 @@ public function join() {
|
||||
'username' => $this->parameters['user']->username,
|
||||
'time' => TIME_NOW,
|
||||
'type' => message\Message::TYPE_JOIN,
|
||||
'message' => serialize(array('ipAddress' => $ipAddress)),
|
||||
'message' => '',
|
||||
'color1' => $this->parameters['user']->chatColor1,
|
||||
'color2' => $this->parameters['user']->chatColor2
|
||||
'color2' => $this->parameters['user']->chatColor2,
|
||||
'additionalData' => serialize(array('ipAddress' => $ipAddress))
|
||||
)
|
||||
));
|
||||
$messageAction->executeAction();
|
||||
@ -286,7 +288,7 @@ public function leave() {
|
||||
'username' => $this->parameters['user']->username,
|
||||
'time' => TIME_NOW,
|
||||
'type' => message\Message::TYPE_LEAVE,
|
||||
'message' => serialize(array('room' => null)),
|
||||
'message' => '',
|
||||
'color1' => $this->parameters['user']->chatColor1,
|
||||
'color2' => $this->parameters['user']->chatColor2
|
||||
)
|
||||
|
@ -59,4 +59,11 @@ public function didInit() {
|
||||
public function getReceiver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* No additionaldata by default.
|
||||
*/
|
||||
public function getAdditionalData() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,11 @@ public function getType();
|
||||
*/
|
||||
public function getMessage();
|
||||
|
||||
/**
|
||||
* Returns additionalData to be saved within database
|
||||
*/
|
||||
public function getAdditionalData();
|
||||
|
||||
/**
|
||||
* Returns the receiver for this command.
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace chat\system\command\commands;
|
||||
use \wcf\system\WCF;
|
||||
use \wcf\util\StringUtil;
|
||||
|
||||
/**
|
||||
@ -33,15 +34,13 @@ public function getType() {
|
||||
* @see \chat\system\command\ICommand::getMessage()
|
||||
*/
|
||||
public function getMessage() {
|
||||
return serialize(array(
|
||||
'message' => \wcf\system\bbcode\PreParser::getInstance()->parse($this->commandHandler->getParameters(), explode(',', \wcf\system\WCF::getSession()->getPermission('user.chat.allowedBBCodes')))
|
||||
));
|
||||
return \wcf\system\bbcode\PreParser::getInstance()->parse($this->commandHandler->getParameters(), explode(',', WCF::getSession()->getPermission('user.chat.allowedBBCodes')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \chat\system\command\ICommand::getReceiver()
|
||||
*/
|
||||
public function getReceiver() {
|
||||
return \wcf\system\WCF::getUser()->userID;
|
||||
return WCF::getUser()->userID;
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
class TemproomCommand extends \chat\system\command\AbstractRestrictedCommand {
|
||||
public $roomName = '';
|
||||
public $roomID = 0;
|
||||
|
||||
public function __construct(\chat\system\command\CommandHandler $commandHandler) {
|
||||
parent::__construct($commandHandler);
|
||||
@ -28,8 +29,8 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
||||
$this->objectAction->executeAction();
|
||||
$returnValues = $this->objectAction->getReturnValues();
|
||||
$chatRoomEditor = new \chat\data\room\RoomEditor($returnValues['returnValues']);
|
||||
$roomID = $returnValues['returnValues']->roomID;
|
||||
$this->roomName = WCF::getLanguage()->getDynamicVariable('chat.room.titleTemp', array('roomID' => $roomID));
|
||||
$this->roomID = $returnValues['returnValues']->roomID;
|
||||
$this->roomName = WCF::getLanguage()->getDynamicVariable('chat.room.titleTemp', array('roomID' => $this->roomID));
|
||||
|
||||
// set accurate title
|
||||
$chatRoomEditor->update(array(
|
||||
@ -50,7 +51,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
|
||||
)
|
||||
);
|
||||
|
||||
$acl->save($roomID, $acl->getObjectTypeID('be.bastelstu.chat.room'));
|
||||
$acl->save($this->roomID, $acl->getObjectTypeID('be.bastelstu.chat.room'));
|
||||
\chat\system\permission\PermissionHandler::clearCache();
|
||||
$this->didInit();
|
||||
}
|
||||
@ -84,4 +85,14 @@ public function getMessage() {
|
||||
public function getReceiver() {
|
||||
return \wcf\system\WCF::getUser()->userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \chat\system\command\ICommand::getAdditionalData()
|
||||
*/
|
||||
public function getAdditionalData() {
|
||||
return array(
|
||||
'roomID' => (int) $this->roomID,
|
||||
'roomName' => $this->roomName
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public function getType() {
|
||||
public function getMessage() {
|
||||
$this->message = \wcf\system\bbcode\PreParser::getInstance()->parse($this->message, explode(',', \wcf\system\WCF::getSession()->getPermission('user.chat.allowedBBCodes')));
|
||||
|
||||
return serialize(array('message' => $this->message, 'username' => $this->user->username));
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,4 +57,13 @@ public function getMessage() {
|
||||
public function getReceiver() {
|
||||
return $this->user->userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \chat\system\command\ICommand::getAdditionalData()
|
||||
*/
|
||||
public function getAdditionalData() {
|
||||
return array(
|
||||
'receiverUsername' => $this->user->username
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ CREATE TABLE chat1_message (
|
||||
enableHTML TINYINT(1) NOT NULL DEFAULT 0,
|
||||
color1 INT(10) NOT NULL DEFAULT 0,
|
||||
color2 INT(10) NOT NULL DEFAULT 0,
|
||||
additionalData TEXT DEFAULT NULL,
|
||||
|
||||
KEY (roomID),
|
||||
KEY (sender),
|
||||
|
@ -110,7 +110,7 @@
|
||||
<!-- 1 = TYPE_JOIN -->
|
||||
<item name="chat.message.1"><![CDATA[hat den Chat betreten.{if $__wcf->session->getPermission('admin.user.canViewIpAddress') && $ipAddress} ({$ipAddress}){/if}]]></item>
|
||||
<!-- 2 = TYPE_LEAVE -->
|
||||
<item name="chat.message.2"><![CDATA[{if $room == null}hat den Chat verlassen.{else}ist in den Raum „{$room}“ gegangen.{/if}]]></item>
|
||||
<item name="chat.message.2"><![CDATA[{if !$room|isset || $room === null}hat den Chat verlassen.{else}ist in den Raum „{$room}“ gegangen.{/if}]]></item>
|
||||
<!-- 3 = TYPE_AWAY -->
|
||||
<item name="chat.message.3"><![CDATA[ist jetzt abwesend{if $message}: {$message}{else}.{/if}]]></item>
|
||||
<!-- 4 = TYPE_BACK -->
|
||||
|
@ -1 +1 @@
|
||||
{literal}<time>{@$formattedTime}</time> <span class="usernameContainer"><span class="username">{@$formattedUsername}</span><span class="separator">{$separator}</span></span> <span class="text">{@$formattedMessage}</span> <span class="markContainer"><input type="checkbox" value="{@$messageID}" /></span>{/literal}
|
||||
{literal}<time>{@$formattedTime}</time> <span class="usernameContainer"><span class="username">{if $type != 7}{@$formattedUsername}{else}{if $receiver == WCF.User.userID}{@$formattedUsername} {/if}->{if $receiver != WCF.User.userID} {$additionalData.receiverUsername}{/if}{/if}</span><span class="separator">{$separator}</span></span> <span class="text">{@$formattedMessage}</span> <span class="markContainer"><input type="checkbox" value="{@$messageID}" /></span>{/literal}
|
Loading…
Reference in New Issue
Block a user