diff --git a/app/reducers/troubleshootingNotification.test.ts b/app/reducers/troubleshootingNotification.test.ts index 83938d47d..00210a456 100644 --- a/app/reducers/troubleshootingNotification.test.ts +++ b/app/reducers/troubleshootingNotification.test.ts @@ -17,7 +17,7 @@ describe('test troubleshootingNotification reducer', () => { it('should return correctly value after call troubleshootingNotification action', () => { const payload: ITroubleshootingNotification = { deviceNotificationEnabled: true, - highlightTroubleshooting: false, + issuesWithNotifications: false, defaultPushGateway: true, pushGatewayEnabled: true, consumptionPercentage: 0, diff --git a/app/reducers/troubleshootingNotification.ts b/app/reducers/troubleshootingNotification.ts index 9da7bbf73..05fdda0cc 100644 --- a/app/reducers/troubleshootingNotification.ts +++ b/app/reducers/troubleshootingNotification.ts @@ -5,7 +5,7 @@ export interface ITroubleshootingNotification { deviceNotificationEnabled: boolean; pushGatewayEnabled: boolean; defaultPushGateway: boolean; - highlightTroubleshooting: boolean; + issuesWithNotifications: boolean; consumptionPercentage: number; isCommunityEdition: boolean; } @@ -14,7 +14,7 @@ export const initialState: ITroubleshootingNotification = { deviceNotificationEnabled: false, pushGatewayEnabled: false, defaultPushGateway: false, - highlightTroubleshooting: false, + issuesWithNotifications: false, consumptionPercentage: 0, isCommunityEdition: false }; diff --git a/app/sagas/troubleshootingNotification.ts b/app/sagas/troubleshootingNotification.ts index 30dbf7216..673119a29 100644 --- a/app/sagas/troubleshootingNotification.ts +++ b/app/sagas/troubleshootingNotification.ts @@ -1,7 +1,6 @@ import { Action } from 'redux'; -import { put, takeEvery } from 'redux-saga/effects'; -import { call } from 'typed-redux-saga'; -import notifee from '@notifee/react-native'; +import { call, takeLatest, put } from 'typed-redux-saga'; +import notifee, { AuthorizationStatus } from '@notifee/react-native'; import { TROUBLESHOOTING_NOTIFICATION } from '../actions/actionsTypes'; import { setTroubleshootingNotification } from '../actions/troubleshootingNotification'; @@ -20,32 +19,28 @@ function* request() { let defaultPushGateway = false; let pushGatewayEnabled = false; try { - const { authorizationStatus } = yield * call(notifee.getNotificationSettings); - deviceNotificationEnabled = authorizationStatus > 0; - const pushInfoResult = yield * call(pushInfo); + const { authorizationStatus } = yield* call(notifee.getNotificationSettings); + deviceNotificationEnabled = authorizationStatus > AuthorizationStatus.DENIED; + const pushInfoResult = yield* call(pushInfo); if (pushInfoResult.success) { pushGatewayEnabled = pushInfoResult.pushGatewayEnabled; defaultPushGateway = pushInfoResult.defaultPushGateway; } - // TODO: Need to request the information of push quota and if the server is a community edition } catch (e) { log(e); - } finally { - // If Any of the items that can have red values: notification settings, CE quota, or gateway connection; the red icon should show. - // Then highlightTroubleshooting has to be true - const highlightTroubleshooting = - !deviceNotificationEnabled || (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.6.0') && !pushGatewayEnabled); - yield put( - setTroubleshootingNotification({ - deviceNotificationEnabled, - defaultPushGateway, - pushGatewayEnabled, - highlightTroubleshooting - }) - ); } + const issuesWithNotifications = + !deviceNotificationEnabled || (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.6.0') && !pushGatewayEnabled); + yield put( + setTroubleshootingNotification({ + deviceNotificationEnabled, + defaultPushGateway, + pushGatewayEnabled, + issuesWithNotifications + }) + ); } export default function* root(): Generator { - yield takeEvery(TROUBLESHOOTING_NOTIFICATION.REQUEST, request); + yield takeLatest(TROUBLESHOOTING_NOTIFICATION.REQUEST, request); } diff --git a/app/views/RoomView/RightButtons.tsx b/app/views/RoomView/RightButtons.tsx index 0552c2bc8..e7c33b068 100644 --- a/app/views/RoomView/RightButtons.tsx +++ b/app/views/RoomView/RightButtons.tsx @@ -46,7 +46,7 @@ interface IRightButtonsProps extends Pick { rid?: string; theme?: TSupportedThemes; colors?: TColors; - highlightTroubleshooting: boolean; + issuesWithNotifications: boolean; disableNotifications?: boolean; } @@ -96,7 +96,7 @@ class RightButtonsContainer extends Component { const { room } = this; - const { rid, navigation, isMasterDetail, highlightTroubleshooting } = this.props; + const { rid, navigation, isMasterDetail, issuesWithNotifications } = this.props; if (!rid || !room) { return; } - if (!highlightTroubleshooting && room) { + if (!issuesWithNotifications && room) { if (isMasterDetail) { navigation.navigate('ModalStackNavigator', { screen: 'NotificationPrefView', @@ -361,7 +361,7 @@ class RightButtonsContainer extends Component - {highlightTroubleshooting || disableNotifications ? ( + {issuesWithNotifications || disableNotifications ? ( ({ threadsEnabled: state.settings.Threads_enabled as boolean, isMasterDetail: state.app.isMasterDetail, livechatRequestComment: state.settings.Livechat_request_comment_when_closing_conversation as boolean, - highlightTroubleshooting: state.troubleshootingNotification.highlightTroubleshooting + issuesWithNotifications: state.troubleshootingNotification.issuesWithNotifications }); export default connect(mapStateToProps)(withTheme(RightButtonsContainer)); diff --git a/app/views/RoomsListView/index.tsx b/app/views/RoomsListView/index.tsx index eb30cc153..343a2d8e2 100644 --- a/app/views/RoomsListView/index.tsx +++ b/app/views/RoomsListView/index.tsx @@ -92,7 +92,7 @@ interface IRoomsListViewProps { createPrivateChannelPermission: []; createDiscussionPermission: []; serverVersion: string; - highlightTroubleshooting: boolean; + issuesWithNotifications: boolean; } interface IRoomsListViewState { @@ -147,7 +147,7 @@ const shouldUpdateProps = [ 'createPublicChannelPermission', 'createPrivateChannelPermission', 'createDiscussionPermission', - 'highlightTroubleshooting', + 'issuesWithNotifications', 'supportedVersionsStatus' ]; @@ -335,7 +335,7 @@ class RoomsListView extends React.Component { const { searching, canCreateRoom } = this.state; - const { navigation, isMasterDetail, notificationPresenceCap, highlightTroubleshooting, supportedVersionsStatus, theme } = + const { navigation, isMasterDetail, notificationPresenceCap, issuesWithNotifications, supportedVersionsStatus, theme } = this.props; if (searching) { return { @@ -462,7 +462,7 @@ class RoomsListView extends React.Component , headerRight: () => ( - {highlightTroubleshooting ? ( + {issuesWithNotifications ? ( ({ createPrivateChannelPermission: state.permissions['create-p'], createDiscussionPermission: state.permissions['start-discussion'], serverVersion: state.server.version, - highlightTroubleshooting: state.troubleshootingNotification.highlightTroubleshooting + issuesWithNotifications: state.troubleshootingNotification.issuesWithNotifications }); export default connect(mapStateToProps)(withDimensions(withTheme(withSafeAreaInsets(RoomsListView))));