mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
more WIP
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
"header.tags": "Tags",
|
"header.tags": "Tags",
|
||||||
"header.popular": "Popular",
|
"header.popular": "Popular",
|
||||||
"header.users": "Users",
|
"header.users": "Users",
|
||||||
|
"header.chats": "Chats",
|
||||||
"header.notifications": "Notifications",
|
"header.notifications": "Notifications",
|
||||||
"header.search": "Search",
|
"header.search": "Search",
|
||||||
"header.profile": "Profile",
|
"header.profile": "Profile",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/* globals define, app*/
|
/* globals define, app*/
|
||||||
|
|
||||||
define('forum/chats', function() {
|
define('forum/chats', ['string','sounds'], function(S, sounds) {
|
||||||
var Chats = {};
|
var Chats = {};
|
||||||
|
|
||||||
Chats.init = function() {
|
Chats.init = function() {
|
||||||
@@ -24,31 +24,32 @@ define('forum/chats', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chats.addEventListeners = function() {
|
Chats.addEventListeners = function() {
|
||||||
var inputEl = $('.chat-input');
|
var inputEl = $('.chat-input'),
|
||||||
|
sendEl = $('.expanded-chat button[data-action="send"]');
|
||||||
|
|
||||||
$('.chats-list').on('click', 'li', function(e) {
|
$('.chats-list').on('click', 'li', function(e) {
|
||||||
// app.openChat($(this).attr('data-username'), $(this).attr('data-uid'));
|
// app.openChat($(this).attr('data-username'), $(this).attr('data-uid'));
|
||||||
ajaxify.go('chats/' + utils.slugify($(this).attr('data-username')));
|
ajaxify.go('chats/' + utils.slugify($(this).attr('data-username')));
|
||||||
});
|
});
|
||||||
|
|
||||||
// inputEl.off('keypress').on('keypress', function(e) {
|
inputEl.off('keypress').on('keypress', function(e) {
|
||||||
// if(e.which === 13) {
|
if(e.which === 13) {
|
||||||
// Chat.sendMessage(chatModal);
|
Chats.sendMessage(Chats.getRecipientUid(), inputEl);
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
inputEl.off('keyup').on('keyup', function() {
|
|
||||||
if ($(this).val()) {
|
|
||||||
Chats.notifyTyping(true);
|
|
||||||
} else {
|
|
||||||
Chats.notifyTyping(false);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// chatModal.find('#chat-message-send-btn').off('click').on('click', function(e){
|
inputEl.off('keyup').on('keyup', function() {
|
||||||
// sendMessage(chatModal);
|
if ($(this).val()) {
|
||||||
// return false;
|
Chats.notifyTyping(Chats.getRecipientUid(), true);
|
||||||
// });
|
} else {
|
||||||
|
Chats.notifyTyping(Chats.getRecipientUid(), false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sendEl.off('click').on('click', function(e) {
|
||||||
|
Chats.sendMessage(Chats.getRecipientUid(), inputEl);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Chats.addSocketListeners = function() {
|
Chats.addSocketListeners = function() {
|
||||||
@@ -71,12 +72,26 @@ define('forum/chats', function() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Chats.notifyTyping = function(typing) {
|
Chats.notifyTyping = function(toUid, typing) {
|
||||||
socket.emit('modules.chats.user' + (typing ? 'Start' : 'Stop') + 'Typing', {
|
socket.emit('modules.chats.user' + (typing ? 'Start' : 'Stop') + 'Typing', {
|
||||||
touid: Chats.getRecipientUid(),
|
touid: toUid,
|
||||||
fromUid: app.uid
|
fromUid: app.uid
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Chats.sendMessage = function(toUid, inputEl) {
|
||||||
|
var msg = S(inputEl.val()).stripTags().s;
|
||||||
|
if (msg.length) {
|
||||||
|
msg = msg +'\n';
|
||||||
|
socket.emit('modules.chats.send', {
|
||||||
|
touid:toUid,
|
||||||
|
message:msg
|
||||||
|
});
|
||||||
|
inputEl.val('');
|
||||||
|
sounds.play('chat-outgoing');
|
||||||
|
Chats.notifyTyping(toUid, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return Chats;
|
return Chats;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
/* globals app, config, define, socket, translator, templates, utils */
|
/* globals app, config, define, socket, translator, templates, utils */
|
||||||
|
|
||||||
define('chat', ['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
|
define('chat', ['taskbar', 'string', 'sounds', 'forum/chats'], function(taskbar, S, sounds, Chats) {
|
||||||
|
|
||||||
var module = {};
|
var module = {};
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ define('chat', ['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
|
|||||||
chatModal.remove();
|
chatModal.remove();
|
||||||
chatModal.data('modal', null);
|
chatModal.data('modal', null);
|
||||||
taskbar.discard('chat', chatModal.attr('UUID'));
|
taskbar.discard('chat', chatModal.attr('UUID'));
|
||||||
notifyStopTyping(chatModal.touid);
|
Chats.notifyTyping(chatModal.touid, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.center = function(chatModal) {
|
module.center = function(chatModal) {
|
||||||
@@ -258,13 +258,9 @@ define('chat', ['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
|
|||||||
taskbar.minimize('chat', uuid);
|
taskbar.minimize('chat', uuid);
|
||||||
clearInterval(chatModal.intervalId);
|
clearInterval(chatModal.intervalId);
|
||||||
chatModal.intervalId = 0;
|
chatModal.intervalId = 0;
|
||||||
notifyStopTyping(chatModal.touid);
|
Chats.notifyTyping(chatModal.touid, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
function notifyStopTyping(touid) {
|
|
||||||
socket.emit('modules.chats.userStopTyping', {touid:touid, fromUid: app.uid});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getChatMessages(chatModal, callback) {
|
function getChatMessages(chatModal, callback) {
|
||||||
socket.emit('modules.chats.get', {touid:chatModal.touid}, function(err, messages) {
|
socket.emit('modules.chats.get', {touid:chatModal.touid}, function(err, messages) {
|
||||||
for(var i = 0; i<messages.length; ++i) {
|
for(var i = 0; i<messages.length; ++i) {
|
||||||
@@ -278,7 +274,7 @@ define('chat', ['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
|
|||||||
var input = chatModal.find('#chat-message-input');
|
var input = chatModal.find('#chat-message-input');
|
||||||
input.off('keypress').on('keypress', function(e) {
|
input.off('keypress').on('keypress', function(e) {
|
||||||
if(e.which === 13) {
|
if(e.which === 13) {
|
||||||
sendMessage(chatModal);
|
Chats.sendMessage(chatModal.touid, chatModal.find('#chat-message-input'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -286,27 +282,16 @@ define('chat', ['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
|
|||||||
if ($(this).val()) {
|
if ($(this).val()) {
|
||||||
socket.emit('modules.chats.userStartTyping', {touid:chatModal.touid, fromUid: app.uid});
|
socket.emit('modules.chats.userStartTyping', {touid:chatModal.touid, fromUid: app.uid});
|
||||||
} else {
|
} else {
|
||||||
notifyStopTyping(chatModal.touid);
|
Chats.notifyTyping(chatModal.touid, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
chatModal.find('#chat-message-send-btn').off('click').on('click', function(e){
|
chatModal.find('#chat-message-send-btn').off('click').on('click', function(e){
|
||||||
sendMessage(chatModal);
|
Chats.sendMessage(chatModal.touid, chatModal.find('#chat-message-input'));
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMessage(chatModal) {
|
|
||||||
var msg = S(chatModal.find('#chat-message-input').val()).stripTags().s;
|
|
||||||
if (msg.length) {
|
|
||||||
msg = msg +'\n';
|
|
||||||
socket.emit('modules.chats.send', {touid:chatModal.touid, message:msg});
|
|
||||||
chatModal.find('#chat-message-input').val('');
|
|
||||||
sounds.play('chat-outgoing');
|
|
||||||
notifyStopTyping(chatModal.touid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.appendChatMessage = function(chatModal, data) {
|
module.appendChatMessage = function(chatModal, data) {
|
||||||
var chatContent = chatModal.find('#chat-content');
|
var chatContent = chatModal.find('#chat-content');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user