Skip to content

Node.js based forum software built for the modern web

closed #615 - added "active chats" dropdown to header - some minor tweaks also, to make taskbar work a little better with chats

Julian Lam030ce95deaed
diff --git a/public/language/en/global.json b/public/language/en/global.json
index 00576a18be..32ea294957 100644
--- a/public/language/en/global.json
+++ b/public/language/en/global.json
@@ -5,7 +5,7 @@
"403.title": "Access Denied",
"403.message": "You seem to have stumbled upon a page that you do not have access to. Perhaps you should <a href='/login'>try logging in</a>?",
"404.title": "Not Found",
- "404.message": "You seem to have stumbled upon a page that does not exist. Return to the <a href='/''>home page</a>.",
+ "404.message": "You seem to have stumbled upon a page that does not exist. Return to the <a href='/'>home page</a>.",
"500.title": "Internal error.",
"500.message": "Ooops! Looks like something went wrong!",
"logout": "Logout",
@@ -16,5 +16,6 @@
"header.unread": "Unread",
"header.users": "Users",
"header.search": "Search",
- "notifications.loading": "Loading Notifications"
+ "notifications.loading": "Loading Notifications",
+ "chats.loading": "Loading Chats"
}
\ No newline at end of file
diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js
index 9de817550c..a496ee7c95 100644
--- a/public/src/forum/footer.js
+++ b/public/src/forum/footer.js
@@ -175,6 +175,34 @@
Tinycon.setBubble(savedCount+1);
});
+ // Chats Dropdown
+ var chatsToggleEl = $('#chat_dropdown'),
+ chatsListEl = $('#chat-list'),
+ chatDropdownEl = chatsToggleEl.parent();
+ chatsToggleEl.on('click', function() {
+ if (chatDropdownEl.hasClass('open')) {
+ return;
+ }
+
+ socket.emit('api:chats.list', function(chats) {
+ var chatsFrag = document.createDocumentFragment(),
+ chatEl = document.createElement('li'),
+ numChats = chats.length,
+ x, userObj;
+
+ for(x=0;x<numChats;x++) {
+ userObj = chats[x];
+ chatEl.setAttribute('data-uid', userObj.uid);
+ chatEl.innerHTML = '<a href="javascript:app.openChat(\'' + userObj.username + '\', ' + userObj.uid + ');"><img src="' + userObj.picture + '" title="' + userObj.username + '" />' + userObj.username + '</a>';
+
+ chatsFrag.appendChild(chatEl.cloneNode(true));
+ }
+
+ chatsListEl.empty();
+ chatsListEl.html(chatsFrag);
+ // console.log('received chats: ', chats);
+ });
+ });
socket.on('chatMessage', function(data) {
diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js
index 8afcd129ad..2aeb2f02bf 100644
--- a/public/src/modules/chat.js
+++ b/public/src/modules/chat.js
@@ -102,6 +102,7 @@ define(['taskbar'], function(taskbar) {
chatModal.show();
module.bringModalToTop(chatModal);
checkOnlineStatus(chatModal);
+ taskbar.updateActive(uuid);
}
module.minimize = function(uuid) {
diff --git a/public/src/modules/taskbar.js b/public/src/modules/taskbar.js
index 131e52ada1..df7e8c460d 100644
--- a/public/src/modules/taskbar.js
+++ b/public/src/modules/taskbar.js
@@ -87,6 +87,11 @@ define(function() {
toggleNew: function(uuid, state) {
var btnEl = $(taskbar.tasklist.querySelector('[data-uuid="' + uuid + '"]'));
btnEl.toggleClass('new', state);
+ },
+ updateActive: function(uuid) {
+ var tasks = $(taskbar.tasklist).find('li');
+ tasks.removeClass('active');
+ tasks.filter('[data-uuid="' + uuid + '"]').addClass('active');
}
}
@@ -98,6 +103,7 @@ define(function() {
push: taskbar.push,
discard: taskbar.discard,
minimize: taskbar.minimize,
- toggleNew: taskbar.toggleNew
+ toggleNew: taskbar.toggleNew,
+ updateActive: taskbar.updateActive
}
});
\ No newline at end of file
diff --git a/public/templates/header.tpl b/public/templates/header.tpl
index 3493ecd75c..b1a2b48479 100644
--- a/public/templates/header.tpl
+++ b/public/templates/header.tpl
@@ -89,7 +89,7 @@
</form>
</li>
- <li id="notifications-list" class="notifications dropdown text-center hidden-xs">
+ <li class="notifications dropdown text-center hidden-xs">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" id="notif_dropdown"></a>
<ul id="notif-list" class="dropdown-menu" aria-labelledby="notif_dropdown">
<li>
@@ -98,6 +98,15 @@
</ul>
</li>
+ <li class="chats dropdown text-center hidden-xs">
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#" id="chat_dropdown"><i class="fa fa-comment"></i></a>
+ <ul id="chat-list" class="dropdown-menu" aria-labelledby="chat_dropdown">
+ <li>
+ <a href="#"><i class="fa fa-refresh fa-spin"></i> [[global:chats.loading]]</a>
+ </li>
+ </ul>
+ </li>
+
<li id="user_label" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" id="user_dropdown">
<img src=""/>
diff --git a/src/messaging.js b/src/messaging.js
index 22e9abfeca..e6275ec9ed 100644
--- a/src/messaging.js
+++ b/src/messaging.js
@@ -28,6 +28,8 @@ var RDB = require('./redis'),
RDB.hmset('message:' + mid, message);
RDB.rpush('messages:' + uids[0] + ':' + uids[1], mid);
+ Messaging.updateChatTime(fromuid, touid);
+ Messaging.updateChatTime(touid, fromuid);
callback(null, message);
});
}
@@ -73,4 +75,22 @@ var RDB = require('./redis'),
});
}
+ Messaging.updateChatTime = function(uid, toUid, callback) {
+ RDB.zadd('uid:' + uid + ':chats', Date.now(), toUid, function(err) {
+ if (callback) {
+ callback(err);
+ }
+ });
+ };
+
+ Messaging.getRecentChats = function(uid, callback) {
+ RDB.zrevrange('uid:' + uid + ':chats', 0, 9, function(err, uids) {
+ if (!err) {
+ user.getMultipleUserFields(uids, ['username', 'picture', 'uid'], callback);
+ } else {
+ callback(err);
+ }
+ });
+ };
+
}(exports));
\ No newline at end of file
diff --git a/src/websockets.js b/src/websockets.js
index 6fea81be45..80a4694dd1 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -27,6 +27,7 @@ var cookie = require('cookie'),
notifications = require('./notifications'),
threadTools = require('./threadTools'),
postTools = require('./postTools'),
+ Messaging = require('./messaging'),
meta = require('./meta'),
logger = require('./logger'),
socketCookieParser = express.cookieParser(nconf.get('secret')),
@@ -680,7 +681,7 @@ websockets.init = function(io) {
socket.on('getChatMessages', function(data, callback) {
var touid = data.touid;
- require('./messaging').getMessages(uid, touid, function(err, messages) {
+ Messaging.getMessages(uid, touid, function(err, messages) {
if (err)
return callback(null);
@@ -709,7 +710,7 @@ websockets.init = function(io) {
});
}
- require('./messaging').addMessage(uid, touid, msg, function(err, message) {
+ Messaging.addMessage(uid, touid, msg, function(err, message) {
var numSockets = 0;
if (userSockets[touid]) {
@@ -742,6 +743,16 @@ websockets.init = function(io) {
});
});
+ socket.on('api:chats.list', function(callback) {
+ Messaging.getRecentChats(uid, function(err, uids) {
+ if (err) {
+ winston.warn('[(socket) api:chats.list] Problem retrieving chats: ' + err.message);
+ }
+
+ callback(uids || []);
+ });
+ });
+
socket.on('api:config.get', function(data) {
meta.configs.list(function(err, config) {
if (!err) socket.emit('api:config.get', config);