From f159d952ca782e7e633953f0f3db5a6bfdde5454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 4 Dec 2011 22:46:50 +0100 Subject: [PATCH] Adding ChatMessageList Show the newest 5 messages on join. Adding method to get formatted nickname --- .../data/chat/message/ChatMessage.class.php | 18 +++++++++++++ .../chat/message/ChatMessageList.class.php | 27 +++++++++++++++++++ file/lib/page/ChatPage.class.php | 4 +++ template/chat.tpl | 8 +++++- 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 file/lib/data/chat/message/ChatMessageList.class.php diff --git a/file/lib/data/chat/message/ChatMessage.class.php b/file/lib/data/chat/message/ChatMessage.class.php index b312815..b95bc10 100644 --- a/file/lib/data/chat/message/ChatMessage.class.php +++ b/file/lib/data/chat/message/ChatMessage.class.php @@ -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 .= ''.$string[$i].''; + } + + return ''.$result.''; + } } diff --git a/file/lib/data/chat/message/ChatMessageList.class.php b/file/lib/data/chat/message/ChatMessageList.class.php new file mode 100644 index 0000000..43891d4 --- /dev/null +++ b/file/lib/data/chat/message/ChatMessageList.class.php @@ -0,0 +1,27 @@ + + * @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()); + } +} diff --git a/file/lib/page/ChatPage.class.php b/file/lib/page/ChatPage.class.php index a1b4dcf..1f49f16 100644 --- a/file/lib/page/ChatPage.class.php +++ b/file/lib/page/ChatPage.class.php @@ -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); } /** diff --git a/template/chat.tpl b/template/chat.tpl index 34e5ade..1350fda 100644 --- a/template/chat.tpl +++ b/template/chat.tpl @@ -203,7 +203,13 @@ {$room->topic|language}
- [HH:MM:SS] <User 1> Test +