feat(notification): integrate expo-notifications for permission handling and deep linking
- Add expo-notifications dependency and configure with JPush plugin - Request notification permission on app launch for iOS/Android - Handle notification taps to navigate to chat or notifications screen - Add UI to check and request system notification permission in settings - Refactor background sync: WebSocket disconnects in background, JPush handles push - Add checkNotificationPermission() and requestNotificationPermission() to jpushService
This commit is contained in:
@@ -128,6 +128,8 @@ function SessionGate({ children }: { children: React.ReactNode }) {
|
||||
|
||||
function NotificationBootstrap() {
|
||||
const appState = useRef<AppStateStatus>(AppState.currentState);
|
||||
const permissionRequested = useRef(false);
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const initNotifications = async () => {
|
||||
@@ -145,9 +147,24 @@ function NotificationBootstrap() {
|
||||
appState.current = nextAppState;
|
||||
});
|
||||
|
||||
// Listen for JPush notification taps
|
||||
// Listen for JPush notification taps — navigate to the relevant screen
|
||||
jpushService.onNotification((message) => {
|
||||
console.log('[NotificationBootstrap] JPush notification tapped:', message);
|
||||
console.log('[NotificationBootstrap] JPush notification:', message.notificationEventType, message);
|
||||
if (message.notificationEventType !== 'notificationOpened') return;
|
||||
|
||||
const extras = message.extras || {};
|
||||
const notifType = extras.notification_type || message.notificationType;
|
||||
|
||||
if (notifType === 'chat_message' && extras.conversation_id) {
|
||||
const isGroup = extras.conversation_type === 'group';
|
||||
router.push(
|
||||
`/chat/${encodeURIComponent(extras.conversation_id)}${
|
||||
isGroup ? '?isGroupChat=1' : extras.sender_id ? `?userId=${encodeURIComponent(extras.sender_id)}` : ''
|
||||
}`
|
||||
);
|
||||
} else {
|
||||
router.push('/messages/notifications');
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
@@ -155,7 +172,24 @@ function NotificationBootstrap() {
|
||||
};
|
||||
};
|
||||
|
||||
const requestPermissionOnLaunch = async () => {
|
||||
if (permissionRequested.current) return;
|
||||
permissionRequested.current = true;
|
||||
|
||||
if (Platform.OS === 'web') return;
|
||||
|
||||
try {
|
||||
const hasPermission = await jpushService.checkNotificationPermission();
|
||||
if (!hasPermission) {
|
||||
await jpushService.requestNotificationPermission();
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('[NotificationBootstrap] request permission on launch failed:', error);
|
||||
}
|
||||
};
|
||||
|
||||
initNotifications();
|
||||
requestPermissionOnLaunch();
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user