removed recent/day week month

it starts with most recent 20 topics now and goes back instead of
showing empty if there are no new replies in the past 24 hours
v1.18.x
barisusakli 10 years ago
parent c4a39c8163
commit c74370bfb1

@ -8,15 +8,6 @@ define('forum/recent', ['forum/infinitescroll'], function(infinitescroll) {
var newTopicCount = 0, var newTopicCount = 0,
newPostCount = 0; newPostCount = 0;
var active = '';
function getActiveSection() {
var url = window.location.href,
parts = url.split('/'),
active = parts[parts.length - 1];
return active;
}
$(window).on('action:ajaxify.start', function(ev, data) { $(window).on('action:ajaxify.start', function(ev, data) {
if(data.url.indexOf('recent') !== 0) { if(data.url.indexOf('recent') !== 0) {
Recent.removeListeners(); Recent.removeListeners();
@ -28,31 +19,13 @@ define('forum/recent', ['forum/infinitescroll'], function(infinitescroll) {
Recent.watchForNewPosts(); Recent.watchForNewPosts();
active = Recent.selectActivePill();
$('#new-topics-alert').on('click', function() { $('#new-topics-alert').on('click', function() {
$(this).addClass('hide'); $(this).addClass('hide');
}); });
infinitescroll.init(Recent.loadMoreTopics); infinitescroll.init(Recent.loadMoreTopics);
}; };
Recent.selectActivePill = function() {
var active = getActiveSection();
$('.nav-pills li').removeClass('active');
$('.nav-pills li a').each(function() {
var $this = $(this);
if ($this.attr('href').match(active)) {
$this.parent().addClass('active');
return false;
}
});
return active;
};
Recent.watchForNewPosts = function () { Recent.watchForNewPosts = function () {
newPostCount = 0; newPostCount = 0;
newTopicCount = 0; newTopicCount = 0;
@ -103,8 +76,7 @@ define('forum/recent', ['forum/infinitescroll'], function(infinitescroll) {
} }
infinitescroll.loadMore('topics.loadMoreRecentTopics', { infinitescroll.loadMore('topics.loadMoreRecentTopics', {
after: $('#topics-container').attr('data-nextstart'), after: $('#topics-container').attr('data-nextstart')
term: active
}, function(data, done) { }, function(data, done) {
if (data.topics && data.topics.length) { if (data.topics && data.topics.length) {
Recent.onTopicsLoaded('recent', data.topics, false, done); Recent.onTopicsLoaded('recent', data.topics, false, done);

@ -19,7 +19,7 @@ var apiToRegular = function(url) {
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;
var end = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; var end = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
topics.getLatestTopics(uid, 0, end, req.params.term, function (err, data) { topics.getRecentTopics(uid, 0, end, function (err, data) {
if (err) { if (err) {
return next(err); return next(err);
} }
@ -27,6 +27,9 @@ categoriesController.recent = function(req, res, next) {
data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
plugins.fireHook('filter:category.get', data, uid, function(err, data) { plugins.fireHook('filter:category.get', data, uid, function(err, data) {
if (err) {
return next(err);
}
res.render('recent', data); res.render('recent', data);
}); });
}); });
@ -53,6 +56,9 @@ categoriesController.popular = function(req, res, next) {
data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
plugins.fireHook('filter:category.get', {topics: data}, uid, function(err, data) { plugins.fireHook('filter:category.get', {topics: data}, uid, function(err, data) {
if (err) {
return next(err);
}
if (uid === 0) { if (uid === 0) {
anonCache[term] = data; anonCache[term] = data;
lastUpdateTime = Date.now(); lastUpdateTime = Date.now();
@ -72,6 +78,9 @@ categoriesController.unread = function(req, res, next) {
} }
plugins.fireHook('filter:category.get', data, uid, function(err, data) { plugins.fireHook('filter:category.get', data, uid, function(err, data) {
if (err) {
return next(err);
}
res.render('unread', data); res.render('unread', data);
}); });
}); });
@ -236,10 +245,10 @@ categoriesController.notFound = function(req, res) {
categoriesController.notAllowed = function(req, res) { categoriesController.notAllowed = function(req, res) {
var uid = req.user ? req.user.uid : 0; var uid = req.user ? req.user.uid : 0;
if (uid) { if (uid) {
if (res.locals.isAPI) { if (res.locals.isAPI) {
res.status(403).json('not-allowed'); res.status(403).json('not-allowed');
} else { } else {
res.status(403).render('403'); res.status(403).render('403');
} }

@ -50,7 +50,7 @@ function tagRoutes(app, middleware, controllers) {
function categoryRoutes(app, middleware, controllers) { function categoryRoutes(app, middleware, controllers) {
setupPageRoute(app, '/popular/:term?', middleware, [], controllers.categories.popular); setupPageRoute(app, '/popular/:term?', middleware, [], controllers.categories.popular);
setupPageRoute(app, '/recent/:term?', middleware, [], controllers.categories.recent); setupPageRoute(app, '/recent', middleware, [], controllers.categories.recent);
setupPageRoute(app, '/unread', middleware, [middleware.authenticate], controllers.categories.unread); setupPageRoute(app, '/unread', middleware, [middleware.authenticate], controllers.categories.unread);
app.get('/api/unread/total', middleware.authenticate, controllers.categories.unreadTotal); app.get('/api/unread/total', middleware.authenticate, controllers.categories.unreadTotal);

@ -459,14 +459,14 @@ SocketTopics.loadMore = function(socket, data, callback) {
}; };
SocketTopics.loadMoreRecentTopics = function(socket, data, callback) { SocketTopics.loadMoreRecentTopics = function(socket, data, callback) {
if(!data || !data.term || !data.after) { if(!data || !data.after) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
var start = parseInt(data.after, 10), var start = parseInt(data.after, 10),
end = start + 9; end = start + 9;
topics.getLatestTopics(socket.uid, start, end, data.term, callback); topics.getRecentTopics(socket.uid, start, end, callback);
}; };
SocketTopics.loadMoreUnreadTopics = function(socket, data, callback) { SocketTopics.loadMoreUnreadTopics = function(socket, data, callback) {

@ -15,6 +15,21 @@ module.exports = function(Topics) {
year: 31104000000 year: 31104000000
}; };
Topics.getRecentTopics = function(uid, start, end, callback) {
async.waterfall([
function(next) {
db.getSortedSetRevRange('topics:recent', start, end, next);
},
function(tids, next) {
Topics.getTopics('topics:recent', uid, tids, next);
},
function(data, next) {
data.nextStart = end + 1;
next(null, data);
}
], callback);
};
Topics.getLatestTopics = function(uid, start, end, term, callback) { Topics.getLatestTopics = function(uid, start, end, term, callback) {
Topics.getLatestTids(start, end, term, function(err, tids) { Topics.getLatestTids(start, end, term, function(err, tids) {
if (err) { if (err) {

Loading…
Cancel
Save