Merge pull request #879 from esteemapp/bugfix/866

created disable notificaiton when user logout
This commit is contained in:
uğur erdal 2019-05-30 20:21:09 +03:00 committed by GitHub
commit deb097d063
2 changed files with 33 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import { NavigationActions } from 'react-navigation';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import Push from 'appcenter-push'; import Push from 'appcenter-push';
import get from 'lodash/get'; import get from 'lodash/get';
import AppCenter from 'appcenter';
// Languages // Languages
import en from 'react-intl/locale-data/en'; import en from 'react-intl/locale-data/en';
@ -40,6 +41,7 @@ import {
} from '../../../realm/realm'; } from '../../../realm/realm';
import { getUser } from '../../../providers/steem/dsteem'; import { getUser } from '../../../providers/steem/dsteem';
import { switchAccount } from '../../../providers/steem/auth'; import { switchAccount } from '../../../providers/steem/auth';
import { setPushToken } from '../../../providers/esteem/esteem';
// Actions // Actions
import { import {
@ -333,11 +335,17 @@ class ApplicationContainer extends Component {
}; };
_logout = async () => { _logout = async () => {
const { otherAccounts, currentAccount, dispatch } = this.props; const {
otherAccounts,
currentAccount: { name, local },
dispatch,
} = this.props;
await removeUserData(currentAccount.name) await removeUserData(name)
.then(async () => { .then(async () => {
const _otherAccounts = otherAccounts.filter(user => user.username !== currentAccount.name); const _otherAccounts = otherAccounts.filter(user => user.username !== name);
this._enableNotification(name, false);
if (_otherAccounts.length > 0) { if (_otherAccounts.length > 0) {
const targetAccountUsername = _otherAccounts[0].username; const targetAccountUsername = _otherAccounts[0].username;
@ -349,12 +357,12 @@ class ApplicationContainer extends Component {
removePinCode(); removePinCode();
setAuthStatus({ isLoggedIn: false }); setAuthStatus({ isLoggedIn: false });
setExistUser(false); setExistUser(false);
if (currentAccount.local === AUTH_TYPE.STEEM_CONNECT) { if (local === AUTH_TYPE.STEEM_CONNECT) {
removeSCAccount(currentAccount.name); removeSCAccount(name);
} }
} }
dispatch(removeOtherAccount(currentAccount.name)); dispatch(removeOtherAccount(name));
dispatch(logoutDone()); dispatch(logoutDone());
}) })
.catch(err => { .catch(err => {
@ -367,6 +375,18 @@ class ApplicationContainer extends Component {
}); });
}; };
_enableNotification = async (username, isEnable) => {
const token = await AppCenter.getInstallId();
setPushToken({
username,
token,
system: Platform.OS,
allows_notify: Number(isEnable),
notify_types: [1, 2, 3, 4, 5, 6],
});
};
_switchAccount = async targetAccountUsername => { _switchAccount = async targetAccountUsername => {
const { dispatch } = this.props; const { dispatch } = this.props;

View File

@ -154,15 +154,15 @@ class SettingsScreen extends PureComponent {
<CollapsibleCard <CollapsibleCard
titleComponent={ titleComponent={
<SettingsItem <SettingsItem
title={intl.formatMessage({ title={intl.formatMessage({
id: 'settings.push_notification', id: 'settings.push_notification',
})} })}
titleStyle={styles.cardTitle} titleStyle={styles.cardTitle}
type="toggle" type="toggle"
actionType="notification" actionType="notification"
isOn={isNotificationSettingsOpen} isOn={isNotificationSettingsOpen}
handleOnChange={handleOnChange} handleOnChange={handleOnChange}
/> />
} }
noBorder noBorder
fitContent fitContent