diff options
| author | rr- | 2017-03-30 20:50:12 +0200 |
|---|---|---|
| committer | rr- | 2017-03-30 20:50:12 +0200 |
| commit | 77bf3bdc3c0c1b9e5746e0f3f63281360c3e5a03 (patch) | |
| tree | bd2a8cdf7cb5d2b099191d3ef68648bebdd70c35 /client/js/models/post_list.js | |
| parent | c2be365b6e8f4ffe1f3156c0e2e8b553d000cdfd (diff) | |
client/posts: add option to disable safety ratings
Diffstat (limited to 'client/js/models/post_list.js')
| -rw-r--r-- | client/js/models/post_list.js | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/client/js/models/post_list.js b/client/js/models/post_list.js index 244e781..2e3c6fc 100644 --- a/client/js/models/post_list.js +++ b/client/js/models/post_list.js @@ -1,5 +1,7 @@ 'use strict'; +const settings = require('../models/settings.js'); +const config = require('../config.js'); const api = require('../api.js'); const uri = require('../util/uri.js'); const AbstractList = require('./abstract_list.js'); @@ -9,14 +11,17 @@ class PostList extends AbstractList { static getAround(id, searchQuery) { return api.get( uri.formatApiLink( - 'post', id, 'around', {query: searchQuery, fields: 'id'})); + 'post', id, 'around', { + query: PostList._decorateSearchQuery(searchQuery || ''), + fields: 'id', + })); } static search(text, offset, limit, fields) { return api.get( uri.formatApiLink( 'posts', { - query: text, + query: PostList._decorateSearchQuery(text || ''), offset: offset, limit: limit, fields: fields.join(','), @@ -28,6 +33,23 @@ class PostList extends AbstractList { {results: PostList.fromResponse(response.results)})); }); } + + static _decorateSearchQuery(text) { + const browsingSettings = settings.get(); + const disabledSafety = []; + if (config.enableSafety) { + for (let key of Object.keys(browsingSettings.listPosts)) { + if (browsingSettings.listPosts[key] === false) { + disabledSafety.push(key); + } + } + if (disabledSafety.length) { + text = `-rating:${disabledSafety.join(',')} ${text}`; + } + } + return text.trim(); + } + } PostList._itemClass = Post; |