Skip to content

Node.js based forum software built for the modern web

check if user exists

barisusakli5cf983dceecd
diff --git a/src/messaging.js b/src/messaging.js
index f438f3a23c..415ab5a12c 100644
--- a/src/messaging.js
+++ b/src/messaging.js
@@ -320,7 +320,17 @@ var db = require('./database'),
};
Messaging.markUnread = function(uid, toUid, callback) {
- db.sortedSetAdd('uid:' + uid + ':chats:unread', Date.now(), toUid, callback);
+ async.waterfall([
+ function (next) {
+ user.exists(toUid, next);
+ },
+ function (exists, next) {
+ if (!exists) {
+ return next(new Error('[[error:no-user]]'));
+ }
+ db.sortedSetAdd('uid:' + uid + ':chats:unread', Date.now(), toUid, next);
+ }
+ ], callback);
};
Messaging.notifyUser = function(fromuid, touid, messageObj) {
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index 9ceecf1cb8..b0dde46c5c 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -71,9 +71,12 @@ SocketModules.chats.canMessage = function(socket, toUid, callback) {
SocketModules.chats.markRead = function(socket, touid, callback) {
Messaging.markRead(socket.uid, touid, function(err) {
- if (!err) {
- Messaging.pushUnreadCount(socket.uid);
+ if (err) {
+ return callback(err);
}
+
+ Messaging.pushUnreadCount(socket.uid);
+ callback();
});
};