category filter on /unread

v1.18.x
barisusakli 10 years ago
parent 3256faeb28
commit 81eeab42ed

@ -5,5 +5,6 @@
"mark_as_read": "Mark as Read",
"selected": "Selected",
"all": "All",
"all_categories": "All categories",
"topics_marked_as_read.success": "Topics marked as read!"
}

@ -68,8 +68,6 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', '
});
});
socket.emit('categories.getWatchedCategories', onCategoriesLoaded);
topicSelect.init();
if ($("body").height() <= $(window).height() && $('[component="category"]').children().length >= 20) {
@ -86,9 +84,11 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', '
if(direction < 0 || !$('[component="category"]').length) {
return;
}
var params = utils.params();
var cid = params.cid;
infinitescroll.loadMore('topics.loadMoreUnreadTopics', {
after: $('[component="category"]').attr('data-nextstart')
after: $('[component="category"]').attr('data-nextstart'),
cid: cid
}, function(data, done) {
if (data.topics && data.topics.length) {
recent.onTopicsLoaded('unread', data.topics, true, done);
@ -118,31 +118,6 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', '
}
}
function onCategoriesLoaded(err, categories) {
createCategoryLinks(categories);
}
function createCategoryLinks(categories) {
for (var i=0; i<categories.length; ++i) {
if (!categories[i].link) {
createCategoryLink(categories[i]);
}
}
}
function createCategoryLink(category) {
var link = $('<a role="menuitem" href="#"></a>');
if (category.icon) {
link.append('<i class="fa fa-fw ' + category.icon + '"></i> ' + category.name);
} else {
link.append(category.name);
}
$('<li role="presentation" class="category" data-cid="' + category.cid + '"></li>')
.append(link)
.appendTo($('.markread .dropdown-menu'));
}
return Unread;
});

