Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3568471
D12665.id.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.id.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,55 @@
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> {
- constructor(props: Props) {
- super(props);
- this.state = {
- currentValue: props.threadInfo.currentUser.subscription.pushNotifs,
- };
- }
-
+class ThreadSettingsPushNotifs extends React.PureComponent<Props> {
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 = (
+ <EditSettingButton
+ onPress={this.onPressEditThreadNotificationSettings}
+ />
+ );
+ } else {
+ notifSettingsLinkingButton = (
<TouchableOpacity
onPress={this.onNotificationsSettingsLinkingIconPress}
>
- <View style={this.props.styles.infoIcon}>
- <SWMansionIcon name="info-circle" size={25} color="gray" />
- </View>
+ <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>
+ {editSettingsButton}
+ {notifSettingsLinkingButton}
</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 +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<BaseProps> =
@@ -180,14 +148,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,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 <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
Sat, Dec 28, 10:50 PM (3 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2729572
Default Alt Text
D12665.id.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