mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-29 00:21:41 +03:00
commit
b85158f69d
@ -59,6 +59,7 @@ const mapStateToProps = state => ({
|
||||
isLoggedIn: state.application.isLoggedIn,
|
||||
isLoginDone: state.application.isLoginDone,
|
||||
isCollapsePostButtonOpen: state.ui.isCollapsePostButton,
|
||||
nsfw: state.application.nsfw,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(PostsContainer);
|
||||
|
@ -81,7 +81,7 @@ class PostsView extends Component {
|
||||
|
||||
_loadPosts = () => {
|
||||
const {
|
||||
getFor, tag, currentAccountUsername, pageType,
|
||||
getFor, tag, currentAccountUsername, pageType, nsfw,
|
||||
} = this.props;
|
||||
const {
|
||||
posts, startAuthor, startPermlink, refreshing, selectedFilterIndex,
|
||||
@ -114,7 +114,7 @@ class PostsView extends Component {
|
||||
options.start_permlink = startPermlink;
|
||||
}
|
||||
|
||||
getPostsSummary(filter, options, currentAccountUsername)
|
||||
getPostsSummary(filter, options, currentAccountUsername, nsfw)
|
||||
.then((result) => {
|
||||
if (result.length > 0) {
|
||||
let _posts = result;
|
||||
@ -160,7 +160,7 @@ class PostsView extends Component {
|
||||
this.setState({ isNoPost: true });
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(() => {
|
||||
this.setState({
|
||||
refreshing: false,
|
||||
isPostsLoading: false,
|
||||
|
@ -63,7 +63,13 @@
|
||||
"dark_theme": "Dark Theme",
|
||||
"push_notification": "Push Notification",
|
||||
"pincode": "PIN code",
|
||||
"reset": "Reset"
|
||||
"reset": "Reset",
|
||||
"nsfw_content": "NSFW Content",
|
||||
"nsfw": {
|
||||
"always_show": "Always show",
|
||||
"always_hide": "Always hide",
|
||||
"always_warn": "Always warn"
|
||||
}
|
||||
},
|
||||
"voters": {
|
||||
"voters_info": "Voters Info",
|
||||
|
5
src/constants/options/nsfw.js
Normal file
5
src/constants/options/nsfw.js
Normal file
@ -0,0 +1,5 @@
|
||||
export default [
|
||||
'settings.nsfw.always_show',
|
||||
'settings.nsfw.always_warn',
|
||||
'settings.nsfw.always_hide',
|
||||
];
|
@ -11,6 +11,7 @@ import { parsePosts, parsePost, parseComments } from '../../utils/postParser';
|
||||
import { getName, getAvatar } from '../../utils/user';
|
||||
import { getReputation } from '../../utils/reputation';
|
||||
import parseToken from '../../utils/parseToken';
|
||||
import filterNsfwPost from '../../utils/filterNsfwPost';
|
||||
|
||||
// Constant
|
||||
import AUTH_TYPE from '../../constants/authType';
|
||||
@ -274,12 +275,17 @@ export const getPosts = async (by, query, user) => {
|
||||
|
||||
export const getActiveVotes = (author, permlink) => client.database.call('get_active_votes', [author, permlink]);
|
||||
|
||||
export const getPostsSummary = async (by, query, currentUserName) => {
|
||||
export const getPostsSummary = async (by, query, currentUserName, filterNsfw) => {
|
||||
try {
|
||||
let posts = await client.database.getDiscussions(by, query);
|
||||
|
||||
if (posts) {
|
||||
posts = await parsePosts(posts, currentUserName, true);
|
||||
|
||||
if (filterNsfw !== '0') {
|
||||
const updatedPosts = filterNsfwPost(posts, filterNsfw);
|
||||
return updatedPosts;
|
||||
}
|
||||
}
|
||||
return posts;
|
||||
} catch (error) {
|
||||
|
@ -51,6 +51,7 @@ const settingsSchema = {
|
||||
notification: { type: 'bool', default: true },
|
||||
server: { type: 'string', default: null },
|
||||
upvotePercent: { type: 'string', default: null },
|
||||
nsfw: { type: 'string', default: null },
|
||||
},
|
||||
};
|
||||
|
||||
@ -74,7 +75,7 @@ const authSchema = {
|
||||
const realm = new Realm({
|
||||
path: 'esteem.realm',
|
||||
schema: [userSchema, authSchema, draftSchema, settingsSchema, applicationSchema, scAccounts],
|
||||
schemaVersion: 0,
|
||||
schemaVersion: 1,
|
||||
migration,
|
||||
});
|
||||
|
||||
@ -102,6 +103,7 @@ if (Array.from(settings).length <= 0) {
|
||||
notification: true,
|
||||
server: '',
|
||||
upvotePercent: '1',
|
||||
nsfw: '0',
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -365,6 +367,29 @@ export const getUpvotePercent = () => new Promise((resolve, reject) => {
|
||||
}
|
||||
});
|
||||
|
||||
export const getNsfw = () => new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (settings[0]) {
|
||||
resolve(settings[0].nsfw);
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
export const setNsfw = nsfw => new Promise((resolve, reject) => {
|
||||
try {
|
||||
realm.write(() => {
|
||||
settings[0].nsfw = nsfw;
|
||||
resolve(true);
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
export const getTheme = () => new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (settings[0]) {
|
||||
|
@ -15,6 +15,7 @@ import {
|
||||
SET_CURRENCY,
|
||||
SET_LANGUAGE,
|
||||
SET_UPVOTE_PERCENT,
|
||||
SET_NSFW,
|
||||
} from '../constants/constants';
|
||||
|
||||
export const login = payload => ({
|
||||
@ -77,6 +78,11 @@ export const setConnectivityStatus = payload => ({
|
||||
type: IS_CONNECTED,
|
||||
});
|
||||
|
||||
export const setNsfw = payload => ({
|
||||
payload,
|
||||
type: SET_NSFW,
|
||||
});
|
||||
|
||||
/**
|
||||
* MW
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ export const SET_API = 'SET_API';
|
||||
export const SET_CURRENCY = 'SET_CURRENCY';
|
||||
export const SET_LANGUAGE = 'SET_LANGUAGE';
|
||||
export const SET_UPVOTE_PERCENT = 'SET_UPVOTE_PERCENT';
|
||||
export const SET_NSFW = 'SET_NSFW';
|
||||
|
||||
// Accounts
|
||||
export const ADD_OTHER_ACCOUNT = 'ADD_OTHER_ACCOUNT';
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
SET_CURRENCY,
|
||||
SET_LANGUAGE,
|
||||
SET_UPVOTE_PERCENT,
|
||||
SET_NSFW,
|
||||
} from '../constants/constants';
|
||||
|
||||
const initialState = {
|
||||
@ -33,6 +34,7 @@ const initialState = {
|
||||
language: 'en-US',
|
||||
loading: false, // It is lock to all screen and shows loading animation.
|
||||
upvotePercent: 1,
|
||||
nsfw: 'Always show',
|
||||
};
|
||||
|
||||
export default function (state = initialState, action) {
|
||||
@ -101,6 +103,10 @@ export default function (state = initialState, action) {
|
||||
return Object.assign({}, state, {
|
||||
upvotePercent: action.payload,
|
||||
});
|
||||
case SET_NSFW:
|
||||
return Object.assign({}, state, {
|
||||
nsfw: action.payload,
|
||||
});
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ import {
|
||||
setCurrency,
|
||||
setLanguage,
|
||||
setUpvotePercent,
|
||||
setNsfw,
|
||||
} from '../../../redux/actions/applicationActions';
|
||||
|
||||
// Container
|
||||
@ -250,6 +251,7 @@ class ApplicationContainer extends Component {
|
||||
dispatch(isNotificationOpen(response.notification));
|
||||
Push.setEnabled(response.notification);
|
||||
}
|
||||
if (response.nsfw !== '') dispatch(setNsfw(response.nsfw));
|
||||
|
||||
dispatch(setCurrency(response.currency !== '' ? response.currency : 'usd'));
|
||||
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
setServer,
|
||||
setNotificationIsOpen,
|
||||
getExistUser,
|
||||
setNsfw as setNsfw2DB,
|
||||
} from '../../../realm/realm';
|
||||
|
||||
// Services and Actions
|
||||
@ -23,6 +24,7 @@ import {
|
||||
setApi,
|
||||
isDarkTheme,
|
||||
openPinCodeModal,
|
||||
setNsfw,
|
||||
} from '../../../redux/actions/applicationActions';
|
||||
import { toastNotification } from '../../../redux/actions/uiAction';
|
||||
import { setPushToken, getNodes } from '../../../providers/esteem/esteem';
|
||||
@ -79,6 +81,11 @@ class SettingsContainer extends Component {
|
||||
this._changeApi(action);
|
||||
break;
|
||||
|
||||
case 'nsfw':
|
||||
dispatch(setNsfw(action));
|
||||
setNsfw2DB(action);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -112,7 +119,6 @@ class SettingsContainer extends Component {
|
||||
dispatch(toastNotification('Server not available'));
|
||||
isError = true;
|
||||
|
||||
this.setState({ apiCheck: false });
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -232,6 +238,7 @@ const mapStateToProps = state => ({
|
||||
isNotificationSettingsOpen: state.application.isNotificationOpen,
|
||||
isLoggedIn: state.application.isLoggedIn,
|
||||
username: state.account.currentAccount && state.account.currentAccount.name,
|
||||
nsfw: state.application.nsfw,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(SettingsContainer);
|
||||
|
@ -8,6 +8,7 @@ import { groomingServerName } from '../../../utils/settings';
|
||||
// Constants
|
||||
import LANGUAGE, { VALUE as LANGUAGE_VALUE } from '../../../constants/options/language';
|
||||
import CURRENCY, { VALUE as CURRENCY_VALUE } from '../../../constants/options/currency';
|
||||
import NSFW from '../../../constants/options/nsfw';
|
||||
|
||||
// Components
|
||||
import { BasicHeader } from '../../../components/basicHeader';
|
||||
@ -41,6 +42,7 @@ class SettingsScreen extends PureComponent {
|
||||
selectedCurrency,
|
||||
selectedLanguage,
|
||||
serverList,
|
||||
nsfw,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
@ -83,6 +85,18 @@ class SettingsScreen extends PureComponent {
|
||||
defaultText={groomingServerName(selectedApi)}
|
||||
handleOnChange={handleOnChange}
|
||||
/>
|
||||
<SettingsItem
|
||||
title={intl.formatMessage({
|
||||
id: 'settings.nsfw_content',
|
||||
})}
|
||||
type="dropdown"
|
||||
actionType="nsfw"
|
||||
options={NSFW.map(item => intl.formatMessage({
|
||||
id: item,
|
||||
}))}
|
||||
selectedOptionIndex={parseInt(nsfw, 10)}
|
||||
handleOnChange={handleOnChange}
|
||||
/>
|
||||
<SettingsItem
|
||||
title={intl.formatMessage({
|
||||
id: 'settings.dark_theme',
|
||||
|
17
src/utils/filterNsfwPost.js
Normal file
17
src/utils/filterNsfwPost.js
Normal file
@ -0,0 +1,17 @@
|
||||
export default (posts, option) => {
|
||||
const updatedPosts = [];
|
||||
if (option === '1') {
|
||||
posts.map((post) => {
|
||||
if (post.parent_permlink === 'nsfw' || post.json_metadata.tags.includes('nsfw')) {
|
||||
post.image = 'https://steemitimages.com/p/Zskj9C56UonWToSX7uRkL8H89BqdWqSPnzP84oDpA65G4PfbZk688V2cRYbWszK7zoMMj35CfbJfcXuJSSwTvasK4pPKfHMy2xjGJSkmqs8gLQnoddR8?format=match&mode=fit&width=600&height=600';
|
||||
}
|
||||
});
|
||||
return posts;
|
||||
}
|
||||
posts.map((post) => {
|
||||
if (post.parent_permlink !== 'nsfw' && !post.json_metadata.tags.includes('nsfw')) {
|
||||
updatedPosts.push(post);
|
||||
}
|
||||
});
|
||||
return updatedPosts;
|
||||
};
|
Loading…
Reference in New Issue
Block a user