v1.18.x
barisusakli 11 years ago
parent d852f284da
commit 522fda2e58

@ -5,14 +5,15 @@ var categoriesController = {},
qs = require('querystring'),
nconf = require('nconf'),
privileges = require('../privileges'),
user = require('./../user'),
categories = require('./../categories'),
topics = require('./../topics'),
meta = require('./../meta');
user = require('../user'),
categories = require('../categories'),
topics = require('../topics'),
meta = require('../meta');
categoriesController.recent = function(req, res, next) {
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;
topics.getLatestTopics(uid, 0, end, req.params.term, function (err, data) {
if (err) {
return next(err);
}
@ -28,7 +29,7 @@ categoriesController.popular = function(req, res, next) {
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) {
return next(err);
}
@ -41,12 +42,12 @@ categoriesController.popular = function(req, res, next) {
categoriesController.unread = function(req, res, next) {
var uid = req.user ? req.user.uid : 0;
topics.getUnreadTopics(uid, 0, 20, function (err, data) {
var end = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
topics.getUnreadTopics(uid, 0, end, function (err, data) {
if (err) {
return next(err);
}
data.topics = data.topics.slice(0, parseInt(meta.config.topicsPerList, 10) || 20);
res.render('unread', data);
});
};

@ -3,13 +3,14 @@
var tagsController = {},
async = require('async'),
nconf = require('nconf'),
topics = require('./../topics');
meta = require('../meta'),
topics = require('../topics');
tagsController.getTag = function(req, res, next) {
var tag = req.params.tag;
var uid = req.user ? req.user.uid : 0;
topics.getTagTids(tag, 0, 19, function(err, tids) {
var end = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
topics.getTagTids(tag, 0, end, function(err, tids) {
if (err) {
return next(err);
}

@ -54,8 +54,16 @@ var winston = require('winston'),
if (err) {
return next(err);
}
options.tags = options.tags || [];
if (isMainPost) {
if (!isMainPost) {
return next(null, {
tid: tid,
isMainPost: false
});
}
title = title.trim();
var topicData = {
@ -70,17 +78,20 @@ var winston = require('winston'),
plugins.fireHook('action:topic.edit', tid);
});
topics.updateTags(tid, options.tags);
topics.updateTags(tid, options.tags, function(err) {
if (err) {
return next(err);
}
next(null, {
topics.getTopicTagsObjects(tid, function(err, tags) {
next(err, {
tid: tid,
title: validator.escape(title),
isMainPost: isMainPost,
tags: options.tags.map(function(tag) { return {name:tag}; })
tags: tags
});
});
});
});
},
content: function(next) {
PostTools.parse(postData.content, next);

@ -8,7 +8,8 @@ var async = require('async'),
module.exports = function(Topics) {
Topics.getPopular = function(term, uid, callback) {
Topics.getPopular = function(term, uid, count, callback) {
count = parseInt(count, 10) || 20;
var terms = {
daily: 'day',
weekly: 'week',
@ -17,7 +18,7 @@ module.exports = function(Topics) {
};
if (term === 'alltime') {
return getAllTimePopular(uid, callback);
return getAllTimePopular(uid, count, callback);
}
var since = terms[term] || 'day';
@ -27,7 +28,7 @@ module.exports = function(Topics) {
Topics.getLatestTids(0, -1, since, next);
},
function(tids, next) {
getTopics(tids, uid, next);
getTopics(tids, uid, count, next);
},
function(topics, next) {
var tids = topics.map(function(topic) {
@ -49,13 +50,13 @@ module.exports = function(Topics) {
], callback);
};
function getAllTimePopular(uid, callback) {
Topics.getTopicsFromSet(uid, 'topics:posts', 0, 19, function(err, data) {
function getAllTimePopular(uid, count, callback) {
Topics.getTopicsFromSet(uid, 'topics:posts', 0, count - 1, function(err, data) {
callback(err, data ? data.topics : null);
});
}
function getTopics(tids, uid, callback) {
function getTopics(tids, uid, count, callback) {
var keys = tids.map(function(tid) {
return 'topic:' + tid;
});
@ -69,7 +70,7 @@ module.exports = function(Topics) {
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;
});

@ -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) {
if (err) {
return winston.error(err.message);
return callback(err);
}
Topics.deleteTopicTags(tid, function(err) {
if (!err) {
Topics.createTags(tags, tid, timestamp);
if (err) {
return callback(err);
}
Topics.createTags(tags, tid, timestamp, callback);
});
});
};

@ -4,10 +4,11 @@
var async = require('async'),
winston = require('winston'),
db = require('./../database'),
user = require('./../user'),
notifications = require('./../notifications'),
categories = require('./../categories'),
db = require('../database'),
user = require('../user'),
meta = require('../meta'),
notifications = require('../notifications'),
categories = require('../categories'),
privileges = require('../privileges');
module.exports = function(Topics) {
@ -27,8 +28,14 @@ module.exports = function(Topics) {
return callback(null, unreadTids);
}
var count = 0;
if (stop === -1) {
count = Infinity;
} else {
count = stop - start + 1;
}
async.whilst(function() {
return unreadTids.length < 21 && !done;
return unreadTids.length < count && !done;
}, function(next) {
Topics.getLatestTids(start, stop, 'month', function(err, tids) {
if (err) {
@ -49,6 +56,10 @@ module.exports = function(Topics) {
return !read[index];
});
privileges.topics.filter('read', newtids, uid, function(err, newtids) {
if (err) {
return next(err);
}
unreadTids.push.apply(unreadTids, newtids);
start = stop + 1;
@ -57,11 +68,9 @@ module.exports = function(Topics) {
next();
});
});
});
}, function(err) {
if (err) {
return callback(err);
}
privileges.topics.filter('read', unreadTids, uid, callback);
callback(err, unreadTids.slice(0, count));
});
};
@ -162,7 +171,6 @@ module.exports = function(Topics) {
};
Topics.markAsRead = function(tid, uid, callback) {
db.setAdd('tid:' + tid + ':read_by_uid', uid, function(err) {
if (err) {
return callback(err);

Loading…
Cancel
Save