@ -68,28 +68,6 @@ categoriesController.popular = function(req, res, next) {
});
};
categoriesController.unread = function(req, res, next) {
var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
topics.getUnreadTopics(req.uid, 0, stop, function (err, data) {
if (err) {
return next(err);
}
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[unread:title]]'}]);
res.render('unread', data);
});
};
categoriesController.unreadTotal = function(req, res, next) {
topics.getTotalUnread(req.uid, function (err, data) {
if (err) {
return next(err);
}
res.json(data);
});
};
categoriesController.list = function(req, res, next) {
async.parallel({
header: function (next) {

@ -18,6 +18,7 @@ var Controllers = {
posts: require('./posts'),
topics: require('./topics'),
categories: require('./categories'),
unread: require('./unread'),
tags: require('./tags'),
search: require('./search'),
users: require('./users'),

@ -0,0 +1,69 @@
'use strict';
var async = require('async'),
meta = require('../meta'),
categories = require('../categories'),
user = require('../user'),
topics = require('../topics'),
helpers = require('./helpers');
var unreadController = {};
unreadController.unread = function(req, res, next) {
var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
var results;
var cid = req.query.cid;
async.waterfall([
function(next) {
async.parallel({
watchedCategories: function(next) {
user.getWatchedCategories(req.uid, next);
},
unreadTopics: function(next) {
topics.getUnreadTopics(cid, req.uid, 0, stop, next);
}
}, next);
},
function(_results, next) {
results = _results;
categories.getMultipleCategoryFields(results.watchedCategories, ['cid', 'name', 'slug', 'icon', 'link'], next);
},
function(categories, next) {
categories = categories.filter(function(category) {
return category && !category.link;
});
categories.forEach(function(category) {
category.selected = parseInt(category.cid, 10) === parseInt(cid, 10);
if (category.selected) {
results.unreadTopics.selectedCategory = category;
}
});
results.unreadTopics.categories = categories;
next(null, results.unreadTopics);
}
], function(err, data) {
if (err) {
return next(err);
}
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[unread:title]]'}]);
res.render('unread', data);
});
};
unreadController.unreadTotal = function(req, res, next) {
topics.getTotalUnread(req.uid, function (err, data) {
if (err) {
return next(err);
}
res.json(data);
});
};
module.exports = unreadController;

@ -18,6 +18,7 @@ module.exports = function(app, middleware, controllers) {
router.get('/post/:pid', controllers.posts.getPost);
router.get('/categories/:cid/moderators', getModerators);
router.get('/recent/posts/:term?', getRecentPosts);
router.get('/unread/total', middleware.authenticate, controllers.unread.unreadTotal);
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();

@ -49,8 +49,7 @@ function categoryRoutes(app, middleware, controllers) {
setupPageRoute(app, '/categories', middleware, [], controllers.categories.list);
setupPageRoute(app, '/popular/:term?', middleware, [], controllers.categories.popular);
setupPageRoute(app, '/recent', middleware, [], controllers.categories.recent);
setupPageRoute(app, '/unread', middleware, [middleware.authenticate], controllers.categories.unread);
app.get('/api/unread/total', middleware.authenticate, controllers.categories.unreadTotal);
setupPageRoute(app, '/unread', middleware, [middleware.authenticate], controllers.unread.unread);
setupPageRoute(app, '/category/:category_id/:slug/:topic_index', middleware, [], controllers.categories.get);
setupPageRoute(app, '/category/:category_id/:slug?', middleware, [], controllers.categories.get);

@ -140,24 +140,12 @@ SocketTopics.markAllRead = function(socket, data, callback) {
};
SocketTopics.markCategoryTopicsRead = function(socket, cid, callback) {
topics.getUnreadTids(socket.uid, 0, -1, function(err, tids) {
topics.getUnreadTids(cid, socket.uid, 0, -1, function(err, tids) {
if (err) {
return callback(err);
}
topics.getTopicsFields(tids, ['tid', 'cid'], function(err, topicData) {
if (err) {
return callback(err);
}
tids = topicData.filter(function(topic) {
return topic && parseInt(topic.cid, 10) === parseInt(cid, 10);
}).map(function(topic) {
return topic.tid;
});
SocketTopics.markAsRead(socket, tids, callback);
});
SocketTopics.markAsRead(socket, tids, callback);
});
};
@ -501,7 +489,7 @@ SocketTopics.loadMoreUnreadTopics = function(socket, data, callback) {
var start = parseInt(data.after, 10),
stop = start + 9;
topics.getUnreadTopics(socket.uid, start, stop, callback);
topics.getUnreadTopics(data.cid, socket.uid, start, stop, callback);
};
SocketTopics.loadMoreFromSet = function(socket, data, callback) {

@ -12,15 +12,15 @@ var async = require('async'),
module.exports = function(Topics) {
var unreadCutoff = 86400000;
var unreadCutoff = 86400000 * 2;
Topics.getTotalUnread = function(uid, callback) {
Topics.getUnreadTids(uid, 0, 20, function(err, tids) {
Topics.getUnreadTids(0, uid, 0, 20, function(err, tids) {
callback(err, tids ? tids.length : 0);
});
};
Topics.getUnreadTopics = function(uid, start, stop, callback) {
Topics.getUnreadTopics = function(cid, uid, start, stop, callback) {
var unreadTopics = {
showSelect: true,
@ -30,7 +30,7 @@ module.exports = function(Topics) {
async.waterfall([
function(next) {
Topics.getUnreadTids(uid, start, stop, next);
Topics.getUnreadTids(cid, uid, start, stop, next);
},
function(tids, next) {
if (!tids.length) {
@ -50,7 +50,7 @@ module.exports = function(Topics) {
], callback);
};
Topics.getUnreadTids = function(uid, start, stop, callback) {
Topics.getUnreadTids = function(cid, uid, start, stop, callback) {
uid = parseInt(uid, 10);
if (uid === 0) {
return callback(null, []);
@ -91,7 +91,7 @@ module.exports = function(Topics) {
tids = tids.slice(0, 100);
filterTopics(uid, tids, results.ignoredCids, function(err, tids) {
filterTopics(uid, tids, cid, results.ignoredCids, function(err, tids) {
if (err) {
return callback(err);
}
@ -107,7 +107,7 @@ module.exports = function(Topics) {
});
};
function filterTopics(uid, tids, ignoredCids, callback) {
function filterTopics(uid, tids, cid, ignoredCids, callback) {
if (!Array.isArray(ignoredCids) || !tids.length) {
return callback(null, tids);
}
@ -121,7 +121,7 @@ module.exports = function(Topics) {
},
function(topics, next) {
tids = topics.filter(function(topic) {
return topic && topic.cid && ignoredCids.indexOf(topic.cid.toString()) === -1;
return topic && topic.cid && ignoredCids.indexOf(topic.cid.toString()) === -1 && (!cid || parseInt(cid, 10) === parseInt(topic.cid, 10));
}).map(function(topic) {
return topic.tid;
});

Loading…
Cancel
Save