mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2025-01-09 00:20:08 +00:00
Adding basic user-sending
This commit is contained in:
parent
59ec2ac3f0
commit
cf07716179
@ -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></li>'
|
||||
li.attr 'id', id
|
||||
li.addClass 'chatUser'
|
||||
a = $ '<a href="javascript:;">'+user.username+'</a>'
|
||||
a.click $.proxy (event) ->
|
||||
event.preventDefault()
|
||||
@toggleUserMenu $ event.target
|
||||
, this
|
||||
li.append a
|
||||
menu = $ '<ul></ul>'
|
||||
menu.addClass 'chatUserMenu'
|
||||
menu.append $ '<li><a href="javascript:;">{lang}wcf.chat.query{/lang}</a></li>'
|
||||
menu.append $ '<li><a href="javascript:;">{lang}wcf.chat.kick{/lang}</a></li>'
|
||||
menu.append $ '<li><a href="javascript:;">{lang}wcf.chat.ban{/lang}</a></li>'
|
||||
menu.append $ '<li><a href="index.php/User/'+user.userID+'">{lang}wcf.chat.profile{/lang}</a></li>'
|
||||
@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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -79,16 +79,16 @@
|
||||
<div id="sidebarContent">
|
||||
<nav class="chatSidebarTabs">
|
||||
<ul>
|
||||
<li id="toggleUsers" class="active"><a href="javascript:;" title="{lang}wcf.chat.users{/lang}">{lang}wcf.chat.users{/lang} <span class="badge">25</span></a></li>
|
||||
<li id="toggleUsers" class="active"><a href="javascript:;" title="{lang}wcf.chat.users{/lang}">{lang}wcf.chat.users{/lang} <span class="badge">0</span></a></li>
|
||||
<li id="toggleRooms"><a href="javascript:;" title="{lang}wcf.chat.rooms{/lang}" data-refresh-url="{link controller="Chat" action="RefreshRoomList"}{/link}">{lang}wcf.chat.rooms{/lang} <span class="badge">{#$rooms|count}</span></a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div id="sidebarContainer">
|
||||
<ul id="chatUserList">
|
||||
{section name=user start=1 loop=26}
|
||||
<li id="user-{$user}" class="chatUser">
|
||||
<span class="bgFix"><a class="chatUserLink" href="javascript:;">User {$user}</a></span>
|
||||
{*section name=user start=1 loop=26}
|
||||
<li class="chatUser">
|
||||
<a href="javascript:;">User {$user}</a>
|
||||
<ul class="chatUserMenu">
|
||||
<li>
|
||||
<a href="javascript:;">{lang}wcf.chat.query{/lang}</a>
|
||||
@ -98,7 +98,7 @@
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
{/section}
|
||||
{/section*}
|
||||
</ul>
|
||||
<nav id="chatRoomList" class="sidebarMenu" style="display: none;">
|
||||
<div>
|
||||
|
Loading…
Reference in New Issue
Block a user