Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for external links #11466

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions app/util/notifications/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ import { useCallback, useEffect } from 'react';
import { NavigationProp, ParamListBase } from '@react-navigation/native';
import NotificationsService from '../../../util/notifications/services/NotificationService';
import Routes from '../../../constants/navigation/Routes';
import { isNotificationsFeatureEnabled } from '../../../util/notifications';
import {
isNotificationsFeatureEnabled,
TRIGGER_TYPES,
} from '../../../util/notifications';
import { Notification } from '../../../util/notifications/types';
import { Linking } from 'react-native';

const useNotificationHandler = (navigation: NavigationProp<ParamListBase>) => {
const performActionBasedOnOpenedNotificationType = useCallback(
async (notification: Notification) => {
navigation.navigate(Routes.NOTIFICATIONS.DETAILS, {
notificationId: notification.id,
});
if (
notification.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT &&
notification.data.externalLink
) {
Linking.openURL(notification.data.externalLink.externalLinkUrl);
} else {
navigation.navigate(Routes.NOTIFICATIONS.DETAILS, {
notificationId: notification.id,
});
}
},
[navigation],
);
Expand All @@ -29,22 +40,22 @@ const useNotificationHandler = (navigation: NavigationProp<ParamListBase>) => {
if (!isNotificationsFeatureEnabled()) return;

const unsubscribeForegroundEvent = NotificationsService.onForegroundEvent(
async ({ type, detail }) => {
async ({ type, detail }) =>
await NotificationsService.handleNotificationEvent({
type,
detail,
callback: handlePressedNotification,
});
},
}),
);

NotificationsService.onBackgroundEvent(async ({ type, detail }) => {
await NotificationsService.handleNotificationEvent({
type,
detail,
callback: handlePressedNotification,
});
});
NotificationsService.onBackgroundEvent(
async ({ type, detail }) =>
await NotificationsService.handleNotificationEvent({
type,
detail,
callback: handlePressedNotification,
}),
);

return () => {
unsubscribeForegroundEvent();
Expand Down
2 changes: 1 addition & 1 deletion app/util/notifications/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class NotificationsService {
await this.cancelTriggerNotification(detail.notification.id);
}

if (detail?.notification?.data?.url) {
if (detail?.notification?.data) {
callback?.(detail.notification as Notification);
}
};
Expand Down
Loading