mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-10-31 14:10:08 +00:00
Adding ChatMessageList
Show the newest 5 messages on join. Adding method to get formatted nickname
This commit is contained in:
parent
d20fd79ece
commit
f159d952ca
@ -42,4 +42,22 @@ class ChatMessage extends \wcf\data\DatabaseObject {
|
||||
public function __toString() {
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the formatted username
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormattedUsername() {
|
||||
$string = str_split($this->username);
|
||||
$r = (int) (($this->color1 >> 16 & 255) - ($this->color2 >> 16 & 255)) / (count($string) - 1);
|
||||
$g = (int) (($this->color1 >> 8 & 255) - ($this->color2 >> 8 & 255)) / (count($string) - 1);
|
||||
$b = (int) (($this->color1 & 255) - ($this->color2 & 255)) / (count($string) - 1);
|
||||
$result = '';
|
||||
for ($i = 0, $max = count($string); $i < $max; $i++) {
|
||||
$result .= '<span style="color:rgb('.(($this->color1 >> 16 & 255) - $i * $r).', '.(($this->color1 >> 8 & 255) - $i * $g).', '.(($this->color1 & 255) - $i * $b).')">'.$string[$i].'</span>';
|
||||
}
|
||||
|
||||
return '<strong>'.$result.'</strong>';
|
||||
}
|
||||
}
|
||||
|
27
file/lib/data/chat/message/ChatMessageList.class.php
Normal file
27
file/lib/data/chat/message/ChatMessageList.class.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace wcf\data\chat\message;
|
||||
|
||||
/**
|
||||
* Represents a list of chat messages.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
* @copyright 2010-2011 Tim Düsterhus
|
||||
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
||||
* @package timwolla.wcf.chat
|
||||
* @subpackage data.chat.room
|
||||
*/
|
||||
class ChatMessageList extends \wcf\data\DatabaseObjectList {
|
||||
/**
|
||||
* @see wcf\data\DatabaseObjectList::$className
|
||||
*/
|
||||
public $className = 'wcf\data\chat\message\ChatMessage';
|
||||
|
||||
public static function getNewestMessages(\wcf\data\chat\room\ChatRoom $room, $number) {
|
||||
$messageList = new static();
|
||||
$messageList->sqlOrderBy = "chat_message.messageID DESC";
|
||||
$messageList->sqlLimit = $number;
|
||||
$messageList->getConditionBuilder()->add('chat_message.roomID = ?', array($room->roomID));
|
||||
$messageList->readObjects();
|
||||
return array_reverse($messageList->getObjects());
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ class ChatPage extends AbstractPage {
|
||||
//public $neededModules = array('CHAT_ACTIVE');
|
||||
//public $neededPermissions = array('user.chat.canEnter');
|
||||
public $joinMessage = null;
|
||||
public $newestMessages = array();
|
||||
public $room = null;
|
||||
public $roomID = 0;
|
||||
public $rooms = array();
|
||||
@ -35,6 +36,7 @@ public function assignVariables() {
|
||||
WCF::getTPL()->assign(array(
|
||||
'chatVersion' => $this->chatVersion,
|
||||
'joinMessage' => $this->joinMessage,
|
||||
'newestMessages' => $this->newestMessages,
|
||||
'room' => $this->room,
|
||||
'roomID' => $this->roomID,
|
||||
'rooms' => $this->rooms,
|
||||
@ -80,6 +82,8 @@ public function readData() {
|
||||
|
||||
$this->readDefaultSmileys();
|
||||
$this->readChatVersion();
|
||||
|
||||
$this->newestMessages = chat\message\ChatMessageList::getNewestMessages($this->room, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,7 +203,13 @@
|
||||
{$room->topic|language}
|
||||
</div>
|
||||
<div class="chatMessage border content">
|
||||
[HH:MM:SS] <User 1> Test
|
||||
<ul>
|
||||
{foreach from=$newestMessages item='message'}
|
||||
<li>
|
||||
{@$message->getFormattedUsername()}
|
||||
</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
<form style="margin-top: 10px;" id="chatForm" action="index.php?form=Chat" method="post">
|
||||
<div class="table">
|
||||
|
Loading…
Reference in New Issue
Block a user