closed #615 - added "active chats" dropdown to header

- some minor tweaks also, to make taskbar work a little better with chats
v1.18.x
Julian Lam 11 years ago
parent 2a1671ba9b
commit 030ce95dea

@ -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"
}

@ -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) {

@ -102,6 +102,7 @@ define(['taskbar'], function(taskbar) {
chatModal.show();
module.bringModalToTop(chatModal);
checkOnlineStatus(chatModal);
taskbar.updateActive(uuid);
}
module.minimize = function(uuid) {

@ -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
}
});

@ -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=""/>

@ -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));

@ -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);

Loading…
Cancel
Save