From e6eb234d849dfa06e8ad72dec70d4cf98f7d12a7 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Fri, 1 Nov 2019 13:32:48 +0300 Subject: [PATCH] Fixed notification disable issue #1134 #1165 --- src/components/posts/view/postsView.js | 7 +-- .../settings/container/settingsContainer.js | 49 +++++++++++-------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/components/posts/view/postsView.js b/src/components/posts/view/postsView.js index 28d7985fc..155c67f09 100644 --- a/src/components/posts/view/postsView.js +++ b/src/components/posts/view/postsView.js @@ -359,12 +359,7 @@ class PostsView extends Component { render() { const { refreshing, posts, isShowFilterBar } = this.state; - const { - filterOptions, - selectedOptionIndex, - isHideImage, - handleImagesHide, - } = this.props; + const { filterOptions, selectedOptionIndex, isHideImage, handleImagesHide } = this.props; return ( diff --git a/src/screens/settings/container/settingsContainer.js b/src/screens/settings/container/settingsContainer.js index 2d74babcc..9a6feb5ef 100644 --- a/src/screens/settings/container/settingsContainer.js +++ b/src/screens/settings/container/settingsContainer.js @@ -236,21 +236,23 @@ class SettingsContainer extends Component { dispatch(changeNotificationSettings({ action, type: actionType })); setNotificationSettings({ action, type: actionType }); - 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', ''); + Object.keys(notificationDetails).map(item => { + const notificationType = item.replace('Notification', ''); - if (notificationType === actionType.replace('notification.', '')) { - if (action) { - notifyTypes.push(notifyTypesConst[notificationType]); - } - } else if (notificationDetails[item]) { + if (notificationType === actionType.replace('notification.', '')) { + if (action) { 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); } }; @@ -286,21 +288,25 @@ class SettingsContainer extends Component { }; _setPushToken = async notifyTypes => { - const { isNotificationSettingsOpen, isLoggedIn, username } = this.props; + const { isLoggedIn, otherAccounts = [] } = this.props; if (isLoggedIn) { const token = await AppCenter.getInstallId(); getExistUser().then(isExistUser => { if (isExistUser) { - const data = { - username, - token, - system: Platform.OS, - allows_notify: Number(isNotificationSettingsOpen), - notify_types: notifyTypes, - }; - setPushToken(data); + otherAccounts.forEach(item => { + const { isNotificationSettingsOpen } = this.props; + + const data = { + username: item.username, + token, + system: Platform.OS, + allows_notify: Number(isNotificationSettingsOpen), + notify_types: notifyTypes, + }; + setPushToken(data); + }); } }); } @@ -401,6 +407,7 @@ const mapStateToProps = state => ({ username: state.account.currentAccount && state.account.currentAccount.name, currentAccount: state.account.currentAccount, + otherAccounts: state.account.otherAccounts, }); export default injectIntl(connect(mapStateToProps)(SettingsContainer));