notification job & EULA metode #36

Merged
bagasbanuna merged 3 commits from notification/9-jan-26 into staging 2026-01-09 17:48:42 +08:00
12 changed files with 86 additions and 60 deletions
Showing only changes of commit 33cd47aaed - Show all commits

View File

@@ -4,6 +4,7 @@ import {
onMessage, onMessage,
FirebaseMessagingTypes, FirebaseMessagingTypes,
} from "@react-native-firebase/messaging"; } from "@react-native-firebase/messaging";
import { useAuth } from "./use-auth";
// Gunakan tipe resmi dari library // Gunakan tipe resmi dari library
type RemoteMessage = FirebaseMessagingTypes.RemoteMessage; type RemoteMessage = FirebaseMessagingTypes.RemoteMessage;
@@ -11,17 +12,26 @@ type RemoteMessage = FirebaseMessagingTypes.RemoteMessage;
export function useForegroundNotifications( export function useForegroundNotifications(
onMessageReceived: (message: RemoteMessage) => void onMessageReceived: (message: RemoteMessage) => void
) { ) {
const { user } = useAuth();
useEffect(() => { useEffect(() => {
const messaging = getMessaging(); const messaging = getMessaging();
const unsubscribe = onMessage(messaging, (remoteMessage) => { const unsubscribe = onMessage(messaging, (remoteMessage) => {
const data = remoteMessage.data;
// console.log("DATA NOTIFIKASI DARI SERVER", data)
if (data?.recipientId && data?.recipientId !== user?.id) {
console.log("📵 Notification untuk user lain", data);
return;
}
console.log( console.log(
"🔔 Notifikasi diterima saat app aktif:", "🔔 Notifikasi diterima saat app aktif:",
JSON.stringify(remoteMessage, null, 2) JSON.stringify(data, null, 2)
); );
onMessageReceived(remoteMessage); onMessageReceived(remoteMessage);
}); });
return unsubscribe; return unsubscribe;
}, [onMessageReceived]); }, [user?.id, onMessageReceived]);
} }