diff --git a/file/js/TimWolla.WCF.Chat.coffee b/file/js/TimWolla.WCF.Chat.coffee
index 9c16513..afd2771 100644
--- a/file/js/TimWolla.WCF.Chat.coffee
+++ b/file/js/TimWolla.WCF.Chat.coffee
@@ -16,7 +16,9 @@ TimWolla.WCF ?= {}
title: document.title
messageTemplate: null
newMessageCount: null
- events: { newMessage: $.Callbacks() }
+ events:
+ newMessage: $.Callbacks()
+ userMenu: $.Callbacks()
init: () ->
@bindEvents()
@refreshRoomList()
@@ -50,11 +52,6 @@ TimWolla.WCF ?= {}
@toggleSidebarContents $ event.target
, this
- $('.chatUser .chatUserLink').click $.proxy (event) ->
- event.preventDefault()
- @toggleUserMenu $ event.target
- , this
-
$('#chatForm').submit $.proxy (event) ->
event.preventDefault()
@submit $ event.target
@@ -168,6 +165,7 @@ TimWolla.WCF ?= {}
, this), 3000
, this), 1000
@handleMessages(data.messages)
+ @handleUsers(data.users)
, this)
###
# Inserts the new messages.
@@ -188,6 +186,43 @@ TimWolla.WCF ?= {}
$('.chatMessageContainer').animate
scrollTop: $('.chatMessageContainer ul').height()
, 1000
+ handleUsers: (users) ->
+ foundUsers = {}
+ for user in users
+ id = 'chatUser-'+user.userID
+ element = $('#'+id)
+ if element[0]
+ console.log('Shifting: ' + user.userID);
+ element = element.detach()
+ $('#chatUserList').append element
+ else
+ console.log('Inserting: ' + user.userID);
+ li = $ '
'
+ li.attr 'id', id
+ li.addClass 'chatUser'
+ a = $ ''+user.username+''
+ a.click $.proxy (event) ->
+ event.preventDefault()
+ @toggleUserMenu $ event.target
+ , this
+ li.append a
+ menu = $ ''
+ menu.addClass 'chatUserMenu'
+ menu.append $ '{lang}wcf.chat.query{/lang}'
+ menu.append $ '{lang}wcf.chat.kick{/lang}'
+ menu.append $ '{lang}wcf.chat.ban{/lang}'
+ menu.append $ '{lang}wcf.chat.profile{/lang}'
+ @events.userMenu.fire user, menu
+ li.append menu
+ li.appendTo $ '#chatUserList'
+
+ foundUsers[id] = true
+
+ $('.chatUser').each () ->
+ if typeof foundUsers[$(this).attr('id')] is 'undefined'
+ $(this).remove()
+
+ $('#toggleUsers .badge').text(users.length);
###
# Inserts text into our input.
#
@@ -284,12 +319,12 @@ TimWolla.WCF ?= {}
# @param jQuery-object target
###
toggleUserMenu: (target) ->
- liUserID = '#' + target.parent().parent().attr 'id'
+ li = target.parent()
- if $(liUserID).hasClass 'activeMenuItem'
- $(liUserID + ' .chatUserMenu').wcfBlindOut 'vertical', () ->
- $(liUserID).removeClass 'activeMenuItem'
+ if li.hasClass 'activeMenuItem'
+ li.find('.chatUserMenu').wcfBlindOut 'vertical', () ->
+ li.removeClass 'activeMenuItem'
else
- $(liUserID).addClass 'activeMenuItem'
- $(liUserID + ' .chatUserMenu').wcfBlindIn()
+ li.addClass 'activeMenuItem'
+ li.find('.chatUserMenu').wcfBlindIn 'vertical'
)(jQuery)
diff --git a/file/lib/page/ChatMessagePage.class.php b/file/lib/page/ChatMessagePage.class.php
index 6fc4506..f05c03e 100644
--- a/file/lib/page/ChatMessagePage.class.php
+++ b/file/lib/page/ChatMessagePage.class.php
@@ -18,6 +18,7 @@ class ChatMessagePage extends AbstractPage {
//public $neededPermissions = array('user.chat.canEnter');
public $room = null;
public $roomID = 0;
+ public $users = array();
public $useTemplate = false;
/**
@@ -36,6 +37,19 @@ public function readData() {
$stmt->execute();
$row = $stmt->fetchArray();
\wcf\util\ChatUtil::writeUserData(array('lastSeen' => $row['messageID']));
+
+ $sql = "SELECT userID FROM wcf".WCF_N."_user_storage WHERE field = 'roomID' AND packageID = 16 AND fieldValue = ".intval($this->roomID);
+ $stmt = WCF::getDB()->prepareStatement($sql);
+ $stmt->execute();
+ while ($row = $stmt->fetchArray()) $userIDs[] = $row['userID'];
+
+ $sql = "SELECT u.*
+ FROM wcf".WCF_N."_user u
+ WHERE userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').")
+ ORDER BY u.username ASC";
+ $stmt = WCF::getDB()->prepareStatement($sql);
+ $stmt->execute($userIDs);
+ $this->users = $stmt->fetchObjects('\wcf\data\user\User');
}
/**
@@ -55,6 +69,12 @@ public function show() {
foreach ($this->messages as $message) {
$json['messages'][] = $message->jsonify(true);
}
+ foreach ($this->users as $user) {
+ $json['users'][] = array(
+ 'userID' => $user->userID,
+ 'username' => $user->username
+ );
+ }
echo \wcf\util\JSON::encode($json);
exit;
}
diff --git a/template/chat.tpl b/template/chat.tpl
index 47eccb5..59efd39 100644
--- a/template/chat.tpl
+++ b/template/chat.tpl
@@ -79,16 +79,16 @@