Skip to content

Commit 155c657

Browse files
committed
notifs: Allow token-registration manual retry from troubleshooting screen
1 parent 9087c62 commit 155c657

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

src/settings/NotifTroubleshootingScreen.js

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { RouteProp } from '../react-navigation';
1414
import type { AppNavigationProp } from '../nav/AppNavigator';
1515
import Screen from '../common/Screen';
1616
import { createStyleSheet } from '../styles';
17-
import { useGlobalSelector, useSelector } from '../react-redux';
17+
import { useDispatch, useGlobalSelector, useSelector } from '../react-redux';
1818
import {
1919
getAccounts,
2020
getGlobalSession,
@@ -29,7 +29,7 @@ import {
2929
getZulipFeatureLevel,
3030
tryGetActiveAccountState,
3131
} from '../account/accountsSelectors';
32-
import { showToast } from '../utils/info';
32+
import { showErrorAlert, showToast } from '../utils/info';
3333
import Input from '../common/Input';
3434
import ZulipButton from '../common/ZulipButton';
3535
import { identityOfAccount, keyOfIdentity } from '../account/accountMisc';
@@ -46,6 +46,8 @@ import isAppOwnDomain from '../isAppOwnDomain';
4646
import { openLinkWithUserPreference, openSystemNotificationSettings } from '../utils/openLink';
4747
import { getOwnUserRole, roleIsAtLeast } from '../permissionSelectors';
4848
import { Role } from '../api/permissionsTypes';
49+
import { initNotifications } from '../notification/notifTokens';
50+
import { ApiError } from '../api/apiErrors';
4951

5052
const {
5153
Notifications, // android
@@ -305,6 +307,7 @@ function useMailComposerIsAvailable(): boolean | null {
305307
*/
306308
export default function NotifTroubleshootingScreen(props: Props): React.Node {
307309
const _ = React.useContext(TranslationContext);
310+
const dispatch = useDispatch();
308311

309312
const settings = useGlobalSelector(getGlobalSettings);
310313

@@ -339,6 +342,28 @@ export default function NotifTroubleshootingScreen(props: Props): React.Node {
339342
[],
340343
);
341344

345+
const handlePressRetryRegister = React.useCallback(async () => {
346+
try {
347+
await dispatch(initNotifications());
348+
} catch (errorIllTyped) {
349+
const error: mixed = errorIllTyped; // https://github.com/facebook/flow/issues/2470
350+
351+
if (!(error instanceof Error)) {
352+
logging.error('Unexpected non-error thrown');
353+
}
354+
355+
let msg = undefined;
356+
if (error instanceof ApiError) {
357+
msg = _('The server said:\n\n{errorMessage}', {
358+
errorMessage: error.message,
359+
});
360+
} else if (error instanceof Error && error.message.length > 0) {
361+
msg = error.message;
362+
}
363+
showErrorAlert(_('Registration failed'), msg);
364+
}
365+
}, [_, dispatch]);
366+
342367
const reportJson = React.useMemo(() => jsonifyNotificationReport(report), [report]);
343368

344369
const handlePressCopy = React.useCallback(() => {
@@ -467,10 +492,29 @@ export default function NotifTroubleshootingScreen(props: Props): React.Node {
467492
break;
468493

469494
case NotificationProblem.TokenNotAcked: {
470-
// TODO: Could offer:
471-
// - Re-request registering token with server, and show if a/the
472-
// request hasn't completed
473-
alerts.push(genericAlert);
495+
invariant(
496+
report.registerPushTokenRequestsInProgress != null,
497+
'report.registerPushTokenRequestsInProgress missing for active account?',
498+
);
499+
const isInProgress = report.registerPushTokenRequestsInProgress > 0;
500+
alerts.push(
501+
<AlertItem
502+
bottomMargin
503+
text={{
504+
text: isInProgress
505+
? 'The Zulip server at {realm} has not yet registered your device token. A request is in progress.'
506+
: 'The Zulip server at {realm} has not yet registered your device token.',
507+
values: { realm: identity.realm.toString() },
508+
}}
509+
buttons={
510+
isInProgress
511+
? undefined
512+
: [{ id: 'retry', label: 'Retry', onPress: handlePressRetryRegister }]
513+
}
514+
/>,
515+
);
516+
517+
alerts.push(genericAlert); // Still point to support for good measure
474518
break;
475519
}
476520

static/translations/messages_en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
"Remind me later": "Remind me later",
7777
"The Zulip server at {realm} is not set up to deliver push notifications.": "The Zulip server at {realm} is not set up to deliver push notifications.",
7878
"The Zulip server at {realm} is not set up to deliver push notifications. Please contact your administrator.": "The Zulip server at {realm} is not set up to deliver push notifications. Please contact your administrator.",
79+
"The Zulip server at {realm} has not yet registered your device token. A request is in progress.": "The Zulip server at {realm} has not yet registered your device token. A request is in progress.",
80+
"The Zulip server at {realm} has not yet registered your device token.": "The Zulip server at {realm} has not yet registered your device token.",
81+
"Registration failed": "Registration failed",
82+
"Retry": "Retry",
7983
"Message not saved": "Message not saved",
8084
"Save message": "Save message",
8185
"Send message": "Send message",

0 commit comments

Comments
 (0)