feat(notification): integrate expo-notifications for permission handling and deep linking
Some checks failed
Frontend CI / ota-android (push) Successful in 1m27s
Frontend CI / build-and-push-web (push) Has been cancelled
Frontend CI / build-android-apk (push) Has been cancelled

- 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:
lafay
2026-04-28 00:20:07 +08:00
parent 296e649fbb
commit b7ce9e3b9a
8 changed files with 188 additions and 137 deletions

View File

@@ -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;