Added client-side support for browsing settings

This commit is contained in:
Marcin Kurczewski 2014-10-22 18:38:04 +02:00
parent 4d7e035383
commit 64743499b6

View file

@ -10,6 +10,7 @@ App.Presenters.PostListPresenter = function(
api, api,
keyboard, keyboard,
pagerPresenter, pagerPresenter,
browsingSettings,
topNavigationPresenter) { topNavigationPresenter) {
var KEY_RETURN = 13; var KEY_RETURN = 13;
@ -105,13 +106,32 @@ App.Presenters.PostListPresenter = function(
function renderPosts($page, posts) { function renderPosts($page, posts) {
var $target = $page.find('.posts'); var $target = $page.find('.posts');
_.each(posts, function(post) { _.each(posts, function(post) {
var $post = renderPost(post); if (!shouldSkipPost(post)) {
softRenderPost($post); var $post = renderPost(post);
$target.append($post); softRenderPost($post);
$target.append($post);
}
}); });
windowResized(); windowResized();
} }
function shouldSkipPost(post) {
var settings = browsingSettings.getSettings();
if (post.ownScore < 0 && settings.hideDownvoted) {
return true;
}
if (settings.listPosts) {
if (post.safety === 'safe' && !settings.listPosts.safe) {
return true;
} else if (post.safety === 'sketchy' && !settings.listPosts.sketchy) {
return true;
} else if (post.safety === 'unsafe' && !settings.listPosts.unsafe) {
return true;
}
}
return false;
}
function renderPost(post) { function renderPost(post) {
var $post = jQuery('<li>' + templates.listItem({ var $post = jQuery('<li>' + templates.listItem({
util: util, util: util,
@ -212,4 +232,4 @@ App.Presenters.PostListPresenter = function(
}; };
App.DI.register('postListPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'api', 'keyboard', 'pagerPresenter', 'topNavigationPresenter'], App.Presenters.PostListPresenter); App.DI.register('postListPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'api', 'keyboard', 'pagerPresenter', 'browsingSettings', 'topNavigationPresenter'], App.Presenters.PostListPresenter);