v1.18.x
Baris Usakli 12 years ago
parent 760037ba0a
commit 9f8c9e8822

@ -733,4 +733,13 @@ body .navbar .nodebb-inline-block {
font-size: 12px;
color: red;
}
}
#chat-content {
width:95%;
height:200px;
}
#chat-message-input {
width:95%;
}

@ -16,7 +16,7 @@
<!-- BEGIN users -->
<div class="users-box well">
<a href="/users/{users.username}">
<img src="{users.picture}"/>
<img src="{users.picture}" class="user-8080-picture"/>
</a>
<br/>
<a href="/users/{users.username}">{users.username}</a>

@ -81,7 +81,6 @@
}
});
// Post window events
var postWindowEl = document.getElementById('post_window'),
discardEl = document.getElementById('discard-post');

@ -90,6 +90,18 @@
</div>
</div>
<div id="chat-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3 id="myModalLabel">Chat with <span id="chat-with-name"></span></h3>
</div>
<div class="modal-body">
<textarea id="chat-content" cols="40" rows="10"></textarea><br/>
<input id="chat-message-input" type="text" name="chat-message" placeholder="type chat message here press enter to send"/><br/>
<a id="chat-message-send-btn" href="#" class="btn btn-primary">Send</a>
</div>
</div>
<div id="notification_window"></div>
<div class="container" id="content">

@ -52,7 +52,7 @@
<!-- END main_posts -->
<!-- BEGIN posts -->
<li class="row post-row" data-pid="{posts.pid}" data-uid="{posts.uid}" data-deleted="{posts.deleted}">
<li class="row post-row" data-pid="{posts.pid}" data-uid="{posts.uid}" data-username="{posts.username}" data-deleted="{posts.deleted}">
<div class="span1 profile-image-block visible-desktop">
<!--<i class="icon-spinner icon-spin icon-2x pull-left"></i>-->
<a href="/users/{posts.username}">
@ -66,6 +66,7 @@
<div class="post-signature">{posts.signature}</div>
<div class="profile-block">
<span class="post-buttons">
<div id="ids_{posts.pid}_{posts.uid}" class="chat hidden-phone"><i class="icon-comment"></i></div>
<div id="ids_{posts.pid}_{posts.uid}" class="edit {posts.display_moderator_tools} hidden-phone"><i class="icon-pencil"></i></div>
<div id="ids_{posts.pid}_{posts.uid}" class="delete {posts.display_moderator_tools} hidden-phone"><i class="icon-trash"></i></div>
<div id="quote_{posts.pid}_{posts.uid}" class="quote hidden-phone"><i class="icon-quote-left"></i></div>
@ -191,6 +192,7 @@
e.preventDefault();
moveThreadModal.modal('show');
}, false);
moveThreadModal.on('shown', function() {
var loadingEl = document.getElementById('categories-loading');
if (loadingEl) {
@ -291,6 +293,79 @@
}
});
// CHAT, move to chat.js later?
$('.post-container').delegate('.chat', 'click', function(e){
var username = $(this).parents('li').attr('data-username');
var touid = $(this).parents('li').attr('data-uid');
var chatModal = $('#chat-modal-'+touid);
console.log($('#chat-modal-'+touid).length);
console.log('#chat-modal-'+touid);
if(!chatModal.length) {
var chatModal = $('#chat-modal').clone();
chatModal.attr('id','#chat-modal-'+touid);
chatModal.appendTo($('body'));
chatModal.find('.close').on('click',function(e){
chatModal.hide();
});
}
chatModal.show();
chatModal.find('#chat-with-name').html(username);
//addSendHandler(touid);
});
$('#chat-modal').on('hide', function(){
$('#chat-message-input').off('keypress');
$('#chat-content').html('');
});
socket.on('chatMessage', function(data){
var username = data.username;
var fromuid = data.fromuid;
var message = data.message;
$('#chat-modal').modal('show');
$('#chat-with-name').html(username);
$('#chat-content').append(message);
var chatContent = $('#chat-content');
chatContent.scrollTop(
chatContent[0].scrollHeight - chatContent.height()
);
addSendHandler(fromuid);
});
function addSendHandler(touid) {
$('#chat-message-input').off('keypress');
$('#chat-message-input').on('keypress', function(e) {
if(e.which === 13) {
sendMessage(touid);
}
});
$('#chat-message-send-btn').off('click');
$('#chat-message-send-btn').on('click', function(e){
sendMessage(touid);
return false;
});
}
function sendMessage(touid) {
var msg = $('#chat-message-input').val() + '\n';
socket.emit('sendChatMessage', { touid:touid, message:msg});
$('#chat-message-input').val('');
$('#chat-content').append('You : '+ msg);
}
//end of chat
ajaxify.register_events([
'event:rep_up', 'event:rep_down', 'event:new_post', 'api:get_users_in_room',
'event:topic_deleted', 'event:topic_restored', 'event:topic:locked',
@ -299,6 +374,7 @@
'api:posts.favourite'
]);
socket.on('api:get_users_in_room', function(users) {
var anonymous = users.anonymous,
usernames = users.usernames,

@ -10,7 +10,8 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
(function(io) {
var users = {},
rooms = {}
userSockets = {},
rooms = {}
global.io = io;
@ -48,6 +49,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
var hs = socket.handshake;
var uid = users[hs.sessionID];
userSockets[uid] = socket;
user.go_online(uid);
@ -233,6 +235,19 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
socket.on('api:posts.restore', function(data) {
posts.restore(uid, data.pid);
});
socket.on('sendChatMessage', function(data) {
var touid = data.touid;
if(userSockets[touid]) {
var msg = data.message;
user.getUserField(uid, 'username', function(username) {
var finalMessage = username + ' says : ' + msg;
userSockets[touid].emit('chatMessage', {fromuid:uid, username:username, message:finalMessage});
});
}
});
});
}(SocketIO));

Loading…
Cancel
Save