@@ -7,7 +7,7 @@ import OpenNotification from 'react-native-open-notification';
7
7
8
8
import type { RouteProp } from '../react-navigation' ;
9
9
import type { AppNavigationProp } from '../nav/AppNavigator' ;
10
- import { useSelector } from '../react-redux' ;
10
+ import { useGlobalSelector , useSelector } from '../react-redux' ;
11
11
import { getAuth , getSettings } from '../selectors' ;
12
12
import SwitchRow from '../common/SwitchRow' ;
13
13
import Screen from '../common/Screen' ;
@@ -19,6 +19,10 @@ import { IconAlertTriangle } from '../common/Icons';
19
19
import type { LocalizableText } from '../types' ;
20
20
import { TranslationContext } from '../boot/TranslationProvider' ;
21
21
import { kWarningColor } from '../styles/constants' ;
22
+ import { getIdentities , getIdentity , getIsActiveAccount } from '../account/accountsSelectors' ;
23
+ import { getRealmName } from '../directSelectors' ;
24
+ import ZulipText from '../common/ZulipText' ;
25
+ import SettingsGroup from './SettingsGroup' ;
22
26
23
27
const {
24
28
ZLPConstants,
@@ -104,11 +108,22 @@ function openSystemNotificationSettings() {
104
108
}
105
109
}
106
110
107
- /** (NB this is a per-account screen -- these are per-account settings.) */
111
+ /**
112
+ * Notification settings with warnings when something seems wrong.
113
+ *
114
+ * Includes an area for per-account settings.
115
+ */
108
116
export default function NotificationsScreen ( props : Props ) : Node {
117
+ const { navigation } = props ;
118
+
109
119
const _ = useContext ( TranslationContext ) ;
110
120
111
121
const auth = useSelector ( getAuth ) ;
122
+ const identity = useSelector ( getIdentity ) ;
123
+ const otherAccounts = useGlobalSelector ( state =>
124
+ getIdentities ( state ) . filter ( identity_ => ! getIsActiveAccount ( state , identity_ ) ) ,
125
+ ) ;
126
+ const realmName = useSelector ( getRealmName ) ;
112
127
const offlineNotification = useSelector ( state => getSettings ( state ) . offlineNotification ) ;
113
128
const onlineNotification = useSelector ( state => getSettings ( state ) . onlineNotification ) ;
114
129
const streamNotification = useSelector ( state => getSettings ( state ) . streamNotification ) ;
@@ -166,6 +181,10 @@ export default function NotificationsScreen(props: Props): Node {
166
181
} ) ;
167
182
} , [ streamNotification , auth ] ) ;
168
183
184
+ const handleOtherAccountsPress = useCallback ( ( ) => {
185
+ navigation . push ( 'account-pick' ) ;
186
+ } , [ navigation ] ) ;
187
+
169
188
return (
170
189
< Screen title = "Notifications" >
171
190
< ServerPushSetupBanner isDismissable = { false } />
@@ -194,21 +213,34 @@ export default function NotificationsScreen(props: Props): Node {
194
213
} ) ( ) }
195
214
onPress = { handleSystemSettingsPress }
196
215
/>
197
- < SwitchRow
198
- label = "Notifications when offline"
199
- value = { offlineNotification }
200
- onValueChange = { handleOfflineNotificationChange }
201
- />
202
- < SwitchRow
203
- label = "Notifications when online"
204
- value = { onlineNotification }
205
- onValueChange = { handleOnlineNotificationChange }
206
- />
207
- < SwitchRow
208
- label = "Stream notifications"
209
- value = { streamNotification }
210
- onValueChange = { handleStreamNotificationChange }
211
- />
216
+ < SettingsGroup
217
+ title = { {
218
+ text : 'Notification settings for this account ({email} in {realmName}):' ,
219
+ values : {
220
+ email : < ZulipText style = { { fontWeight : 'bold' } } text = { identity . email } /> ,
221
+ realmName : < ZulipText style = { { fontWeight : 'bold' } } text = { realmName } /> ,
222
+ } ,
223
+ } }
224
+ >
225
+ < SwitchRow
226
+ label = "Notifications when offline"
227
+ value = { offlineNotification }
228
+ onValueChange = { handleOfflineNotificationChange }
229
+ />
230
+ < SwitchRow
231
+ label = "Notifications when online"
232
+ value = { onlineNotification }
233
+ onValueChange = { handleOnlineNotificationChange }
234
+ />
235
+ < SwitchRow
236
+ label = "Stream notifications"
237
+ value = { streamNotification }
238
+ onValueChange = { handleStreamNotificationChange }
239
+ />
240
+ </ SettingsGroup >
241
+ { otherAccounts . length > 0 && (
242
+ < NestedNavRow title = "Other accounts" onPress = { handleOtherAccountsPress } />
243
+ ) }
212
244
</ Screen >
213
245
) ;
214
246
}
0 commit comments