mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-14 16:40:52 +01:00
Merge branch 'master' of https://github.com/designcreateplay/NodeBB
This commit is contained in:
@@ -171,8 +171,14 @@ var db = require('./database'),
|
||||
|
||||
Categories.isTopicsRead = function(cid, uid, callback) {
|
||||
db.getSortedSetRange('categories:' + cid + ':tid', 0, -1, function(err, tids) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
topics.hasReadTopics(tids, uid, function(hasRead) {
|
||||
topics.hasReadTopics(tids, uid, function(err, hasRead) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var allread = true;
|
||||
for (var i = 0, ii = tids.length; i < ii; i++) {
|
||||
@@ -271,8 +277,6 @@ var db = require('./database'),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
Categories.getCategoryData = function(cid, callback) {
|
||||
db.exists('category:' + cid, function(err, exists) {
|
||||
if (exists) {
|
||||
|
||||
@@ -424,10 +424,23 @@
|
||||
// sets
|
||||
|
||||
module.setAdd = function(key, value, callback) {
|
||||
if(value !== null && value !== undefined) {
|
||||
value = value.toString();
|
||||
if(!Array.isArray(value)) {
|
||||
value = [value];
|
||||
}
|
||||
db.collection('objects').update({_key:key}, {$addToSet: { members: value }}, {upsert:true, w: 1}, function(err, result) {
|
||||
|
||||
value.forEach(function(element, index, array) {
|
||||
array[index] = element ? element.toString() : element;
|
||||
});
|
||||
|
||||
|
||||
db.collection('objects').update({_key:key},
|
||||
{
|
||||
$addToSet: { members: { $each: value } }
|
||||
},
|
||||
{
|
||||
upsert:true, w: 1
|
||||
}
|
||||
, function(err, result) {
|
||||
if(typeof callback === 'function') {
|
||||
callback(err, result);
|
||||
}
|
||||
@@ -435,10 +448,15 @@
|
||||
}
|
||||
|
||||
module.setRemove = function(key, value, callback) {
|
||||
if(value !== null && value !== undefined) {
|
||||
value = value.toString();
|
||||
if(!Array.isArray(value)) {
|
||||
value = [value];
|
||||
}
|
||||
db.collection('objects').update({_key:key, members: value}, {$pull : {members: value}}, function(err, result) {
|
||||
|
||||
value.forEach(function(element, index, array) {
|
||||
array[index] = element ? element.toString() : element;
|
||||
});
|
||||
|
||||
db.collection('objects').update( { _key: key }, { $pullAll: { members: value } }, function(err, result) {
|
||||
if(typeof callback === 'function') {
|
||||
callback(err, result);
|
||||
}
|
||||
@@ -456,17 +474,26 @@
|
||||
}
|
||||
|
||||
module.isMemberOfSets = function(sets, value, callback) {
|
||||
function iterator(set, next) {
|
||||
module.isSetMember(set, value, function(err, result) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
next(null, result?1:0);
|
||||
});
|
||||
if(value !== null && value !== undefined) {
|
||||
value = value.toString();
|
||||
}
|
||||
|
||||
async.map(sets, iterator, callback);
|
||||
db.collection('objects').find({_key: {$in : sets}, members: value}).toArray(function(err, result) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
result = result.map(function(item) {
|
||||
return item._key;
|
||||
});
|
||||
|
||||
result = sets.map(function(set) {
|
||||
return result.indexOf(set) !== -1 ? 1 : 0;
|
||||
});
|
||||
|
||||
callback(err, result);
|
||||
});
|
||||
}
|
||||
|
||||
module.getSetMembers = function(key, callback) {
|
||||
@@ -655,16 +682,18 @@
|
||||
if(value !== null && value !== undefined) {
|
||||
value = value.toString();
|
||||
}
|
||||
module.getSortedSetRange(key, 0, -1, function(err, result) {
|
||||
module.getSortedSetRevRange(key, 0, -1, function(err, result) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var rank = result.indexOf(value);
|
||||
|
||||
if(rank === -1) {
|
||||
return callback(null, null);
|
||||
}
|
||||
|
||||
callback(null, result.length - rank - 1);
|
||||
callback(null, rank);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
13
src/meta.js
13
src/meta.js
@@ -243,7 +243,7 @@ var fs = require('fs'),
|
||||
minFile: path.join(__dirname, '..', 'public/src/nodebb.min.js'),
|
||||
get: function (callback) {
|
||||
plugins.fireHook('filter:scripts.get', this.scripts, function(err, scripts) {
|
||||
var mtime,
|
||||
var ctime,
|
||||
jsPaths = scripts.map(function (jsPath) {
|
||||
jsPath = path.normalize(jsPath);
|
||||
|
||||
@@ -267,12 +267,12 @@ var fs = require('fs'),
|
||||
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
async.parallel({
|
||||
mtime: function (next) {
|
||||
ctime: function (next) {
|
||||
async.map(jsPaths, fs.stat, function (err, stats) {
|
||||
async.reduce(stats, 0, function (memo, item, next) {
|
||||
if(item) {
|
||||
mtime = +new Date(item.mtime);
|
||||
next(null, mtime > memo ? mtime : memo);
|
||||
ctime = +new Date(item.ctime);
|
||||
next(null, ctime > memo ? ctime : memo);
|
||||
} else {
|
||||
next(null, memo);
|
||||
}
|
||||
@@ -286,14 +286,15 @@ var fs = require('fs'),
|
||||
}
|
||||
|
||||
fs.stat(Meta.js.minFile, function (err, stat) {
|
||||
next(err, +new Date(stat.mtime));
|
||||
next(err, +new Date(stat.ctime));
|
||||
});
|
||||
}
|
||||
}, function (err, results) {
|
||||
if (results.minFile > results.mtime) {
|
||||
if (results.minFile > results.ctime) {
|
||||
winston.info('No changes to client-side libraries -- skipping minification');
|
||||
callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]);
|
||||
} else {
|
||||
winston.info('Minifying client-side libraries -- please wait');
|
||||
Meta.js.minify(function () {
|
||||
callback(null, [
|
||||
path.relative(path.join(__dirname, '../public'), Meta.js.minFile)
|
||||
|
||||
@@ -71,7 +71,7 @@ var fs = require('fs'),
|
||||
plugins.push(meta.config['theme:id']);
|
||||
|
||||
async.each(plugins, function(plugin, next) {
|
||||
if (!plugin) {
|
||||
if (!plugin || typeof plugin !== 'string') {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ var fs = require('fs'),
|
||||
}).filter(function(file) {
|
||||
var stats = fs.statSync(file),
|
||||
isPlugin = file.substr(npmPluginPath.length + 1, 14) === 'nodebb-plugin-' || file.substr(npmPluginPath.length + 1, 14) === 'nodebb-widget-';
|
||||
|
||||
|
||||
if (stats.isDirectory() && isPlugin) return true;
|
||||
else return false;
|
||||
});
|
||||
|
||||
@@ -518,8 +518,10 @@ var async = require('async'),
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
Topics.hasReadTopics(tids, uid, function(read) {
|
||||
|
||||
Topics.hasReadTopics(tids, uid, function(err, read) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
var newtids = tids.filter(function(tid, index, self) {
|
||||
return read[index] === 0;
|
||||
});
|
||||
@@ -563,8 +565,10 @@ var async = require('async'),
|
||||
unreadTids.push.apply(unreadTids, tids);
|
||||
callback(null);
|
||||
} else {
|
||||
Topics.hasReadTopics(tids, uid, function(read) {
|
||||
|
||||
Topics.hasReadTopics(tids, uid, function(err, read) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
var newtids = tids.filter(function(tid, index, self) {
|
||||
return parseInt(read[index], 10) === 0;
|
||||
});
|
||||
@@ -572,11 +576,7 @@ var async = require('async'),
|
||||
|
||||
async.filter(newtids, function(tid, next) {
|
||||
threadTools.privileges(tid, uid, function(err, privileges) {
|
||||
if (!err && privileges.read) {
|
||||
next(true);
|
||||
} else {
|
||||
next(false);
|
||||
}
|
||||
next(!err && privileges.read);
|
||||
});
|
||||
}, function(newtids) {
|
||||
unreadTids.push.apply(unreadTids, newtids);
|
||||
@@ -692,9 +692,7 @@ var async = require('async'),
|
||||
}
|
||||
|
||||
function hasReadTopic(next) {
|
||||
Topics.hasReadTopic(topicData.tid, current_user, function(hasRead) {
|
||||
next(null, hasRead);
|
||||
});
|
||||
Topics.hasReadTopic(topicData.tid, current_user, next);
|
||||
}
|
||||
|
||||
function getTeaserInfo(next) {
|
||||
@@ -870,9 +868,7 @@ var async = require('async'),
|
||||
|
||||
function getReadStatus(next) {
|
||||
if (uid && parseInt(uid, 10) > 0) {
|
||||
Topics.hasReadTopic(tid, uid, function(read) {
|
||||
next(null, read);
|
||||
});
|
||||
Topics.hasReadTopic(tid, uid, next);
|
||||
} else {
|
||||
next(null, null);
|
||||
}
|
||||
@@ -989,7 +985,7 @@ var async = require('async'),
|
||||
|
||||
Topics.hasReadTopics = function(tids, uid, callback) {
|
||||
if(!parseInt(uid, 10)) {
|
||||
return callback(tids.map(function() {
|
||||
return callback(null, tids.map(function() {
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
@@ -1000,25 +996,15 @@ var async = require('async'),
|
||||
sets.push('tid:' + tids[i] + ':read_by_uid');
|
||||
}
|
||||
|
||||
db.isMemberOfSets(sets, uid, function(err, hasRead) {
|
||||
callback(hasRead);
|
||||
});
|
||||
db.isMemberOfSets(sets, uid, callback);
|
||||
};
|
||||
|
||||
Topics.hasReadTopic = function(tid, uid, callback) {
|
||||
if(!parseInt(uid, 10)) {
|
||||
return callback(false);
|
||||
return callback(null, false);
|
||||
}
|
||||
|
||||
db.isSetMember('tid:' + tid + ':read_by_uid', uid, function(err, hasRead) {
|
||||
|
||||
if (err === null) {
|
||||
callback(hasRead);
|
||||
} else {
|
||||
console.log(err);
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
db.isSetMember('tid:' + tid + ':read_by_uid', uid, callback);
|
||||
};
|
||||
|
||||
Topics.getTeasers = function(tids, callback) {
|
||||
|
||||
@@ -1136,8 +1136,9 @@ var bcrypt = require('bcryptjs'),
|
||||
async.filter(nids, function(nid, next) {
|
||||
notifications.get(nid, uid, function(notifObj) {
|
||||
if(!notifObj) {
|
||||
next(false);
|
||||
return next(false);
|
||||
}
|
||||
|
||||
if (notifObj.uniqueId === uniqueId) {
|
||||
next(true);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user