mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-31 19:15:58 +01:00
closes #1483
This commit is contained in:
@@ -115,17 +115,21 @@ var async = require('async'),
|
|||||||
|
|
||||||
Notifications.get(nid, null, function(notif_data) {
|
Notifications.get(nid, null, function(notif_data) {
|
||||||
async.each(uids, function(uid, next) {
|
async.each(uids, function(uid, next) {
|
||||||
if (parseInt(uid, 10) > 0) {
|
if (!parseInt(uid, 10)) {
|
||||||
checkReplace(notif_data.uniqueId, uid, notif_data, function(err, replace) {
|
next();
|
||||||
if (replace) {
|
}
|
||||||
db.sortedSetAdd('uid:' + uid + ':notifications:unread', notif_data.datetime, nid);
|
|
||||||
websockets.in('uid_' + uid).emit('event:new_notification', notif_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback) {
|
checkReplace(notif_data.uniqueId, uid, notif_data, function(err, replace) {
|
||||||
callback(true);
|
if (replace) {
|
||||||
}
|
db.sortedSetAdd('uid:' + uid + ':notifications:unread', notif_data.datetime, nid);
|
||||||
});
|
websockets.in('uid_' + uid).emit('event:new_notification', notif_data);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
}, function(err) {
|
||||||
|
if (callback) {
|
||||||
|
callback(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,10 +39,10 @@ User.banUsers = function(socket, uids, callback) {
|
|||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async.each(uids, banUser, callback);
|
async.each(uids, User.banUser, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function banUser(uid, callback) {
|
User.banUser = function(uid, callback) {
|
||||||
user.isAdministrator(uid, function(err, isAdmin) {
|
user.isAdministrator(uid, function(err, isAdmin) {
|
||||||
if (err || isAdmin) {
|
if (err || isAdmin) {
|
||||||
return callback(err || new Error('[[error:cant-ban-other-admins]]'));
|
return callback(err || new Error('[[error:cant-ban-other-admins]]'));
|
||||||
@@ -63,7 +63,7 @@ function banUser(uid, callback) {
|
|||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
User.unbanUsers = function(socket, uids, callback) {
|
User.unbanUsers = function(socket, uids, callback) {
|
||||||
if(!Array.isArray(uids)) {
|
if(!Array.isArray(uids)) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
|
|
||||||
|
db = require('../database'),
|
||||||
posts = require('../posts'),
|
posts = require('../posts'),
|
||||||
meta = require('../meta'),
|
meta = require('../meta'),
|
||||||
topics = require('../topics'),
|
topics = require('../topics'),
|
||||||
@@ -262,7 +263,8 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var message = '',
|
var message = '',
|
||||||
path = '';
|
path = '',
|
||||||
|
post;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
@@ -270,10 +272,11 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
},
|
},
|
||||||
function(username, next) {
|
function(username, next) {
|
||||||
message = '[[notifications:user_flagged_post, ' + username + ']]';
|
message = '[[notifications:user_flagged_post, ' + username + ']]';
|
||||||
posts.getPostField(pid, 'tid', next);
|
posts.getPostFields(pid, ['tid', 'uid'], next);
|
||||||
},
|
},
|
||||||
function(tid, next) {
|
function(postData, next) {
|
||||||
topics.getTopicField(tid, 'slug', next);
|
post = postData;
|
||||||
|
topics.getTopicField(postData.tid, 'slug', next);
|
||||||
},
|
},
|
||||||
function(topicSlug, next) {
|
function(topicSlug, next) {
|
||||||
path = nconf.get('relative_path') + '/topic/' + topicSlug + '#' + pid;
|
path = nconf.get('relative_path') + '/topic/' + topicSlug + '#' + pid;
|
||||||
@@ -287,7 +290,30 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
from: socket.uid
|
from: socket.uid
|
||||||
}, function(nid) {
|
}, function(nid) {
|
||||||
notifications.push(nid, adminGroup.members, function() {
|
notifications.push(nid, adminGroup.members, function() {
|
||||||
next(null);
|
next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
if (!parseInt(post.uid, 10)) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
db.setAdd('uid:' + post.uid + ':flagged_by', socket.uid, function(err) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
db.setCount('uid:' + post.uid + ':flagged_by', function(err, count) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count >= (meta.config.flagsForBan || 3)) {
|
||||||
|
var adminUser = require('./admin/user');
|
||||||
|
adminUser.banUser(post.uid, next);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ module.exports = function(User) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
User.unban = function(uid, callback) {
|
User.unban = function(uid, callback) {
|
||||||
|
db.delete('uid:' + uid + ':flagged_by');
|
||||||
User.setUserField(uid, 'banned', 0, callback);
|
User.setUserField(uid, 'banned', 0, callback);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user