diff --git a/native/chat/settings/thread-settings-push-notifs.react.js b/native/chat/settings/thread-settings-push-notifs.react.js --- a/native/chat/settings/thread-settings-push-notifs.react.js +++ b/native/chat/settings/thread-settings-push-notifs.react.js @@ -1,40 +1,25 @@ // @flow import * as React from 'react'; -import { Platform, Switch, TouchableOpacity, View } from 'react-native'; +import { Platform, TouchableOpacity, View } from 'react-native'; import Linking from 'react-native/Libraries/Linking/Linking.js'; -import { - updateSubscriptionActionTypes, - useUpdateSubscription, -} from 'lib/actions/user-actions.js'; import { extractKeyserverIDFromID } from 'lib/keyserver-conn/keyserver-call-utils.js'; import { deviceTokenSelector } from 'lib/selectors/keyserver-selectors.js'; +import { threadSettingsNotificationsCopy } from 'lib/shared/thread-settings-notifications-utils.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; -import type { - SubscriptionUpdateRequest, - SubscriptionUpdateResult, -} from 'lib/types/subscription-types.js'; -import { - type DispatchActionPromise, - useDispatchActionPromise, -} from 'lib/utils/redux-promise-utils.js'; +import type { ThreadSettingsNavigate } from './thread-settings.react.js'; +import EditSettingButton from '../../components/edit-setting-button.react.js'; import SingleLine from '../../components/single-line.react.js'; import SWMansionIcon from '../../components/swmansion-icon.react.js'; +import { ThreadSettingsNotificationsRouteName } from '../../navigation/route-names.js'; import { CommAndroidNotifications } from '../../push/android.js'; import { useSelector } from '../../redux/redux-utils.js'; import { useStyles } from '../../themes/colors.js'; import Alert from '../../utils/alert.js'; const unboundStyles = { - currentValue: { - alignItems: 'flex-end', - margin: 0, - paddingLeft: 4, - paddingRight: 0, - paddingVertical: 0, - }, label: { color: 'panelForegroundTertiaryLabel', fontSize: 16, @@ -47,81 +32,55 @@ paddingHorizontal: 24, paddingVertical: 3, }, - infoIcon: { - paddingRight: 20, - }, }; type BaseProps = { +threadInfo: ThreadInfo, + +navigate: ThreadSettingsNavigate, }; type Props = { ...BaseProps, // Redux state +styles: $ReadOnly, - // Redux dispatch functions - +dispatchActionPromise: DispatchActionPromise, - // async functions that hit server APIs +hasPushPermissions: boolean, - +updateSubscription: ( - subscriptionUpdate: SubscriptionUpdateRequest, - ) => Promise, }; -type State = { - +currentValue: boolean, -}; -class ThreadSettingsPushNotifs extends React.PureComponent { - constructor(props: Props) { - super(props); - this.state = { - currentValue: props.threadInfo.currentUser.subscription.pushNotifs, - }; - } - +class ThreadSettingsPushNotifs extends React.PureComponent { render(): React.Node { - const componentLabel = 'Push notifs'; - let notificationsSettingsLinkingIcon: React.Node = undefined; - if (!this.props.hasPushPermissions) { - notificationsSettingsLinkingIcon = ( + let componentLabel = threadSettingsNotificationsCopy.FOCUSED; + if (!this.props.threadInfo.currentUser.subscription.home) { + componentLabel = threadSettingsNotificationsCopy.BACKGROUND; + } else if (!this.props.threadInfo.currentUser.subscription.pushNotifs) { + componentLabel = threadSettingsNotificationsCopy.BADGE_ONLY; + } + + let editSettingsButton, notifSettingsLinkingButton; + if (this.props.hasPushPermissions) { + editSettingsButton = ( + + ); + } else { + notifSettingsLinkingButton = ( - - - + ); } + return ( {componentLabel} - {notificationsSettingsLinkingIcon} - - - + {editSettingsButton} + {notifSettingsLinkingButton} ); } - onValueChange = (value: boolean) => { - this.setState({ currentValue: value }); - void this.props.dispatchActionPromise( - updateSubscriptionActionTypes, - this.props.updateSubscription({ - threadID: this.props.threadInfo.id, - updatedFields: { - pushNotifs: value, - }, - }), - ); - }; - onNotificationsSettingsLinkingIconPress = async () => { let platformRequestsPermission; if (Platform.OS !== 'android') { @@ -140,7 +99,10 @@ : 'Settings → Apps → Comm → Notifications'; let alertMessage; - if (platformRequestsPermission && this.state.currentValue) { + if ( + platformRequestsPermission && + this.props.threadInfo.currentUser.subscription.pushNotifs + ) { alertMessage = 'Notifs for this chat are enabled, but cannot be delivered ' + 'to this device because you haven’t granted notif permissions to Comm. ' + @@ -169,6 +131,12 @@ }, ]); }; + + onPressEditThreadNotificationSettings = () => { + this.props.navigate(ThreadSettingsNotificationsRouteName, { + threadInfo: this.props.threadInfo, + }); + }; } const ConnectedThreadSettingsPushNotifs: React.ComponentType = @@ -180,14 +148,10 @@ const hasPushPermissions = deviceToken !== null && deviceToken !== undefined; const styles = useStyles(unboundStyles); - const dispatchActionPromise = useDispatchActionPromise(); - const callUpdateSubscription = useUpdateSubscription(); return ( ); diff --git a/native/chat/settings/thread-settings.react.js b/native/chat/settings/thread-settings.react.js --- a/native/chat/settings/thread-settings.react.js +++ b/native/chat/settings/thread-settings.react.js @@ -189,6 +189,7 @@ +itemType: 'pushNotifs', +key: string, +threadInfo: ResolvedThreadInfo, + +navigate: ThreadSettingsNavigate, } | { +itemType: 'homeNotifs', @@ -457,14 +458,15 @@ if (isMember) { listData.push({ itemType: 'header', - key: 'subscriptionHeader', - title: 'Subscription', + key: 'notificationsHeader', + title: 'Notifications', categoryType: 'full', }); listData.push({ itemType: 'pushNotifs', key: 'pushNotifs', threadInfo, + navigate, }); if (threadInfo.type !== threadTypes.SIDEBAR) { listData.push({ @@ -475,7 +477,7 @@ } listData.push({ itemType: 'footer', - key: 'subscriptionFooter', + key: 'notificationsFooter', categoryType: 'full', }); } @@ -995,7 +997,12 @@ } else if (item.itemType === 'visibility') { return ; } else if (item.itemType === 'pushNotifs') { - return ; + return ( + + ); } else if (item.itemType === 'homeNotifs') { return ; } else if (item.itemType === 'seeMore') { diff --git a/native/components/edit-setting-button.react.js b/native/components/edit-setting-button.react.js --- a/native/components/edit-setting-button.react.js +++ b/native/components/edit-setting-button.react.js @@ -9,27 +9,28 @@ type Props = { +onPress: () => void, - +canChangeSettings: boolean, + +canChangeSettings?: boolean, +style?: TextStyle, }; function EditSettingButton(props: Props): React.Node { + const { onPress, canChangeSettings = true, style } = props; const colors = useColors(); const appliedStyles = React.useMemo(() => { const stylesArr: Array = [styles.editIcon]; - if (props.style) { - stylesArr.push(props.style); + if (style) { + stylesArr.push(style); } return stylesArr; - }, [props.style]); + }, [style]); - if (!props.canChangeSettings) { + if (!canChangeSettings) { return null; } const { modalForegroundSecondaryLabel } = colors; return ( - +