Fixed notification disable issue #1134 #1165

This commit is contained in:
Mustafa Buyukcelebi 2019-11-01 13:32:48 +03:00
parent 9bfc5d9d87
commit e6eb234d84
2 changed files with 29 additions and 27 deletions

View File

@ -359,12 +359,7 @@ class PostsView extends Component {
render() { render() {
const { refreshing, posts, isShowFilterBar } = this.state; const { refreshing, posts, isShowFilterBar } = this.state;
const { const { filterOptions, selectedOptionIndex, isHideImage, handleImagesHide } = this.props;
filterOptions,
selectedOptionIndex,
isHideImage,
handleImagesHide,
} = this.props;
return ( return (
<View style={styles.container}> <View style={styles.container}>

View File

@ -236,21 +236,23 @@ class SettingsContainer extends Component {
dispatch(changeNotificationSettings({ action, type: actionType })); dispatch(changeNotificationSettings({ action, type: actionType }));
setNotificationSettings({ action, type: actionType }); setNotificationSettings({ action, type: actionType });
if (actionType === 'notification') { Object.keys(notificationDetails).map(item => {
await Push.setEnabled(action); const notificationType = item.replace('Notification', '');
this._setPushToken(action ? [1, 2, 3, 4, 5, 6] : notifyTypes);
} else {
Object.keys(notificationDetails).map(item => {
const notificationType = item.replace('Notification', '');
if (notificationType === actionType.replace('notification.', '')) { if (notificationType === actionType.replace('notification.', '')) {
if (action) { if (action) {
notifyTypes.push(notifyTypesConst[notificationType]);
}
} else if (notificationDetails[item]) {
notifyTypes.push(notifyTypesConst[notificationType]); notifyTypes.push(notifyTypesConst[notificationType]);
} }
}); } else if (notificationDetails[item]) {
notifyTypes.push(notifyTypesConst[notificationType]);
}
});
notifyTypes.sort();
if (actionType === 'notification') {
await Push.setEnabled(action);
this._setPushToken(action ? notifyTypes : []);
} else {
this._setPushToken(notifyTypes); this._setPushToken(notifyTypes);
} }
}; };
@ -286,21 +288,25 @@ class SettingsContainer extends Component {
}; };
_setPushToken = async notifyTypes => { _setPushToken = async notifyTypes => {
const { isNotificationSettingsOpen, isLoggedIn, username } = this.props; const { isLoggedIn, otherAccounts = [] } = this.props;
if (isLoggedIn) { if (isLoggedIn) {
const token = await AppCenter.getInstallId(); const token = await AppCenter.getInstallId();
getExistUser().then(isExistUser => { getExistUser().then(isExistUser => {
if (isExistUser) { if (isExistUser) {
const data = { otherAccounts.forEach(item => {
username, const { isNotificationSettingsOpen } = this.props;
token,
system: Platform.OS, const data = {
allows_notify: Number(isNotificationSettingsOpen), username: item.username,
notify_types: notifyTypes, token,
}; system: Platform.OS,
setPushToken(data); allows_notify: Number(isNotificationSettingsOpen),
notify_types: notifyTypes,
};
setPushToken(data);
});
} }
}); });
} }
@ -401,6 +407,7 @@ const mapStateToProps = state => ({
username: state.account.currentAccount && state.account.currentAccount.name, username: state.account.currentAccount && state.account.currentAccount.name,
currentAccount: state.account.currentAccount, currentAccount: state.account.currentAccount,
otherAccounts: state.account.otherAccounts,
}); });
export default injectIntl(connect(mapStateToProps)(SettingsContainer)); export default injectIntl(connect(mapStateToProps)(SettingsContainer));