mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
closes #1936
This commit is contained in:
@@ -5,15 +5,16 @@ var categoriesController = {},
|
|||||||
qs = require('querystring'),
|
qs = require('querystring'),
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
privileges = require('../privileges'),
|
privileges = require('../privileges'),
|
||||||
user = require('./../user'),
|
user = require('../user'),
|
||||||
categories = require('./../categories'),
|
categories = require('../categories'),
|
||||||
topics = require('./../topics'),
|
topics = require('../topics'),
|
||||||
meta = require('./../meta');
|
meta = require('../meta');
|
||||||
|
|
||||||
categoriesController.recent = function(req, res, next) {
|
categoriesController.recent = function(req, res, next) {
|
||||||
var uid = req.user ? req.user.uid : 0;
|
var uid = req.user ? req.user.uid : 0;
|
||||||
topics.getLatestTopics(uid, 0, 19, req.params.term, function (err, data) {
|
var end = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
|
||||||
if(err) {
|
topics.getLatestTopics(uid, 0, end, req.params.term, function (err, data) {
|
||||||
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,8 +29,8 @@ categoriesController.popular = function(req, res, next) {
|
|||||||
|
|
||||||
var term = req.params.term || 'daily';
|
var term = req.params.term || 'daily';
|
||||||
|
|
||||||
topics.getPopular(term, uid, function(err, data) {
|
topics.getPopular(term, uid, meta.config.topicsPerList, function(err, data) {
|
||||||
if(err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,12 +42,12 @@ categoriesController.popular = function(req, res, next) {
|
|||||||
|
|
||||||
categoriesController.unread = function(req, res, next) {
|
categoriesController.unread = function(req, res, next) {
|
||||||
var uid = req.user ? req.user.uid : 0;
|
var uid = req.user ? req.user.uid : 0;
|
||||||
|
var end = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
|
||||||
topics.getUnreadTopics(uid, 0, 20, function (err, data) {
|
topics.getUnreadTopics(uid, 0, end, function (err, data) {
|
||||||
if(err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
data.topics = data.topics.slice(0, parseInt(meta.config.topicsPerList, 10) || 20);
|
||||||
res.render('unread', data);
|
res.render('unread', data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,13 +3,14 @@
|
|||||||
var tagsController = {},
|
var tagsController = {},
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
topics = require('./../topics');
|
meta = require('../meta'),
|
||||||
|
topics = require('../topics');
|
||||||
|
|
||||||
tagsController.getTag = function(req, res, next) {
|
tagsController.getTag = function(req, res, next) {
|
||||||
var tag = req.params.tag;
|
var tag = req.params.tag;
|
||||||
var uid = req.user ? req.user.uid : 0;
|
var uid = req.user ? req.user.uid : 0;
|
||||||
|
var end = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
|
||||||
topics.getTagTids(tag, 0, 19, function(err, tids) {
|
topics.getTagTids(tag, 0, end, function(err, tids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,8 +54,16 @@ var winston = require('winston'),
|
|||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
options.tags = options.tags || [];
|
options.tags = options.tags || [];
|
||||||
if (isMainPost) {
|
|
||||||
|
if (!isMainPost) {
|
||||||
|
return next(null, {
|
||||||
|
tid: tid,
|
||||||
|
isMainPost: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
title = title.trim();
|
title = title.trim();
|
||||||
|
|
||||||
var topicData = {
|
var topicData = {
|
||||||
@@ -70,17 +78,20 @@ var winston = require('winston'),
|
|||||||
plugins.fireHook('action:topic.edit', tid);
|
plugins.fireHook('action:topic.edit', tid);
|
||||||
});
|
});
|
||||||
|
|
||||||
topics.updateTags(tid, options.tags);
|
topics.updateTags(tid, options.tags, function(err) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
}
|
}
|
||||||
|
topics.getTopicTagsObjects(tid, function(err, tags) {
|
||||||
next(null, {
|
next(err, {
|
||||||
tid: tid,
|
tid: tid,
|
||||||
title: validator.escape(title),
|
title: validator.escape(title),
|
||||||
isMainPost: isMainPost,
|
isMainPost: isMainPost,
|
||||||
tags: options.tags.map(function(tag) { return {name:tag}; })
|
tags: tags
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
content: function(next) {
|
content: function(next) {
|
||||||
PostTools.parse(postData.content, next);
|
PostTools.parse(postData.content, next);
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ var async = require('async'),
|
|||||||
|
|
||||||
module.exports = function(Topics) {
|
module.exports = function(Topics) {
|
||||||
|
|
||||||
Topics.getPopular = function(term, uid, callback) {
|
Topics.getPopular = function(term, uid, count, callback) {
|
||||||
|
count = parseInt(count, 10) || 20;
|
||||||
var terms = {
|
var terms = {
|
||||||
daily: 'day',
|
daily: 'day',
|
||||||
weekly: 'week',
|
weekly: 'week',
|
||||||
@@ -17,7 +18,7 @@ module.exports = function(Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (term === 'alltime') {
|
if (term === 'alltime') {
|
||||||
return getAllTimePopular(uid, callback);
|
return getAllTimePopular(uid, count, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
var since = terms[term] || 'day';
|
var since = terms[term] || 'day';
|
||||||
@@ -27,7 +28,7 @@ module.exports = function(Topics) {
|
|||||||
Topics.getLatestTids(0, -1, since, next);
|
Topics.getLatestTids(0, -1, since, next);
|
||||||
},
|
},
|
||||||
function(tids, next) {
|
function(tids, next) {
|
||||||
getTopics(tids, uid, next);
|
getTopics(tids, uid, count, next);
|
||||||
},
|
},
|
||||||
function(topics, next) {
|
function(topics, next) {
|
||||||
var tids = topics.map(function(topic) {
|
var tids = topics.map(function(topic) {
|
||||||
@@ -49,13 +50,13 @@ module.exports = function(Topics) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getAllTimePopular(uid, callback) {
|
function getAllTimePopular(uid, count, callback) {
|
||||||
Topics.getTopicsFromSet(uid, 'topics:posts', 0, 19, function(err, data) {
|
Topics.getTopicsFromSet(uid, 'topics:posts', 0, count - 1, function(err, data) {
|
||||||
callback(err, data ? data.topics : null);
|
callback(err, data ? data.topics : null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTopics(tids, uid, callback) {
|
function getTopics(tids, uid, count, callback) {
|
||||||
var keys = tids.map(function(tid) {
|
var keys = tids.map(function(tid) {
|
||||||
return 'topic:' + tid;
|
return 'topic:' + tid;
|
||||||
});
|
});
|
||||||
@@ -69,7 +70,7 @@ module.exports = function(Topics) {
|
|||||||
return parseInt(b.postcount, 10) - parseInt(a.postcount, 10);
|
return parseInt(b.postcount, 10) - parseInt(a.postcount, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
topics = topics.slice(0, 20).map(function(topic) {
|
topics = topics.slice(0, count).map(function(topic) {
|
||||||
return topic.tid;
|
return topic.tid;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -132,16 +132,19 @@ module.exports = function(Topics) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.updateTags = function(tid, tags) {
|
Topics.updateTags = function(tid, tags, callback) {
|
||||||
|
callback = callback || function() {};
|
||||||
Topics.getTopicField(tid, 'timestamp', function(err, timestamp) {
|
Topics.getTopicField(tid, 'timestamp', function(err, timestamp) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return winston.error(err.message);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.deleteTopicTags(tid, function(err) {
|
Topics.deleteTopicTags(tid, function(err) {
|
||||||
if (!err) {
|
if (err) {
|
||||||
Topics.createTags(tags, tid, timestamp);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Topics.createTags(tags, tid, timestamp, callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
|
|
||||||
db = require('./../database'),
|
db = require('../database'),
|
||||||
user = require('./../user'),
|
user = require('../user'),
|
||||||
notifications = require('./../notifications'),
|
meta = require('../meta'),
|
||||||
categories = require('./../categories'),
|
notifications = require('../notifications'),
|
||||||
|
categories = require('../categories'),
|
||||||
privileges = require('../privileges');
|
privileges = require('../privileges');
|
||||||
|
|
||||||
module.exports = function(Topics) {
|
module.exports = function(Topics) {
|
||||||
@@ -27,8 +28,14 @@ module.exports = function(Topics) {
|
|||||||
return callback(null, unreadTids);
|
return callback(null, unreadTids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
if (stop === -1) {
|
||||||
|
count = Infinity;
|
||||||
|
} else {
|
||||||
|
count = stop - start + 1;
|
||||||
|
}
|
||||||
async.whilst(function() {
|
async.whilst(function() {
|
||||||
return unreadTids.length < 21 && !done;
|
return unreadTids.length < count && !done;
|
||||||
}, function(next) {
|
}, function(next) {
|
||||||
Topics.getLatestTids(start, stop, 'month', function(err, tids) {
|
Topics.getLatestTids(start, stop, 'month', function(err, tids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -49,6 +56,10 @@ module.exports = function(Topics) {
|
|||||||
return !read[index];
|
return !read[index];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
privileges.topics.filter('read', newtids, uid, function(err, newtids) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
unreadTids.push.apply(unreadTids, newtids);
|
unreadTids.push.apply(unreadTids, newtids);
|
||||||
|
|
||||||
start = stop + 1;
|
start = stop + 1;
|
||||||
@@ -57,11 +68,9 @@ module.exports = function(Topics) {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err) {
|
callback(err, unreadTids.slice(0, count));
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
privileges.topics.filter('read', unreadTids, uid, callback);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -162,7 +171,6 @@ module.exports = function(Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.markAsRead = function(tid, uid, callback) {
|
Topics.markAsRead = function(tid, uid, callback) {
|
||||||
|
|
||||||
db.setAdd('tid:' + tid + ':read_by_uid', uid, function(err) {
|
db.setAdd('tid:' + tid + ':read_by_uid', uid, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user