Merge branch 'socketAL-fix' of https://github.com/designcreateplay/NodeBB into socketAL-fix

v1.18.x
Baris Soner Usakli 11 years ago
commit 8740cc0fc7

@ -13,13 +13,13 @@ define(['taskbar', 'string'], function(taskbar, S) {
return; return;
} }
socket.emit('modules.chats.list', function(chats) { socket.emit('modules.chats.list', function(err, chats) {
var chatsFrag = document.createDocumentFragment(), var chatsFrag = document.createDocumentFragment(),
chatEl = document.createElement('li'), chatEl = document.createElement('li'),
numChats = chats.length, numChats = chats.length,
x, userObj; x, userObj;
if (numChats > 0) { if (!err && numChats > 0) {
for(x=0;x<numChats;x++) { for(x=0;x<numChats;x++) {
userObj = chats[x]; userObj = chats[x];
chatEl.setAttribute('data-uid', userObj.uid); chatEl.setAttribute('data-uid', userObj.uid);
@ -191,7 +191,7 @@ define(['taskbar', 'string'], function(taskbar, S) {
} }
function getChatMessages(chatModal, callback) { function getChatMessages(chatModal, callback) {
socket.emit('modules.chats.get', {touid:chatModal.touid}, function(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) {
module.appendChatMessage(chatModal, messages[i].content, messages[i].timestamp); module.appendChatMessage(chatModal, messages[i].content, messages[i].timestamp);
} }

@ -47,7 +47,7 @@ define(['taskbar'], function(taskbar) {
if(allowed()) { if(allowed()) {
socket.emit('modules.composer.push', { socket.emit('modules.composer.push', {
pid: pid pid: pid
}, function(threadData) { }, function(err, threadData) {
push({ push({
pid: pid, pid: pid,
title: threadData.title, title: threadData.title,
@ -108,8 +108,8 @@ define(['taskbar'], function(taskbar) {
} else if (parseInt(postData.pid) > 0) { } else if (parseInt(postData.pid) > 0) {
titleEl.val(postData.title); titleEl.val(postData.title);
titleEl.prop('readOnly', true); titleEl.prop('readOnly', true);
socket.emit('modules.composer.editCheck', postData.pid, function(editCheck) { socket.emit('modules.composer.editCheck', postData.pid, function(err, editCheck) {
if (editCheck.titleEditable) { if (!err && editCheck.titleEditable) {
postContainer.find('input').prop('readonly', false); postContainer.find('input').prop('readonly', false);
} }
}); });

@ -11,14 +11,14 @@ define(function() {
notifTrigger.addEventListener('click', function(e) { notifTrigger.addEventListener('click', function(e) {
e.preventDefault(); e.preventDefault();
if (notifContainer.className.indexOf('open') === -1) { if (notifContainer.className.indexOf('open') === -1) {
socket.emit('notifications.get', null, function(data) { socket.emit('notifications.get', null, function(err, data) {
var notifFrag = document.createDocumentFragment(), var notifFrag = document.createDocumentFragment(),
notifEl = document.createElement('li'), notifEl = document.createElement('li'),
numRead = data.read.length, numRead = data.read.length,
numUnread = data.unread.length, numUnread = data.unread.length,
x; x;
notifList.innerHTML = ''; notifList.innerHTML = '';
if ((data.read.length + data.unread.length) > 0) { if (!err && (data.read.length + data.unread.length) > 0) {
for (x = 0; x < numUnread; x++) { for (x = 0; x < numUnread; x++) {
notifEl.setAttribute('data-nid', data.unread[x].nid); notifEl.setAttribute('data-nid', data.unread[x].nid);
notifEl.className = 'unread'; notifEl.className = 'unread';
@ -51,13 +51,15 @@ define(function() {
notifIcon.toggleClass('active', false); notifIcon.toggleClass('active', false);
} }
socket.emit('modules.notifications.mark_all_read', null, function() { socket.emit('modules.notifications.mark_all_read', null, function(err) {
notifIcon.toggleClass('active', false); if (!err) {
app.refreshTitle(); notifIcon.toggleClass('active', false);
app.refreshTitle();
// Update favicon + local count // Update favicon + local count
Tinycon.setBubble(0); Tinycon.setBubble(0);
localStorage.setItem('notifications:count', 0); localStorage.setItem('notifications:count', 0);
}
}); });
}); });
} }

@ -11,6 +11,7 @@ var posts = require('../posts'),
async = require('async'), async = require('async'),
S = require('string'), S = require('string'),
winston = require('winston'), winston = require('winston'),
server = require('./'),
SocketModules = {}; SocketModules = {};
@ -32,7 +33,7 @@ SocketModules.composer.push = function(socket, data, callback) {
}); });
} }
], function(err, results) { ], function(err, results) {
callback({ callback(err, {
title: results[1], title: results[1],
pid: data.pid, pid: data.pid,
body: results[0].content body: results[0].content
@ -40,7 +41,7 @@ SocketModules.composer.push = function(socket, data, callback) {
}); });
} }
} else { } else {
callback({ callback(null, {
error: 'no-uid' error: 'no-uid'
}); });
} }
@ -48,8 +49,12 @@ SocketModules.composer.push = function(socket, data, callback) {
SocketModules.composer.editCheck = function(socket, pid, callback) { SocketModules.composer.editCheck = function(socket, pid, callback) {
posts.getPostField(pid, 'tid', function(err, tid) { posts.getPostField(pid, 'tid', function(err, tid) {
if (err) {
return callback(err);
}
postTools.isMain(pid, tid, function(err, isMain) { postTools.isMain(pid, tid, function(err, isMain) {
callback({ callback(err, {
titleEditable: isMain titleEditable: isMain
}); });
}); });
@ -62,13 +67,7 @@ SocketModules.chats = {};
SocketModules.chats.get = function(socket, data, callback) { SocketModules.chats.get = function(socket, data, callback) {
var touid = data.touid; var touid = data.touid;
Messaging.getMessages(socket.uid, touid, function(err, messages) { Messaging.getMessages(socket.uid, touid, callback);
if (err) {
return callback(null);
}
callback(messages);
});
}; };
SocketModules.chats.send = function(socket, data) { SocketModules.chats.send = function(socket, data) {
@ -102,11 +101,11 @@ SocketModules.chats.send = function(socket, data) {
var numSockets = 0, var numSockets = 0,
x; x;
if (socket.userSockets[touid]) { if (server.userSockets[touid]) {
numSockets = socket.userSockets[touid].length; numSockets = server.userSockets[touid].length;
for (x = 0; x < numSockets; ++x) { for (x = 0; x < numSockets; ++x) {
socket.userSockets[touid][x].emit('event:chats.receive', { server.userSockets[touid][x].emit('event:chats.receive', {
fromuid: socket.uid, fromuid: socket.uid,
username: username, username: username,
// todo this isnt very nice, but can't think of a better way atm // todo this isnt very nice, but can't think of a better way atm
@ -116,12 +115,12 @@ SocketModules.chats.send = function(socket, data) {
} }
} }
if (socket.userSockets[socket.uid]) { if (server.userSockets[socket.uid]) {
numSockets = socket.userSockets[socket.uid].length; numSockets = server.userSockets[socket.uid].length;
for (x = 0; x < numSockets; ++x) { for (x = 0; x < numSockets; ++x) {
socket.userSockets[socket.uid][x].emit('event:chats.receive', { server.userSockets[socket.uid][x].emit('event:chats.receive', {
fromuid: touid, fromuid: touid,
username: toUsername, username: toUsername,
message: parsed, message: parsed,
@ -135,13 +134,7 @@ SocketModules.chats.send = function(socket, data) {
}; };
SocketModules.chats.list = function(socket, data, callback) { SocketModules.chats.list = function(socket, data, callback) {
Messaging.getRecentChats(socket.uid, function(err, uids) { Messaging.getRecentChats(socket.uid, callback);
if (err) {
winston.warn('[(socket) chats.list] Problem retrieving chats: ' + err.message);
}
callback(uids || []);
});
}; };
/* Notifications */ /* Notifications */
@ -153,11 +146,7 @@ SocketModules.notifications.mark_read = function(socket, nid) {
}; };
SocketModules.notifications.mark_all_read = function(socket, data, callback) { SocketModules.notifications.mark_all_read = function(socket, data, callback) {
notifications.mark_all_read(socket.uid, function(err) { notifications.mark_all_read(socket.uid, callback);
if (!err) {
callback();
}
});
}; };
module.exports = SocketModules; module.exports = SocketModules;

@ -1,17 +1,15 @@
"use strict";
var user = require('../user'), var user = require('../user'),
SocketNotifs = {}; SocketNotifs = {};
SocketNotifs.get = function(socket, data, callback) { SocketNotifs.get = function(socket, data, callback) {
user.notifications.get(socket.uid, function(notifs) { user.notifications.get(socket.uid, callback);
callback(notifs);
});
}; };
SocketNotifs.getCount = function(socket, data, callback) { SocketNotifs.getCount = function(socket, data, callback) {
user.notifications.getUnreadCount(socket.uid, function(err, count) { user.notifications.getUnreadCount(socket.uid, callback);
callback(err ? err.message : null, count);
});
}; };
module.exports = SocketNotifs; module.exports = SocketNotifs;

@ -1016,7 +1016,7 @@ var bcrypt = require('bcrypt'),
notifications.read.length = maxNotifs - notifications.unread.length; notifications.read.length = maxNotifs - notifications.unread.length;
} }
callback(notifications); callback(err, notifications);
}); });
}, },
getAll: function(uid, limit, before, callback) { getAll: function(uid, limit, before, callback) {

Loading…
Cancel
Save