mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 21:01:31 +03:00
Merge pull request #688 from esteemapp/feature/custom-push
Feature/custom push
This commit is contained in:
commit
3c0e75500c
Binary file not shown.
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>BuildLocationStyle</key>
|
||||||
|
<string>UseAppPreferences</string>
|
||||||
|
<key>CustomBuildLocationType</key>
|
||||||
|
<string>RelativeToDerivedData</string>
|
||||||
|
<key>DerivedDataLocationStyle</key>
|
||||||
|
<string>Default</string>
|
||||||
|
<key>EnabledFullIndexStoreVisibility</key>
|
||||||
|
<false/>
|
||||||
|
<key>IssueFilterStyle</key>
|
||||||
|
<string>ShowActiveSchemeOnly</string>
|
||||||
|
<key>LiveSourceIssuesEnabled</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
@ -34,11 +34,11 @@ class CollapsibleCardView extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
const { isExpanded, moreHeight } = this.props;
|
const { isExpanded, moreHeight, locked } = this.props;
|
||||||
const { expanded } = this.state;
|
const { expanded } = this.state;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!nextProps.isExpanded
|
(locked || !nextProps.isExpanded)
|
||||||
&& isExpanded !== nextProps.isExpanded
|
&& isExpanded !== nextProps.isExpanded
|
||||||
&& expanded !== nextProps.isExpanded
|
&& expanded !== nextProps.isExpanded
|
||||||
) {
|
) {
|
||||||
|
@ -85,11 +85,11 @@ class SettingsItemView extends PureComponent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { title } = this.props;
|
const { title, titleStyle } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.wrapper}>
|
<View style={styles.wrapper}>
|
||||||
<Text style={styles.text}>{title}</Text>
|
<Text style={[styles.text, titleStyle]}>{title}</Text>
|
||||||
{this._renderItem()}
|
{this._renderItem()}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
@ -58,11 +58,20 @@
|
|||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
|
"general": "General",
|
||||||
"currency": "Currency",
|
"currency": "Currency",
|
||||||
"language": "Language",
|
"language": "Language",
|
||||||
"server": "Server",
|
"server": "Server",
|
||||||
"dark_theme": "Dark Theme",
|
"dark_theme": "Dark Theme",
|
||||||
"push_notification": "Push Notification",
|
"push_notification": "Push Notification",
|
||||||
|
"notification": {
|
||||||
|
"follow": "Follow",
|
||||||
|
"vote": "Vote",
|
||||||
|
"comment": "Comment",
|
||||||
|
"mention": "Mention",
|
||||||
|
"reblog": "Reblog",
|
||||||
|
"transfers": "Transfers"
|
||||||
|
},
|
||||||
"pincode": "PIN code",
|
"pincode": "PIN code",
|
||||||
"reset": "Reset",
|
"reset": "Reset",
|
||||||
"nsfw_content": "NSFW Content",
|
"nsfw_content": "NSFW Content",
|
||||||
|
@ -54,10 +54,6 @@ export default EStyleSheet.create({
|
|||||||
backgroundColor: '$primaryLightBackground',
|
backgroundColor: '$primaryLightBackground',
|
||||||
flex: 1,
|
flex: 1,
|
||||||
},
|
},
|
||||||
settingsContainer: {
|
|
||||||
marginLeft: 42,
|
|
||||||
marginRight: 32,
|
|
||||||
},
|
|
||||||
hintText: {
|
hintText: {
|
||||||
color: '$iconColor',
|
color: '$iconColor',
|
||||||
alignSelf: 'center',
|
alignSelf: 'center',
|
||||||
|
@ -53,6 +53,12 @@ const settingsSchema = {
|
|||||||
nsfw: { type: 'string', default: null },
|
nsfw: { type: 'string', default: null },
|
||||||
server: { type: 'string', default: null },
|
server: { type: 'string', default: null },
|
||||||
upvotePercent: { type: 'string', default: null },
|
upvotePercent: { type: 'string', default: null },
|
||||||
|
followNotification: { type: 'bool', default: true },
|
||||||
|
voteNotification: { type: 'bool', default: true },
|
||||||
|
commentNotification: { type: 'bool', default: true },
|
||||||
|
mentionNotification: { type: 'bool', default: true },
|
||||||
|
reblogNotification: { type: 'bool', default: true },
|
||||||
|
transfersNotification: { type: 'bool', default: true },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,6 +111,12 @@ if (Array.from(settings).length <= 0) {
|
|||||||
server: '',
|
server: '',
|
||||||
upvotePercent: '1',
|
upvotePercent: '1',
|
||||||
nsfw: '0',
|
nsfw: '0',
|
||||||
|
followNotification: true,
|
||||||
|
voteNotification: true,
|
||||||
|
commentNotification: true,
|
||||||
|
mentionNotification: true,
|
||||||
|
reblogNotification: true,
|
||||||
|
transfersNotification: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -450,10 +462,34 @@ export const setServer = selectedServer => new Promise((resolve, reject) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const setNotificationIsOpen = notificationIsOpen => new Promise((resolve, reject) => {
|
export const setNotificationSettings = ({ type, action }) => new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
settings[0].notification = notificationIsOpen;
|
switch (type) {
|
||||||
|
case 'notification.follow':
|
||||||
|
settings[0].followNotification = action;
|
||||||
|
break;
|
||||||
|
case 'notification.vote':
|
||||||
|
settings[0].voteNotification = action;
|
||||||
|
break;
|
||||||
|
case 'notification.comment':
|
||||||
|
settings[0].commentNotification = action;
|
||||||
|
break;
|
||||||
|
case 'notification.mention':
|
||||||
|
settings[0].mentionNotification = action;
|
||||||
|
break;
|
||||||
|
case 'notification.reblog':
|
||||||
|
settings[0].reblogNotification = action;
|
||||||
|
break;
|
||||||
|
case 'notification.transfers':
|
||||||
|
settings[0].transfersNotification = action;
|
||||||
|
break;
|
||||||
|
case 'notification':
|
||||||
|
settings[0].notification = action;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -2,6 +2,13 @@ import getSymbolFromCurrency from 'currency-symbol-map';
|
|||||||
import { getCurrencyRate } from '../../providers/esteem/esteem';
|
import { getCurrencyRate } from '../../providers/esteem/esteem';
|
||||||
import {
|
import {
|
||||||
ACTIVE_APPLICATION,
|
ACTIVE_APPLICATION,
|
||||||
|
CHANGE_COMMENT_NOTIFICATION,
|
||||||
|
CHANGE_FOLLOW_NOTIFICATION,
|
||||||
|
CHANGE_MENTION_NOTIFICATION,
|
||||||
|
CHANGE_REBLOG_NOTIFICATION,
|
||||||
|
CHANGE_TRANSFERS_NOTIFICATION,
|
||||||
|
CHANGE_ALL_NOTIFICATION_SETTINGS,
|
||||||
|
CHANGE_VOTE_NOTIFICATION,
|
||||||
CLOSE_PIN_CODE_MODAL,
|
CLOSE_PIN_CODE_MODAL,
|
||||||
IS_CONNECTED,
|
IS_CONNECTED,
|
||||||
IS_DARK_THEME,
|
IS_DARK_THEME,
|
||||||
@ -64,11 +71,60 @@ export const setUpvotePercent = payload => ({
|
|||||||
type: SET_UPVOTE_PERCENT,
|
type: SET_UPVOTE_PERCENT,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const isNotificationOpen = payload => ({
|
export const changeAllNotificationSettings = payload => ({
|
||||||
payload,
|
payload,
|
||||||
type: IS_NOTIFICATION_OPEN,
|
type: CHANGE_ALL_NOTIFICATION_SETTINGS,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const changeNotificationSettings = (payload) => {
|
||||||
|
switch (payload.type) {
|
||||||
|
case 'notification.follow':
|
||||||
|
return {
|
||||||
|
payload: payload.action,
|
||||||
|
type: CHANGE_FOLLOW_NOTIFICATION,
|
||||||
|
};
|
||||||
|
|
||||||
|
case 'notification.vote':
|
||||||
|
return {
|
||||||
|
payload: payload.action,
|
||||||
|
type: CHANGE_VOTE_NOTIFICATION,
|
||||||
|
};
|
||||||
|
|
||||||
|
case 'notification.comment':
|
||||||
|
return {
|
||||||
|
payload: payload.action,
|
||||||
|
type: CHANGE_COMMENT_NOTIFICATION,
|
||||||
|
};
|
||||||
|
|
||||||
|
case 'notification.mention':
|
||||||
|
return {
|
||||||
|
payload: payload.action,
|
||||||
|
type: CHANGE_MENTION_NOTIFICATION,
|
||||||
|
};
|
||||||
|
|
||||||
|
case 'notification.reblog':
|
||||||
|
return {
|
||||||
|
payload: payload.action,
|
||||||
|
type: CHANGE_REBLOG_NOTIFICATION,
|
||||||
|
};
|
||||||
|
|
||||||
|
case 'notification.transfers':
|
||||||
|
return {
|
||||||
|
payload: payload.action,
|
||||||
|
type: CHANGE_TRANSFERS_NOTIFICATION,
|
||||||
|
};
|
||||||
|
|
||||||
|
case 'notification':
|
||||||
|
return {
|
||||||
|
payload: payload.action,
|
||||||
|
type: IS_NOTIFICATION_OPEN,
|
||||||
|
};
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const isDarkTheme = payload => ({
|
export const isDarkTheme = payload => ({
|
||||||
payload,
|
payload,
|
||||||
type: IS_DARK_THEME,
|
type: IS_DARK_THEME,
|
||||||
|
@ -23,6 +23,13 @@ export const SET_CURRENCY = 'SET_CURRENCY';
|
|||||||
export const SET_LANGUAGE = 'SET_LANGUAGE';
|
export const SET_LANGUAGE = 'SET_LANGUAGE';
|
||||||
export const SET_UPVOTE_PERCENT = 'SET_UPVOTE_PERCENT';
|
export const SET_UPVOTE_PERCENT = 'SET_UPVOTE_PERCENT';
|
||||||
export const SET_NSFW = 'SET_NSFW';
|
export const SET_NSFW = 'SET_NSFW';
|
||||||
|
export const CHANGE_FOLLOW_NOTIFICATION = 'CHANGE_FOLLOW_NOTIFICATION';
|
||||||
|
export const CHANGE_VOTE_NOTIFICATION = 'CHANGE_VOTE_NOTIFICATION';
|
||||||
|
export const CHANGE_COMMENT_NOTIFICATION = 'CHANGE_COMMENT_NOTIFICATION';
|
||||||
|
export const CHANGE_MENTION_NOTIFICATION = 'CHANGE_MENTION_NOTIFICATION';
|
||||||
|
export const CHANGE_REBLOG_NOTIFICATION = 'CHANGE_REBLOG_NOTIFICATION';
|
||||||
|
export const CHANGE_TRANSFERS_NOTIFICATION = 'CHANGE_TRANSFERS_NOTIFICATION';
|
||||||
|
export const CHANGE_ALL_NOTIFICATION_SETTINGS = 'CHANGE_ALL_NOTIFICATION_SETTINGS';
|
||||||
|
|
||||||
// Accounts
|
// Accounts
|
||||||
export const ADD_OTHER_ACCOUNT = 'ADD_OTHER_ACCOUNT';
|
export const ADD_OTHER_ACCOUNT = 'ADD_OTHER_ACCOUNT';
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
import {
|
import {
|
||||||
ACTIVE_APPLICATION,
|
ACTIVE_APPLICATION,
|
||||||
|
CHANGE_COMMENT_NOTIFICATION,
|
||||||
|
CHANGE_FOLLOW_NOTIFICATION,
|
||||||
|
CHANGE_MENTION_NOTIFICATION,
|
||||||
|
CHANGE_REBLOG_NOTIFICATION,
|
||||||
|
CHANGE_TRANSFERS_NOTIFICATION,
|
||||||
|
CHANGE_VOTE_NOTIFICATION,
|
||||||
|
CHANGE_ALL_NOTIFICATION_SETTINGS,
|
||||||
CLOSE_PIN_CODE_MODAL,
|
CLOSE_PIN_CODE_MODAL,
|
||||||
IS_CONNECTED,
|
IS_CONNECTED,
|
||||||
IS_DARK_THEME,
|
IS_DARK_THEME,
|
||||||
@ -35,6 +42,14 @@ const initialState = {
|
|||||||
isPinCodeReqiure: false,
|
isPinCodeReqiure: false,
|
||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
loading: false, // It is lock to all screen and shows loading animation.
|
loading: false, // It is lock to all screen and shows loading animation.
|
||||||
|
notificationDetails: {
|
||||||
|
commentNotification: true,
|
||||||
|
followNotification: true,
|
||||||
|
mentionNotification: true,
|
||||||
|
reblogNotification: true,
|
||||||
|
transfersNotification: true,
|
||||||
|
voteNotification: true,
|
||||||
|
},
|
||||||
upvotePercent: 1,
|
upvotePercent: 1,
|
||||||
nsfw: 'Always show',
|
nsfw: 'Always show',
|
||||||
};
|
};
|
||||||
@ -97,6 +112,61 @@ export default function (state = initialState, action) {
|
|||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
isNotificationOpen: action.payload,
|
isNotificationOpen: action.payload,
|
||||||
});
|
});
|
||||||
|
case CHANGE_COMMENT_NOTIFICATION:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
notificationDetails: {
|
||||||
|
...state.notificationDetails,
|
||||||
|
commentNotification: action.payload,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
case CHANGE_FOLLOW_NOTIFICATION:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
notificationDetails: {
|
||||||
|
...state.notificationDetails,
|
||||||
|
followNotification: action.payload,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
case CHANGE_MENTION_NOTIFICATION:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
notificationDetails: {
|
||||||
|
...state.notificationDetails,
|
||||||
|
mentionNotification: action.payload,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
case CHANGE_REBLOG_NOTIFICATION:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
notificationDetails: {
|
||||||
|
...state.notificationDetails,
|
||||||
|
reblogNotification: action.payload,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
case CHANGE_TRANSFERS_NOTIFICATION:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
notificationDetails: {
|
||||||
|
...state.notificationDetails,
|
||||||
|
transfersNotification: action.payload,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
case CHANGE_VOTE_NOTIFICATION:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
notificationDetails: {
|
||||||
|
...state.notificationDetails,
|
||||||
|
voteNotification: action.payload,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
case CHANGE_ALL_NOTIFICATION_SETTINGS:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
notificationDetails: {
|
||||||
|
...state.notificationDetails,
|
||||||
|
mentionNotification: action.payload.mentionNotification,
|
||||||
|
reblogNotification: action.payload.reblogNotification,
|
||||||
|
transfersNotification: action.payload.transfersNotification,
|
||||||
|
voteNotification: action.payload.voteNotification,
|
||||||
|
followNotification: action.payload.followNotification,
|
||||||
|
commentNotification: action.payload.commentNotification,
|
||||||
|
},
|
||||||
|
});
|
||||||
case IS_DARK_THEME:
|
case IS_DARK_THEME:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
isDarkTheme: action.payload,
|
isDarkTheme: action.payload,
|
||||||
|
@ -5,7 +5,6 @@ import {
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { addLocaleData } from 'react-intl';
|
import { addLocaleData } from 'react-intl';
|
||||||
import Config from 'react-native-config';
|
import Config from 'react-native-config';
|
||||||
import AppCenter from 'appcenter';
|
|
||||||
import { NavigationActions } from 'react-navigation';
|
import { NavigationActions } from 'react-navigation';
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
import Push from 'appcenter-push';
|
import Push from 'appcenter-push';
|
||||||
@ -29,11 +28,9 @@ import AUTH_TYPE from '../../../constants/authType';
|
|||||||
import {
|
import {
|
||||||
getAuthStatus,
|
getAuthStatus,
|
||||||
getExistUser,
|
getExistUser,
|
||||||
getPushTokenSaved,
|
|
||||||
getSettings,
|
getSettings,
|
||||||
getUserData,
|
getUserData,
|
||||||
removeUserData,
|
removeUserData,
|
||||||
setPushTokenSaved,
|
|
||||||
getUserDataWithUsername,
|
getUserDataWithUsername,
|
||||||
removePinCode,
|
removePinCode,
|
||||||
setAuthStatus,
|
setAuthStatus,
|
||||||
@ -42,7 +39,6 @@ import {
|
|||||||
setDefaultFooter,
|
setDefaultFooter,
|
||||||
} from '../../../realm/realm';
|
} from '../../../realm/realm';
|
||||||
import { getUser } from '../../../providers/steem/dsteem';
|
import { getUser } from '../../../providers/steem/dsteem';
|
||||||
import { setPushToken } from '../../../providers/esteem/esteem';
|
|
||||||
import { switchAccount } from '../../../providers/steem/auth';
|
import { switchAccount } from '../../../providers/steem/auth';
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -57,7 +53,8 @@ import {
|
|||||||
activeApplication,
|
activeApplication,
|
||||||
isDarkTheme,
|
isDarkTheme,
|
||||||
isLoginDone,
|
isLoginDone,
|
||||||
isNotificationOpen,
|
changeNotificationSettings,
|
||||||
|
changeAllNotificationSettings,
|
||||||
login,
|
login,
|
||||||
logoutDone,
|
logoutDone,
|
||||||
openPinCodeModal,
|
openPinCodeModal,
|
||||||
@ -229,7 +226,6 @@ class ApplicationContainer extends Component {
|
|||||||
dispatch(openPinCodeModal());
|
dispatch(openPinCodeModal());
|
||||||
}
|
}
|
||||||
this._connectNotificationServer(accountData.name);
|
this._connectNotificationServer(accountData.name);
|
||||||
this._setPushToken(accountData.name);
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
Alert.alert(err);
|
Alert.alert(err);
|
||||||
@ -251,7 +247,9 @@ class ApplicationContainer extends Component {
|
|||||||
if (response.upvotePercent !== '') dispatch(setUpvotePercent(Number(response.upvotePercent)));
|
if (response.upvotePercent !== '') dispatch(setUpvotePercent(Number(response.upvotePercent)));
|
||||||
if (response.isDefaultFooter !== '') dispatch(isDefaultFooter(response.isDefaultFooter));
|
if (response.isDefaultFooter !== '') dispatch(isDefaultFooter(response.isDefaultFooter));
|
||||||
if (response.notification !== '') {
|
if (response.notification !== '') {
|
||||||
dispatch(isNotificationOpen(response.notification));
|
dispatch(changeNotificationSettings({ type: 'notification', action: response.notification }));
|
||||||
|
dispatch(changeAllNotificationSettings(response));
|
||||||
|
|
||||||
Push.setEnabled(response.notification);
|
Push.setEnabled(response.notification);
|
||||||
}
|
}
|
||||||
if (response.nsfw !== '') dispatch(setNsfw(response.nsfw));
|
if (response.nsfw !== '') dispatch(setNsfw(response.nsfw));
|
||||||
@ -273,29 +271,6 @@ class ApplicationContainer extends Component {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
_setPushToken = async (username) => {
|
|
||||||
const { notificationSettings } = this.props;
|
|
||||||
const token = await AppCenter.getInstallId();
|
|
||||||
|
|
||||||
getExistUser().then((isExistUser) => {
|
|
||||||
if (isExistUser) {
|
|
||||||
getPushTokenSaved().then((isPushTokenSaved) => {
|
|
||||||
if (!isPushTokenSaved) {
|
|
||||||
const data = {
|
|
||||||
username,
|
|
||||||
token,
|
|
||||||
system: Platform.OS,
|
|
||||||
allows_notify: Number(notificationSettings),
|
|
||||||
};
|
|
||||||
setPushToken(data).then(() => {
|
|
||||||
setPushTokenSaved(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
_logout = async () => {
|
_logout = async () => {
|
||||||
const { otherAccounts, currentAccount, dispatch } = this.props;
|
const { otherAccounts, currentAccount, dispatch } = this.props;
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import { Alert, Linking } from 'react-native';
|
import { Alert, Linking, Platform } from 'react-native';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { injectIntl } from 'react-intl';
|
import { injectIntl } from 'react-intl';
|
||||||
|
import AppCenter from 'appcenter';
|
||||||
|
|
||||||
// Services and Actions
|
// Services and Actions
|
||||||
import { login } from '../../../providers/steem/auth';
|
import { login } from '../../../providers/steem/auth';
|
||||||
@ -13,6 +14,8 @@ import {
|
|||||||
updateCurrentAccount,
|
updateCurrentAccount,
|
||||||
} from '../../../redux/actions/accountAction';
|
} from '../../../redux/actions/accountAction';
|
||||||
import { login as loginAction, openPinCodeModal } from '../../../redux/actions/applicationActions';
|
import { login as loginAction, openPinCodeModal } from '../../../redux/actions/applicationActions';
|
||||||
|
import { setPushTokenSaved } from '../../../realm/realm';
|
||||||
|
import { setPushToken } from '../../../providers/esteem/esteem';
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
|
|
||||||
@ -57,6 +60,7 @@ class LoginContainer extends PureComponent {
|
|||||||
setPinCodeState({ navigateTo: ROUTES.DRAWER.MAIN });
|
setPinCodeState({ navigateTo: ROUTES.DRAWER.MAIN });
|
||||||
dispatch(loginAction(true));
|
dispatch(loginAction(true));
|
||||||
userActivity(result.name, 20);
|
userActivity(result.name, 20);
|
||||||
|
this._setPushToken(result.name);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@ -71,6 +75,39 @@ class LoginContainer extends PureComponent {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_setPushToken = async (username) => {
|
||||||
|
const { notificationSettings, notificationDetails } = this.props;
|
||||||
|
const notifyTypesConst = {
|
||||||
|
vote: 1,
|
||||||
|
mention: 2,
|
||||||
|
follow: 3,
|
||||||
|
comment: 4,
|
||||||
|
reblog: 5,
|
||||||
|
transfers: 6,
|
||||||
|
};
|
||||||
|
const notifyTypes = [];
|
||||||
|
const token = await AppCenter.getInstallId();
|
||||||
|
|
||||||
|
Object.keys(notificationDetails).map((item) => {
|
||||||
|
const notificationType = item.replace('Notification', '');
|
||||||
|
|
||||||
|
if (notificationDetails[item]) {
|
||||||
|
notifyTypes.push(notifyTypesConst[notificationType]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
username,
|
||||||
|
token,
|
||||||
|
system: Platform.OS,
|
||||||
|
allows_notify: Number(notificationSettings),
|
||||||
|
notify_types: notifyTypes,
|
||||||
|
};
|
||||||
|
setPushToken(data).then(() => {
|
||||||
|
setPushTokenSaved(true);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
_getAccountsWithUsername = async (username) => {
|
_getAccountsWithUsername = async (username) => {
|
||||||
const validUsers = await lookupAccounts(username);
|
const validUsers = await lookupAccounts(username);
|
||||||
return validUsers;
|
return validUsers;
|
||||||
@ -98,6 +135,8 @@ class LoginContainer extends PureComponent {
|
|||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
account: state.accounts,
|
account: state.accounts,
|
||||||
|
notificationDetails: state.application.notificationDetails,
|
||||||
|
notificationSettings: state.application.isNotificationOpen,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default injectIntl(connect(mapStateToProps)(LoginContainer));
|
export default injectIntl(connect(mapStateToProps)(LoginContainer));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { PureComponent, Fragment } from 'react';
|
import React, { PureComponent, Fragment } from 'react';
|
||||||
import { View, Text, ScrollView } from 'react-native';
|
import { View, ScrollView } from 'react-native';
|
||||||
import { injectIntl } from 'react-intl';
|
import { injectIntl } from 'react-intl';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
@ -16,7 +16,6 @@ import { Posts } from '../../../components/posts';
|
|||||||
import { ProfileSummary } from '../../../components/profileSummary';
|
import { ProfileSummary } from '../../../components/profileSummary';
|
||||||
import { TabBar } from '../../../components/tabBar';
|
import { TabBar } from '../../../components/tabBar';
|
||||||
import { Wallet } from '../../../components/wallet';
|
import { Wallet } from '../../../components/wallet';
|
||||||
import { FormatedCurrency } from '../../../components/formatedElements';
|
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import { PROFILE_FILTERS } from '../../../constants/options/filters';
|
import { PROFILE_FILTERS } from '../../../constants/options/filters';
|
||||||
|
@ -10,23 +10,25 @@ import VersionNumber from 'react-native-version-number';
|
|||||||
import {
|
import {
|
||||||
getExistUser,
|
getExistUser,
|
||||||
setCurrency as setCurrency2DB,
|
setCurrency as setCurrency2DB,
|
||||||
|
setServer,
|
||||||
|
setNotificationSettings,
|
||||||
setDefaultFooter,
|
setDefaultFooter,
|
||||||
setLanguage as setLanguage2DB,
|
setLanguage as setLanguage2DB,
|
||||||
setNotificationIsOpen,
|
setNotificationIsOpen,
|
||||||
setNsfw as setNsfw2DB,
|
setNsfw as setNsfw2DB,
|
||||||
setServer,
|
|
||||||
setTheme,
|
setTheme,
|
||||||
} from '../../../realm/realm';
|
} from '../../../realm/realm';
|
||||||
|
|
||||||
// Services and Actions
|
// Services and Actions
|
||||||
import {
|
import {
|
||||||
|
setLanguage,
|
||||||
|
changeNotificationSettings,
|
||||||
|
setCurrency,
|
||||||
|
setApi,
|
||||||
isDarkTheme,
|
isDarkTheme,
|
||||||
isDefaultFooter,
|
isDefaultFooter,
|
||||||
isNotificationOpen,
|
isNotificationOpen,
|
||||||
openPinCodeModal,
|
openPinCodeModal,
|
||||||
setApi,
|
|
||||||
setCurrency,
|
|
||||||
setLanguage,
|
|
||||||
setNsfw,
|
setNsfw,
|
||||||
} from '../../../redux/actions/applicationActions';
|
} from '../../../redux/actions/applicationActions';
|
||||||
import { toastNotification } from '../../../redux/actions/uiAction';
|
import { toastNotification } from '../../../redux/actions/uiAction';
|
||||||
@ -55,6 +57,7 @@ class SettingsContainer extends Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
serverList: [],
|
serverList: [],
|
||||||
|
isNotificationMenuOpen: props.isNotificationSettingsOpen,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +150,13 @@ class SettingsContainer extends Component {
|
|||||||
|
|
||||||
switch (actionType) {
|
switch (actionType) {
|
||||||
case 'notification':
|
case 'notification':
|
||||||
this._handleNotification(action);
|
case 'notification.follow':
|
||||||
|
case 'notification.vote':
|
||||||
|
case 'notification.comment':
|
||||||
|
case 'notification.mention':
|
||||||
|
case 'notification.reblog':
|
||||||
|
case 'notification.transfers':
|
||||||
|
this._handleNotification(action, actionType);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'theme':
|
case 'theme':
|
||||||
@ -164,16 +173,38 @@ class SettingsContainer extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleNotification = async (action) => {
|
_handleNotification = async (action, actionType) => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch, notificationDetails } = this.props;
|
||||||
|
const notifyTypesConst = {
|
||||||
|
vote: 1,
|
||||||
|
mention: 2,
|
||||||
|
follow: 3,
|
||||||
|
comment: 4,
|
||||||
|
reblog: 5,
|
||||||
|
transfers: 6,
|
||||||
|
};
|
||||||
|
const notifyTypes = [];
|
||||||
|
|
||||||
dispatch(isNotificationOpen(action));
|
dispatch(changeNotificationSettings({ action, type: actionType }));
|
||||||
setNotificationIsOpen(action);
|
setNotificationSettings({ action, type: actionType });
|
||||||
|
|
||||||
const isPushEnabled = await Push.isEnabled();
|
if (actionType === 'notification') {
|
||||||
|
await Push.setEnabled(action);
|
||||||
|
this._setPushToken(action ? [1, 2, 3, 4, 5, 6] : notifyTypes);
|
||||||
|
} else {
|
||||||
|
Object.keys(notificationDetails).map((item) => {
|
||||||
|
const notificationType = item.replace('Notification', '');
|
||||||
|
|
||||||
await Push.setEnabled(!isPushEnabled);
|
if (notificationType === actionType.replace('notification.', '')) {
|
||||||
this._setPushToken();
|
if (action) {
|
||||||
|
notifyTypes.push(notifyTypesConst[notificationType]);
|
||||||
|
}
|
||||||
|
} else if (notificationDetails[item]) {
|
||||||
|
notifyTypes.push(notifyTypesConst[notificationType]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this._setPushToken(notifyTypes);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleButtonPress = (actionType) => {
|
_handleButtonPress = (actionType) => {
|
||||||
@ -207,8 +238,9 @@ class SettingsContainer extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_setPushToken = async () => {
|
_setPushToken = async (notifyTypes) => {
|
||||||
const { isNotificationSettingsOpen, isLoggedIn, username } = this.props;
|
const { isNotificationSettingsOpen, isLoggedIn, username } = this.props;
|
||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
const token = await AppCenter.getInstallId();
|
const token = await AppCenter.getInstallId();
|
||||||
|
|
||||||
@ -219,6 +251,7 @@ class SettingsContainer extends Component {
|
|||||||
token,
|
token,
|
||||||
system: Platform.OS,
|
system: Platform.OS,
|
||||||
allows_notify: Number(isNotificationSettingsOpen),
|
allows_notify: Number(isNotificationSettingsOpen),
|
||||||
|
notify_types: notifyTypes,
|
||||||
};
|
};
|
||||||
setPushToken(data);
|
setPushToken(data);
|
||||||
}
|
}
|
||||||
@ -257,12 +290,13 @@ class SettingsContainer extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { serverList } = this.state;
|
const { serverList, isNotificationMenuOpen } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsScreen
|
<SettingsScreen
|
||||||
serverList={serverList}
|
serverList={serverList}
|
||||||
handleOnChange={this._handleOnChange}
|
handleOnChange={this._handleOnChange}
|
||||||
|
isNotificationMenuOpen={isNotificationMenuOpen}
|
||||||
handleOnButtonPress={this._handleButtonPress}
|
handleOnButtonPress={this._handleButtonPress}
|
||||||
{...this.props}
|
{...this.props}
|
||||||
/>
|
/>
|
||||||
@ -276,6 +310,13 @@ const mapStateToProps = state => ({
|
|||||||
isLoggedIn: state.application.isLoggedIn,
|
isLoggedIn: state.application.isLoggedIn,
|
||||||
isNotificationSettingsOpen: state.application.isNotificationOpen,
|
isNotificationSettingsOpen: state.application.isNotificationOpen,
|
||||||
nsfw: state.application.nsfw,
|
nsfw: state.application.nsfw,
|
||||||
|
notificationDetails: state.application.notificationDetails,
|
||||||
|
commentNotification: state.application.notificationDetails.commentNotification,
|
||||||
|
followNotification: state.application.notificationDetails.followNotification,
|
||||||
|
mentionNotification: state.application.notificationDetails.mentionNotification,
|
||||||
|
reblogNotification: state.application.notificationDetails.reblogNotification,
|
||||||
|
transfersNotification: state.application.notificationDetails.transfersNotification,
|
||||||
|
voteNotification: state.application.notificationDetails.voteNotification,
|
||||||
selectedApi: state.application.api,
|
selectedApi: state.application.api,
|
||||||
selectedCurrency: state.application.currency,
|
selectedCurrency: state.application.currency,
|
||||||
selectedLanguage: state.application.language,
|
selectedLanguage: state.application.language,
|
||||||
|
@ -13,9 +13,10 @@ import NSFW from '../../../constants/options/nsfw';
|
|||||||
// Components
|
// Components
|
||||||
import { BasicHeader } from '../../../components/basicHeader';
|
import { BasicHeader } from '../../../components/basicHeader';
|
||||||
import { SettingsItem } from '../../../components/settingsItem';
|
import { SettingsItem } from '../../../components/settingsItem';
|
||||||
|
import { CollapsibleCard } from '../../../components/collapsibleCard';
|
||||||
|
|
||||||
// Styles
|
// Styles
|
||||||
import globalStyles from '../../../globalStyles';
|
import styles from './settingsStyles';
|
||||||
|
|
||||||
class SettingsScreen extends PureComponent {
|
class SettingsScreen extends PureComponent {
|
||||||
/* Props
|
/* Props
|
||||||
@ -44,18 +45,32 @@ class SettingsScreen extends PureComponent {
|
|||||||
selectedCurrency,
|
selectedCurrency,
|
||||||
selectedLanguage,
|
selectedLanguage,
|
||||||
serverList,
|
serverList,
|
||||||
|
isNotificationMenuOpen,
|
||||||
|
commentNotification,
|
||||||
|
followNotification,
|
||||||
|
mentionNotification,
|
||||||
|
reblogNotification,
|
||||||
|
transfersNotification,
|
||||||
|
voteNotification,
|
||||||
handleOnButtonPress,
|
handleOnButtonPress,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={globalStyles.container}>
|
<Fragment>
|
||||||
<BasicHeader
|
<BasicHeader
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
id: 'settings.settings',
|
id: 'settings.settings',
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ScrollView style={globalStyles.settingsContainer}>
|
<ScrollView>
|
||||||
|
<View style={styles.settingsCard}>
|
||||||
|
<SettingsItem
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'settings.general',
|
||||||
|
})}
|
||||||
|
titleStyle={styles.cardTitle}
|
||||||
|
/>
|
||||||
<SettingsItem
|
<SettingsItem
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
id: 'settings.currency',
|
id: 'settings.currency',
|
||||||
@ -93,11 +108,9 @@ class SettingsScreen extends PureComponent {
|
|||||||
})}
|
})}
|
||||||
type="dropdown"
|
type="dropdown"
|
||||||
actionType="nsfw"
|
actionType="nsfw"
|
||||||
options={NSFW.map(item =>
|
options={NSFW.map(item => intl.formatMessage({
|
||||||
intl.formatMessage({
|
|
||||||
id: item,
|
id: item,
|
||||||
}),
|
}))}
|
||||||
)}
|
|
||||||
selectedOptionIndex={parseInt(nsfw, 10)}
|
selectedOptionIndex={parseInt(nsfw, 10)}
|
||||||
handleOnChange={handleOnChange}
|
handleOnChange={handleOnChange}
|
||||||
/>
|
/>
|
||||||
@ -112,24 +125,17 @@ class SettingsScreen extends PureComponent {
|
|||||||
/>
|
/>
|
||||||
<SettingsItem
|
<SettingsItem
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
id: 'settings.push_notification',
|
id: 'settings.send_feedback',
|
||||||
})}
|
})}
|
||||||
type="toggle"
|
text={intl.formatMessage({
|
||||||
actionType="notification"
|
id: 'settings.send',
|
||||||
isOn={isNotificationSettingsOpen}
|
})}
|
||||||
handleOnChange={handleOnChange}
|
type="button"
|
||||||
|
actionType="feedback"
|
||||||
|
handleOnButtonPress={handleOnButtonPress}
|
||||||
/>
|
/>
|
||||||
{!!isLoggedIn && (
|
{!!isLoggedIn && (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
{/* <SettingsItem
|
|
||||||
title={intl.formatMessage({
|
|
||||||
id: 'settings.default_footer',
|
|
||||||
})}
|
|
||||||
type="toggle"
|
|
||||||
actionType="default_footer"
|
|
||||||
isOn={isDefaultFooter}
|
|
||||||
handleOnChange={handleOnChange}
|
|
||||||
/> */}
|
|
||||||
<SettingsItem
|
<SettingsItem
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
id: 'settings.pincode',
|
id: 'settings.pincode',
|
||||||
@ -142,20 +148,97 @@ class SettingsScreen extends PureComponent {
|
|||||||
handleOnButtonPress={handleOnButtonPress}
|
handleOnButtonPress={handleOnButtonPress}
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
// <SettingsItem
|
||||||
|
// title={intl.formatMessage({
|
||||||
|
// id: 'settings.default_footer',
|
||||||
|
// })}
|
||||||
|
// type="toggle"
|
||||||
|
// actionType="default_footer"
|
||||||
|
// isOn={isDefaultFooter}
|
||||||
|
// handleOnChange={handleOnChange}
|
||||||
|
// />
|
||||||
)}
|
)}
|
||||||
|
</View>
|
||||||
|
{!!isLoggedIn && (
|
||||||
|
<View style={styles.settingsCard}>
|
||||||
|
<CollapsibleCard
|
||||||
|
titleComponent={(
|
||||||
<SettingsItem
|
<SettingsItem
|
||||||
title={intl.formatMessage({
|
title={intl.formatMessage({
|
||||||
id: 'settings.send_feedback',
|
id: 'settings.push_notification',
|
||||||
})}
|
})}
|
||||||
text={intl.formatMessage({
|
titleStyle={styles.cardTitle}
|
||||||
id: 'settings.send',
|
type="toggle"
|
||||||
})}
|
actionType="notification"
|
||||||
type="button"
|
isOn={isNotificationSettingsOpen}
|
||||||
actionType="feedback"
|
handleOnChange={handleOnChange}
|
||||||
handleOnButtonPress={handleOnButtonPress}
|
|
||||||
/>
|
/>
|
||||||
</ScrollView>
|
)}
|
||||||
|
noBorder
|
||||||
|
fitContent
|
||||||
|
locked
|
||||||
|
isExpanded={isNotificationSettingsOpen}
|
||||||
|
expanded={isNotificationMenuOpen}
|
||||||
|
>
|
||||||
|
<SettingsItem
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'settings.notification.follow',
|
||||||
|
})}
|
||||||
|
type="toggle"
|
||||||
|
actionType="notification.follow"
|
||||||
|
isOn={followNotification}
|
||||||
|
handleOnChange={handleOnChange}
|
||||||
|
/>
|
||||||
|
<SettingsItem
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'settings.notification.vote',
|
||||||
|
})}
|
||||||
|
type="toggle"
|
||||||
|
actionType="notification.vote"
|
||||||
|
isOn={voteNotification}
|
||||||
|
handleOnChange={handleOnChange}
|
||||||
|
/>
|
||||||
|
<SettingsItem
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'settings.notification.comment',
|
||||||
|
})}
|
||||||
|
type="toggle"
|
||||||
|
actionType="notification.comment"
|
||||||
|
isOn={commentNotification}
|
||||||
|
handleOnChange={handleOnChange}
|
||||||
|
/>
|
||||||
|
<SettingsItem
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'settings.notification.mention',
|
||||||
|
})}
|
||||||
|
type="toggle"
|
||||||
|
actionType="notification.mention"
|
||||||
|
isOn={mentionNotification}
|
||||||
|
handleOnChange={handleOnChange}
|
||||||
|
/>
|
||||||
|
<SettingsItem
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'settings.notification.reblog',
|
||||||
|
})}
|
||||||
|
type="toggle"
|
||||||
|
actionType="notification.reblog"
|
||||||
|
isOn={reblogNotification}
|
||||||
|
handleOnChange={handleOnChange}
|
||||||
|
/>
|
||||||
|
<SettingsItem
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'settings.notification.transfers',
|
||||||
|
})}
|
||||||
|
type="toggle"
|
||||||
|
actionType="notification.transfers"
|
||||||
|
isOn={transfersNotification}
|
||||||
|
handleOnChange={handleOnChange}
|
||||||
|
/>
|
||||||
|
</CollapsibleCard>
|
||||||
</View>
|
</View>
|
||||||
|
)}
|
||||||
|
</ScrollView>
|
||||||
|
</Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
src/screens/settings/screen/settingsStyles.js
Normal file
13
src/screens/settings/screen/settingsStyles.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import EStyleSheet from 'react-native-extended-stylesheet';
|
||||||
|
|
||||||
|
export default EStyleSheet.create({
|
||||||
|
settingsCard: {
|
||||||
|
backgroundColor: '$primaryBackgroundColor',
|
||||||
|
paddingLeft: 42,
|
||||||
|
paddingRight: 32,
|
||||||
|
marginVertical: 5,
|
||||||
|
},
|
||||||
|
cardTitle: {
|
||||||
|
color: '$primaryBlue',
|
||||||
|
},
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user