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 try logging in?",
"404.title": "Not Found",
- "404.message": "You seem to have stumbled upon a page that does not exist. Return to the home page.",
+ "404.message": "You seem to have stumbled upon a page that does not exist. Return to the home page.",
"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
' + userObj.username + '';
+
+ 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 @@
-
+
+
+
+
+
+
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);