This commit is contained in:
u-e 2019-03-05 20:06:52 +03:00
commit 429646cbf8
18 changed files with 119 additions and 15 deletions

View File

@ -25,6 +25,7 @@ export default EStyleSheet.create({
color: '$primaryDarkGray',
fontSize: 14,
fontWeight: 'bold',
maxWidth: '$deviceWidth - 100',
fontFamily: '$primaryFont',
},
reputation: {

View File

@ -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);

View File

@ -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,

View File

@ -4,7 +4,7 @@ export default EStyleSheet.create({
container: {
padding: 8,
flexDirection: 'row',
height: '$deviceHeight - 100',
height: '$deviceHeight - 150',
backgroundColor: '$primaryBackgroundColor',
},
text: {

View File

@ -1,11 +1,11 @@
import axios from 'axios';
import Config from 'react-native-config';
const search = axios.create({
const ePoint = axios.create({
baseURL: Config.BACKEND_URL,
headers: {
'User-Agent': Config.USER_AGENT,
},
});
export default search;
export default ePoint;

View File

@ -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",

View File

@ -0,0 +1,5 @@
export default [
'settings.nsfw.always_show',
'settings.nsfw.always_warn',
'settings.nsfw.always_hide',
];

View File

@ -12,7 +12,14 @@ export const userActivity = (username, type, blockNumber = '', transactionNumber
}
try {
return ePointApi.post('/usr-activity', params).then(res => res.data);
return ePointApi
.post('/usr-activity', {
us: username,
ty: type,
bn: blockNumber,
tn: transactionNumber,
})
.then(res => res.data);
} catch (error) {
return null;
}

View File

@ -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) {

View File

@ -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]) {

View File

@ -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
*/

View File

@ -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';

View File

@ -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;
}

View File

@ -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'));

View File

@ -46,7 +46,7 @@ class BookmarksScreen extends Component {
handleOnPress={() => (isFavorites
? handleOnFavoritePress(item.account)
: handleOnBookarkPress(item.permlink, item.author))
}
}
index={index}
isClickable
text={text}
@ -76,9 +76,9 @@ class BookmarksScreen extends Component {
) : (
!isNoItem && (
<FlatList
data={
data.map(item => (item._id !== data[item._id] && isFavorites ? item.account !== data[item.account] && item : item))
}
data={data.map(item => (item._id !== data[item._id] && isFavorites
? item.account !== data[item.account] && item
: item))}
keyExtractor={item => item._id}
removeClippedSubviews={false}
renderItem={({ item, index }) => this._renderItem(item, index, type)}

View File

@ -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);

View File

@ -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',

View 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;
};