Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3392323
D3565.id10988.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D3565.id10988.diff
View Options
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
@@ -2,6 +2,8 @@
import * as React from 'react';
import { View, Switch } from 'react-native';
+import Alert from 'react-native/Libraries/Alert/Alert';
+import Linking from 'react-native/Libraries/Linking/Linking';
import {
updateSubscriptionActionTypes,
@@ -19,6 +21,7 @@
} from 'lib/utils/action-utils';
import { SingleLine } from '../../components/single-line.react';
+import { useSelector } from '../../redux/redux-utils';
import { useStyles } from '../../themes/colors';
type BaseProps = {
@@ -31,6 +34,7 @@
// Redux dispatch functions
+dispatchActionPromise: DispatchActionPromise,
// async functions that hit server APIs
+ +deviceToken: ?string,
+updateSubscription: (
subscriptionUpdate: SubscriptionUpdateRequest,
) => Promise<SubscriptionUpdateResult>,
@@ -55,7 +59,7 @@
</SingleLine>
<View style={this.props.styles.currentValue}>
<Switch
- value={this.state.currentValue}
+ value={this.state.currentValue && this.hasPushPermissions()}
onValueChange={this.onValueChange}
/>
</View>
@@ -64,17 +68,39 @@
}
onValueChange = (value: boolean) => {
- this.setState({ currentValue: value });
- this.props.dispatchActionPromise(
- updateSubscriptionActionTypes,
- this.props.updateSubscription({
- threadID: this.props.threadInfo.id,
- updatedFields: {
- pushNotifs: value,
+ if (this.hasPushPermissions()) {
+ this.setState({ currentValue: value });
+ this.props.dispatchActionPromise(
+ updateSubscriptionActionTypes,
+ this.props.updateSubscription({
+ threadID: this.props.threadInfo.id,
+ updatedFields: {
+ pushNotifs: value,
+ },
+ }),
+ );
+ return;
+ }
+ Alert.alert(
+ 'Need Notifications Permissions',
+ 'Comm needs notification permissions to show notifications from the thread!' +
+ ' Please enable them in Settings',
+ [
+ {
+ text: 'Go to application settings',
+ onPress: () => Linking.openSettings(),
},
- }),
+ {
+ text: 'Cancel',
+ style: 'cancel',
+ },
+ ],
);
};
+
+ hasPushPermissions(): boolean {
+ return this.props.deviceToken !== null;
+ }
}
const unboundStyles = {
@@ -104,12 +130,14 @@
const styles = useStyles(unboundStyles);
const dispatchActionPromise = useDispatchActionPromise();
const callUpdateSubscription = useServerCall(updateSubscription);
+ const deviceToken = useSelector(state => state.deviceToken);
return (
<ThreadSettingsPushNotifs
{...props}
styles={styles}
dispatchActionPromise={dispatchActionPromise}
updateSubscription={callUpdateSubscription}
+ deviceToken={deviceToken}
/>
);
},
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 1, 8:08 AM (19 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2604319
Default Alt Text
D3565.id10988.diff (3 KB)
Attached To
Mode
D3565: Deep-link user to applications settings when they try to enable notifications for a thread without notifications enabled globally for Comm application.
Attached
Detach File
Event Timeline
Log In to Comment