Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3358276
D12665.id42000.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
D12665.id42000.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
@@ -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,49 @@
paddingHorizontal: 24,
paddingVertical: 3,
},
- infoIcon: {
- paddingRight: 20,
- },
};
type BaseProps = {
+threadInfo: ThreadInfo,
+ +navigate: ThreadSettingsNavigate,
};
type Props = {
...BaseProps,
// Redux state
+styles: $ReadOnly<typeof unboundStyles>,
- // Redux dispatch functions
- +dispatchActionPromise: DispatchActionPromise,
- // async functions that hit server APIs
+hasPushPermissions: boolean,
- +updateSubscription: (
- subscriptionUpdate: SubscriptionUpdateRequest,
- ) => Promise<SubscriptionUpdateResult>,
-};
-type State = {
- +currentValue: boolean,
};
-class ThreadSettingsPushNotifs extends React.PureComponent<Props, State> {
+class ThreadSettingsPushNotifs extends React.PureComponent<Props> {
constructor(props: Props) {
super(props);
- this.state = {
- currentValue: props.threadInfo.currentUser.subscription.pushNotifs,
- };
}
render(): React.Node {
- const componentLabel = 'Push notifs';
- let notificationsSettingsLinkingIcon: React.Node = undefined;
- if (!this.props.hasPushPermissions) {
- notificationsSettingsLinkingIcon = (
- <TouchableOpacity
- onPress={this.onNotificationsSettingsLinkingIconPress}
- >
- <View style={this.props.styles.infoIcon}>
- <SWMansionIcon name="info-circle" size={25} color="gray" />
- </View>
- </TouchableOpacity>
- );
+ 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;
}
+
+ const button = this.props.hasPushPermissions ? (
+ <EditSettingButton onPress={this.onPressEditThreadNotificationSettings} />
+ ) : (
+ <TouchableOpacity onPress={this.onNotificationsSettingsLinkingIconPress}>
+ <SWMansionIcon name="info-circle" size={20} color="gray" />
+ </TouchableOpacity>
+ );
+
return (
<View style={this.props.styles.row}>
<SingleLine style={this.props.styles.label} adjustsFontSizeToFit={true}>
{componentLabel}
</SingleLine>
- {notificationsSettingsLinkingIcon}
- <View style={this.props.styles.currentValue}>
- <Switch
- value={this.state.currentValue}
- onValueChange={this.onValueChange}
- disabled={!this.props.hasPushPermissions}
- />
- </View>
+ {button}
</View>
);
}
- 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 +93,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 +125,12 @@
},
]);
};
+
+ onPressEditThreadNotificationSettings = () => {
+ this.props.navigate(ThreadSettingsNotificationsRouteName, {
+ threadInfo: this.props.threadInfo,
+ });
+ };
}
const ConnectedThreadSettingsPushNotifs: React.ComponentType<BaseProps> =
@@ -180,14 +142,10 @@
const hasPushPermissions =
deviceToken !== null && deviceToken !== undefined;
const styles = useStyles(unboundStyles);
- const dispatchActionPromise = useDispatchActionPromise();
- const callUpdateSubscription = useUpdateSubscription();
return (
<ThreadSettingsPushNotifs
{...props}
styles={styles}
- dispatchActionPromise={dispatchActionPromise}
- updateSubscription={callUpdateSubscription}
hasPushPermissions={hasPushPermissions}
/>
);
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,11 +189,7 @@
+itemType: 'pushNotifs',
+key: string,
+threadInfo: ResolvedThreadInfo,
- }
- | {
- +itemType: 'homeNotifs',
- +key: string,
- +threadInfo: ResolvedThreadInfo,
+ +navigate: ThreadSettingsNavigate,
}
| {
+itemType: 'seeMore',
@@ -457,14 +453,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 +472,7 @@
}
listData.push({
itemType: 'footer',
- key: 'subscriptionFooter',
+ key: 'notificationsFooter',
categoryType: 'full',
});
}
@@ -995,7 +992,12 @@
} else if (item.itemType === 'visibility') {
return <ThreadSettingsVisibility threadInfo={item.threadInfo} />;
} else if (item.itemType === 'pushNotifs') {
- return <ThreadSettingsPushNotifs threadInfo={item.threadInfo} />;
+ return (
+ <ThreadSettingsPushNotifs
+ threadInfo={item.threadInfo}
+ navigate={item.navigate}
+ />
+ );
} else if (item.itemType === 'homeNotifs') {
return <ThreadSettingsHomeNotifs threadInfo={item.threadInfo} />;
} 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<TextStyle> = [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 (
- <TouchableOpacity onPress={props.onPress}>
+ <TouchableOpacity onPress={onPress}>
<SWMansionIcon
name="edit-1"
size={20}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 3:54 AM (20 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2578269
Default Alt Text
D12665.id42000.diff (9 KB)
Attached To
Mode
D12665: [native] update ThreadSettingsPushNotifs to use new thread notifs settings experience
Attached
Detach File
Event Timeline
Log In to Comment