Skip to content

Node.js based forum software built for the modern web

typing notifcation socket implementation for chat page, #1788

Julian Lam404ab4878b70
diff --git a/public/language/en_GB/modules.json b/public/language/en_GB/modules.json
index f1902d0e21..44fd976173 100644
--- a/public/language/en_GB/modules.json
+++ b/public/language/en_GB/modules.json
@@ -1,6 +1,6 @@
{
"chat.chatting_with": "Chat with <span id=\"chat-with-name\"></span>",
- "chat.placeholder": "type chat message here, press enter to send",
+ "chat.placeholder": "Type chat message here, press enter to send",
"chat.send": "Send",
"chat.no_active": "You have no active chats.",
"chat.user_typing": "%1 is typing ...",
diff --git a/public/src/forum/chats.js b/public/src/forum/chats.js
index 6d5587a11e..6d48158cad 100644
--- a/public/src/forum/chats.js
+++ b/public/src/forum/chats.js
@@ -6,9 +6,75 @@ define('forum/chats', function() {
var Chats = {};
Chats.init = function() {
+ Chats.addEventListeners();
+ Chats.addSocketListeners();
+ };
+
+ Chats.getRecipientUid = function() {
+ return parseInt($('.expanded-chat').attr('data-uid'), 10);
+ };
+
+ Chats.isCurrentChat = function(uid) {
+ uid = parseInt(uid, 10);
+ if (Chats.getRecipientUid() === uid) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+
+ Chats.addEventListeners = function() {
+ var inputEl = $('.chat-input');
$('.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')));
+ });
+
+ // inputEl.off('keypress').on('keypress', function(e) {
+ // if(e.which === 13) {
+ // Chat.sendMessage(chatModal);
+ // }
+ // });
+
+ 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){
+ // sendMessage(chatModal);
+ // return false;
+ // });
+ };
+
+ Chats.addSocketListeners = function() {
+ var typingNotifEl = $('.user-typing');
+
+ socket.on('event:chats.receive', function(data) {
+
+ });
+
+ socket.on('event:chats.userStartTyping', function(withUid) {
+ if (Chats.isCurrentChat(withUid)) {
+ typingNotifEl.removeClass('hide');
+ }
+ });
+
+ socket.on('event:chats.userStopTyping', function(withUid) {
+ if (Chats.isCurrentChat(withUid)) {
+ typingNotifEl.addClass('hide');
+ }
+ });
+ };
+
+ Chats.notifyTyping = function(typing) {
+ socket.emit('modules.chats.user' + (typing ? 'Start' : 'Stop') + 'Typing', {
+ touid: Chats.getRecipientUid(),
+ fromUid: app.uid
});
};
diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js
index fd55dc7dc9..c996af7b10 100644
--- a/src/controllers/accounts.js
+++ b/src/controllers/accounts.js
@@ -486,8 +486,6 @@ accountsController.getChats = function(req, res, next) {
return next(err);
}
- console.log(res.locals);
-
res.render('chats', {
meta: res.locals.chatData,
chats: chats,