From dce1f64d94895d259135db249f6a2a259e12a205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 21 Apr 2013 20:21:51 +0200 Subject: [PATCH] Make avatar available in user list --- file/js/be.bastelstu.Chat.litcoffee | 14 +++++-------- file/lib/data/room/Room.class.php | 28 ++++++------------------- file/lib/page/NewMessagesPage.class.php | 11 +++++++++- template/chat.tpl | 4 +++- template/userListUser.tpl | 1 + 5 files changed, 25 insertions(+), 33 deletions(-) create mode 100644 template/userListUser.tpl diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index c764ec7..3582a3f 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -49,6 +49,7 @@ Instances of `WCF.Template` titleTemplate: null messageTemplate: null + userTemplate: null Attributes needed for notificationss @@ -86,10 +87,10 @@ Every `WCF.PeriodicalExecuter` used by the chat to allow access for 3rd party de Methods ------- -**init(@config, @titleTemplate, @messageTemplate)** +**init(@config, @titleTemplate, @messageTemplate, @userTemplate)** Constructor, binds needed events and initializes `@events` and `PeriodicalExecuter`s. - init: (@config, @titleTemplate, @messageTemplate) -> + init: (@config, @titleTemplate, @messageTemplate, @userTemplate) -> console.log 'Initializing' Bind events and initialize our own event system. @@ -504,13 +505,8 @@ Build HTML of new user and append it. li.attr 'title', user.awayStatus li.data 'username', user.username - a = $ '' + WCF.String.escapeHTML(user.username) + '' - a.addClass 'userLink' - a.addClass 'dropdownToggle' - a.data 'userID', user.userID - a.data 'toggle', id - - li.append a + li.append @userTemplate.fetch + user: user menu = $ '' menu.addClass 'dropdownMenu' diff --git a/file/lib/data/room/Room.class.php b/file/lib/data/room/Room.class.php index 37eadc0..248d03e 100644 --- a/file/lib/data/room/Room.class.php +++ b/file/lib/data/room/Room.class.php @@ -137,7 +137,7 @@ public function getTitle() { /** * Returns the users that are currently active in this room. * - * @return array<\wcf\data\user\User> + * @return \wcf\data\user\UserList */ public function getUsers() { $sql = "SELECT @@ -152,27 +152,11 @@ public function getUsers() { $userIDs = array(); while ($userID = $stmt->fetchColumn()) $userIDs[] = $userID; - if (empty($userIDs)) return array(); + $userList = new \wcf\data\user\UserProfileList(); + if (!empty($userIDs)) $userList->getConditionBuilder()->add('user_table.userID IN (?)', array($userIDs)); + else $userList->getConditionBuilder()->add('1 = 0', array()); + $userList->readObjects(); - $sql = "SELECT - u.*, - st.fieldValue AS awayStatus - FROM - wcf".WCF_N."_user u - LEFT JOIN - wcf".WCF_N."_user_storage st - ON ( - u.userID = st.userID - AND st.field = ? - ) - WHERE - u.userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').") - ORDER BY - u.username ASC"; - $stmt = WCF::getDB()->prepareStatement($sql); - array_unshift($userIDs, 'away'); - $stmt->execute($userIDs); - - return $stmt->fetchObjects('\wcf\data\user\User'); + return $userList; } } diff --git a/file/lib/page/NewMessagesPage.class.php b/file/lib/page/NewMessagesPage.class.php index 34f7db7..f685aad 100644 --- a/file/lib/page/NewMessagesPage.class.php +++ b/file/lib/page/NewMessagesPage.class.php @@ -140,12 +140,21 @@ public function show() { foreach ($this->messages as $message) { $json['messages'][] = $message->jsonify(true); } + + \wcf\system\user\storage\UserStorageHandler::getInstance()->loadStorage(array_keys($this->users->getObjects())); + foreach ($this->users as $user) { $json['users'][] = array( 'userID' => (int) $user->userID, 'username' => $user->username, 'awayStatus' => $user->awayStatus, - 'suspended' => (boolean) !$this->room->canWrite($user) + 'suspended' => (boolean) !$this->room->canWrite($user->getDecoratedObject()), + 'avatar' => array( + 16 => $user->getAvatar()->getImageTag(16), + 24 => $user->getAvatar()->getImageTag(24), + 32 => $user->getAvatar()->getImageTag(32), + 48 => $user->getAvatar()->getImageTag(48) + ) ); } diff --git a/template/chat.tpl b/template/chat.tpl index 746a643..31ce164 100644 --- a/template/chat.tpl +++ b/template/chat.tpl @@ -23,6 +23,7 @@ {if MODULE_SMILEY}WCF.TabMenu.init();{/if} new WCF.Message.Smilies(); {capture assign='messageTemplate'}{include application='chat' file='message'}{/capture} + {capture assign='userTemplate'}{include application='chat' file='userListUser'}{/capture} window.chat = new be.bastelstu.Chat( { @@ -32,7 +33,8 @@ socketIOPath: '{@CHAT_SOCKET_IO_PATH|encodeJS}' }, new WCF.Template('{ldelim}$title} - {'chat.general.title'|language|encodeJS} - {PAGE_TITLE|language|encodeJS}'), - new WCF.Template('{@$messageTemplate|encodeJS}') + new WCF.Template('{@$messageTemplate|encodeJS}'), + new WCF.Template('{@$userTemplate|encodeJS}') ); {event name='afterInit'} diff --git a/template/userListUser.tpl b/template/userListUser.tpl new file mode 100644 index 0000000..f8c1015 --- /dev/null +++ b/template/userListUser.tpl @@ -0,0 +1 @@ +{literal}{@$user.avatar['24']} {$user.username}{/literal} \ No newline at end of file