upd: notifikasi diskusi umum

This commit is contained in:
2025-08-06 11:58:54 +08:00
parent 1e2069ca42
commit 5db712d4b9
2 changed files with 34 additions and 4 deletions

View File

@@ -13,8 +13,9 @@ import { apiReadOneNotification } from "@/lib/api";
import { pushToPage } from "@/lib/pushToPage";
import store from "@/lib/store";
import { useAuthSession } from "@/providers/AuthProvider";
import AsyncStorage from "@react-native-async-storage/async-storage";
import firebase from '@react-native-firebase/app';
import { Redirect, router, Stack } from "expo-router";
import { Redirect, router, Stack, usePathname } from "expo-router";
import { StatusBar } from 'expo-status-bar';
import { useEffect } from "react";
import { Easing, Notifier } from 'react-native-notifier';
@@ -22,6 +23,7 @@ import { Provider } from "react-redux";
export default function RootLayout() {
const { token, decryptToken, isLoading } = useAuthSession()
const pathname = usePathname()
async function handleReadNotification(id: string, category: string, idContent: string) {
try {
@@ -33,12 +35,30 @@ export default function RootLayout() {
}
}
useEffect(() => {
const checkNavigation = async () => {
const navData = await AsyncStorage.getItem('navigateOnOpen');
if (navData) {
const { screen, content } = JSON.parse(navData);
await AsyncStorage.removeItem('navigateOnOpen'); // reset
pushToPage(screen, content)
}
};
checkNavigation();
}, []);
useEffect(() => {
const unsubscribe = firebase.app().messaging().onMessage(async remoteMessage => {
const id = remoteMessage?.data?.id;
const category = remoteMessage?.data?.category;
const content = remoteMessage?.data?.content;
if (remoteMessage.notification != undefined && remoteMessage.notification.title != undefined && remoteMessage.notification.body != undefined) {
if (
remoteMessage.notification != undefined &&
remoteMessage.notification.title != undefined &&
remoteMessage.notification.body != undefined &&
pathname != `/${category}/${content}`
) {
Notifier.showNotification({
title: remoteMessage.notification?.title,
description: remoteMessage.notification?.body,