1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Allow fetching avatars for chat messages

This commit is contained in:
Tim Düsterhus 2013-05-25 00:50:50 +02:00
parent 73a152bcfa
commit 9e30cb66e7
4 changed files with 96 additions and 3 deletions

View File

@ -44,7 +44,7 @@ class Message extends \chat\data\CHATDatabaseObject {
protected static $users = array();
/**
* @see \chat\data\\message\Message::getFormattedMessage()
* @see \chat\data\message\Message::getFormattedMessage()
*/
public function __toString() {
return $this->getFormattedMessage();

View File

@ -0,0 +1,54 @@
<?php
namespace chat\data\message;
/**
* Represents a viewable chat message.
*
* @author Tim Düsterhus
* @copyright 2010-2013 Tim Düsterhus
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @package be.bastelstu.chat
* @subpackage data.message
*/
class ViewableMessage extends \wcf\data\DatabaseObjectDecorator {
/**
* @see \wcf\data\DatabaseObjectDecorator::$baseClass
*/
protected static $baseClass = 'chat\data\message\Message';
/**
* user profile object
* @var \wcf\data\user\UserProfile
*/
protected $userProfile = null;
/**
* Returns the profile object of the user who created the post.
*
* @return wcf\data\user\UserProfile
*/
public function getUserProfile() {
if ($this->userProfile === null) {
$this->userProfile = new \wcf\data\user\UserProfile(new \wcf\data\user\User(null, $this->getDecoratedObject()->data));
}
return $this->userProfile;
}
/**
* @see \chat\data\message\Message::jsonify()
*/
public function jsonify($raw = false) {
$array = parent::jsonify(true);
$array['avatar'] = array(
16 => $this->getUserProfile()->getAvatar()->getImageTag(16),
24 => $this->getUserProfile()->getAvatar()->getImageTag(24),
32 => $this->getUserProfile()->getAvatar()->getImageTag(32),
48 => $this->getUserProfile()->getAvatar()->getImageTag(48)
);
if ($raw) return $array;
return \wcf\util\JSON::encode($array);
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace chat\data\message;
/**
* Represents a list of viewable chat messages.
*
* @author Tim Düsterhus
* @copyright 2010-2013 Tim Düsterhus
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @package be.bastelstu.chat
* @subpackage chat.room
*/
class ViewableMessageList extends MessageList {
/**
* @see \wcf\data\DatabaseObjectList::$decoratorClassName
*/
public $decoratorClassName = 'chat\data\message\ViewableMessage';
/**
* @see \wcf\data\DatabaseObjectList::__construct()
*/
public function __construct() {
parent::__construct();
$this->sqlSelects .= "user_avatar.*, user_option_value.*, user_table.*";
$this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = message.sender)";
$this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_avatar user_avatar ON (user_avatar.avatarID = user_table.avatarID)";
$this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_option_value user_option_value ON (user_option_value.userID = user_table.userID)";
if (MODULE_USER_RANK) {
$this->sqlSelects .= ",user_rank.*";
$this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_rank user_rank ON (user_rank.rankID = user_table.rankID)";
}
}
}

View File

@ -73,7 +73,7 @@ public function readData() {
* Fetches the new messages
*/
public function readMessages() {
$this->messages = data\message\MessageList::getMessagesSince($this->room, WCF::getUser()->chatLastSeen);
$this->messages = data\message\ViewableMessageList::getMessagesSince($this->room, WCF::getUser()->chatLastSeen);
// update last seen message
$sql = "SELECT
@ -142,7 +142,11 @@ public function show() {
$items = array();
if (ENABLE_DEBUG_MODE) {
foreach ($b->getItems() as $item) {
$items[] = array('text' => $item['text'], 'use' => $item['use']);
$items[] = array(
'text' => $item['text'],
'use' => $item['use'],
'trace' => $item['trace']
);
}
}