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
|
title: document.title
|
||||||
messageTemplate: null
|
messageTemplate: null
|
||||||
newMessageCount: null
|
newMessageCount: null
|
||||||
events: { newMessage: $.Callbacks() }
|
events:
|
||||||
|
newMessage: $.Callbacks()
|
||||||
|
userMenu: $.Callbacks()
|
||||||
init: () ->
|
init: () ->
|
||||||
@bindEvents()
|
@bindEvents()
|
||||||
@refreshRoomList()
|
@refreshRoomList()
|
||||||
@ -50,11 +52,6 @@ TimWolla.WCF ?= {}
|
|||||||
@toggleSidebarContents $ event.target
|
@toggleSidebarContents $ event.target
|
||||||
, this
|
, this
|
||||||
|
|
||||||
$('.chatUser .chatUserLink').click $.proxy (event) ->
|
|
||||||
event.preventDefault()
|
|
||||||
@toggleUserMenu $ event.target
|
|
||||||
, this
|
|
||||||
|
|
||||||
$('#chatForm').submit $.proxy (event) ->
|
$('#chatForm').submit $.proxy (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@submit $ event.target
|
@submit $ event.target
|
||||||
@ -168,6 +165,7 @@ TimWolla.WCF ?= {}
|
|||||||
, this), 3000
|
, this), 3000
|
||||||
, this), 1000
|
, this), 1000
|
||||||
@handleMessages(data.messages)
|
@handleMessages(data.messages)
|
||||||
|
@handleUsers(data.users)
|
||||||
, this)
|
, this)
|
||||||
###
|
###
|
||||||
# Inserts the new messages.
|
# Inserts the new messages.
|
||||||
@ -188,6 +186,43 @@ TimWolla.WCF ?= {}
|
|||||||
$('.chatMessageContainer').animate
|
$('.chatMessageContainer').animate
|
||||||
scrollTop: $('.chatMessageContainer ul').height()
|
scrollTop: $('.chatMessageContainer ul').height()
|
||||||
, 1000
|
, 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.
|
# Inserts text into our input.
|
||||||
#
|
#
|
||||||
@ -284,12 +319,12 @@ TimWolla.WCF ?= {}
|
|||||||
# @param jQuery-object target
|
# @param jQuery-object target
|
||||||
###
|
###
|
||||||
toggleUserMenu: (target) ->
|
toggleUserMenu: (target) ->
|
||||||
liUserID = '#' + target.parent().parent().attr 'id'
|
li = target.parent()
|
||||||
|
|
||||||
if $(liUserID).hasClass 'activeMenuItem'
|
if li.hasClass 'activeMenuItem'
|
||||||
$(liUserID + ' .chatUserMenu').wcfBlindOut 'vertical', () ->
|
li.find('.chatUserMenu').wcfBlindOut 'vertical', () ->
|
||||||
$(liUserID).removeClass 'activeMenuItem'
|
li.removeClass 'activeMenuItem'
|
||||||
else
|
else
|
||||||
$(liUserID).addClass 'activeMenuItem'
|
li.addClass 'activeMenuItem'
|
||||||
$(liUserID + ' .chatUserMenu').wcfBlindIn()
|
li.find('.chatUserMenu').wcfBlindIn 'vertical'
|
||||||
)(jQuery)
|
)(jQuery)
|
||||||
|
@ -18,6 +18,7 @@ class ChatMessagePage extends AbstractPage {
|
|||||||
//public $neededPermissions = array('user.chat.canEnter');
|
//public $neededPermissions = array('user.chat.canEnter');
|
||||||
public $room = null;
|
public $room = null;
|
||||||
public $roomID = 0;
|
public $roomID = 0;
|
||||||
|
public $users = array();
|
||||||
public $useTemplate = false;
|
public $useTemplate = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,6 +37,19 @@ public function readData() {
|
|||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$row = $stmt->fetchArray();
|
$row = $stmt->fetchArray();
|
||||||
\wcf\util\ChatUtil::writeUserData(array('lastSeen' => $row['messageID']));
|
\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) {
|
foreach ($this->messages as $message) {
|
||||||
$json['messages'][] = $message->jsonify(true);
|
$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);
|
echo \wcf\util\JSON::encode($json);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -79,16 +79,16 @@
|
|||||||
<div id="sidebarContent">
|
<div id="sidebarContent">
|
||||||
<nav class="chatSidebarTabs">
|
<nav class="chatSidebarTabs">
|
||||||
<ul>
|
<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>
|
<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>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="sidebarContainer">
|
<div id="sidebarContainer">
|
||||||
<ul id="chatUserList">
|
<ul id="chatUserList">
|
||||||
{section name=user start=1 loop=26}
|
{*section name=user start=1 loop=26}
|
||||||
<li id="user-{$user}" class="chatUser">
|
<li class="chatUser">
|
||||||
<span class="bgFix"><a class="chatUserLink" href="javascript:;">User {$user}</a></span>
|
<a href="javascript:;">User {$user}</a>
|
||||||
<ul class="chatUserMenu">
|
<ul class="chatUserMenu">
|
||||||
<li>
|
<li>
|
||||||
<a href="javascript:;">{lang}wcf.chat.query{/lang}</a>
|
<a href="javascript:;">{lang}wcf.chat.query{/lang}</a>
|
||||||
@ -98,7 +98,7 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{/section}
|
{/section*}
|
||||||
</ul>
|
</ul>
|
||||||
<nav id="chatRoomList" class="sidebarMenu" style="display: none;">
|
<nav id="chatRoomList" class="sidebarMenu" style="display: none;">
|
||||||
<div>
|
<div>
|
||||||
|
Loading…
Reference in New Issue
Block a user