Skip to content

Commit c3d9a53

Browse files
authored
Merge pull request #108 from eurofurence/spike/notification-channels
add special notification channels to assign to messages
2 parents 03b4ef7 + 15cce82 commit c3d9a53

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

src/components/Managers/NotificationChannel.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,40 @@ import { captureNotificationException } from "../../sentryHelpers";
55

66
// Import globally at index, this code runs the method on import.
77

8+
export type NotificationChannels = "default" | "event_reminders" | "announcements" | "private_messages";
89
// Setup default channel.
910
setNotificationChannelAsync("default", {
10-
name: "default",
11+
name: "Miscellaneous",
1112
importance: Notifications.AndroidImportance.MIN,
1213
lightColor: "#006459",
1314
}).then(
14-
() => console.log("Assigned notification channel"),
15+
() => console.log("Assigned default notification channel"),
16+
(e) => captureNotificationException("Failed to assign notification channel:", e)
17+
);
18+
19+
setNotificationChannelAsync("event_reminders", {
20+
name: "Event Reminders",
21+
importance: Notifications.AndroidImportance.HIGH,
22+
lightColor: "#006459",
23+
}).then(
24+
() => console.log("Assigned Event Reminders notification channel"),
25+
(e) => captureNotificationException("Failed to assign notification channel:", e)
26+
);
27+
28+
setNotificationChannelAsync("announcements", {
29+
name: "Announcements",
30+
importance: Notifications.AndroidImportance.DEFAULT,
31+
lightColor: "#006459",
32+
}).then(
33+
() => console.log("Assigned Announcements notification channel"),
34+
(e) => captureNotificationException("Failed to assign notification channel:", e)
35+
);
36+
37+
setNotificationChannelAsync("private_messages", {
38+
name: "Private Messages",
39+
importance: Notifications.AndroidImportance.DEFAULT,
40+
lightColor: "#006459",
41+
}).then(
42+
() => console.log("Assigned Private Messages notification channel"),
1543
(e) => captureNotificationException("Failed to assign notification channel:", e)
1644
);

src/components/Managers/NotificationReceivedManager.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addNotificationReceivedListener, Notification, removeNotificationSubscription, scheduleNotificationAsync } from "expo-notifications";
1+
import { addNotificationReceivedListener, Notification, NotificationChannel, removeNotificationSubscription, scheduleNotificationAsync } from "expo-notifications";
22
import moment from "moment";
33
import { useEffect } from "react";
44

@@ -9,16 +9,19 @@ import { useAppDispatch } from "../../store";
99
import { logFCMMessage } from "../../store/background.slice";
1010
import { FirebaseNotificationTrigger, isTrigger, isTriggerWithData, isTriggerWithNotification } from "../../types/NotificationTrigger";
1111
import { useSynchronizer } from "../Synchronization/SynchronizationProvider";
12+
import { NotificationChannels } from "./NotificationChannel";
1213

13-
const scheduleNotificationFromTrigger = (source: FirebaseNotificationTrigger) =>
14+
const scheduleNotificationFromTrigger = (source: FirebaseNotificationTrigger, channelId: NotificationChannels = "default") =>
1415
scheduleNotificationAsync({
1516
identifier: source.remoteMessage.messageId ?? undefined,
1617
content: {
1718
title: source.remoteMessage.notification.title ?? undefined,
1819
body: source.remoteMessage.notification.body ?? undefined,
1920
data: source.remoteMessage.data,
2021
},
21-
trigger: null,
22+
trigger: {
23+
channelId,
24+
},
2225
});
2326

2427
/**
@@ -69,13 +72,13 @@ export const NotificationReceivedManager = () => {
6972
console.log("Synchronized for remote Sync request");
7073
} else if (event === "Announcement" && isTriggerWithNotification(trigger)) {
7174
// Schedule it.
72-
scheduleNotificationFromTrigger(trigger).then(
75+
scheduleNotificationFromTrigger(trigger, "announcements").then(
7376
() => console.log("Announcement scheduled"),
7477
(e) => captureNotificationException("Unable to schedule announcement", e)
7578
);
7679
} else if (event === "Notification" && isTriggerWithNotification(trigger)) {
7780
// Schedule it.
78-
scheduleNotificationFromTrigger(trigger).then(
81+
scheduleNotificationFromTrigger(trigger, "private_messages").then(
7982
() => console.log("Personal message scheduled"),
8083
(e) => captureNotificationException("Unable to schedule personal message", e)
8184
);

src/hooks/useEventReminder.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export const useEventReminder = (event: EventRecord) => {
2828
title: event.Title,
2929
subtitle: "This event is starting soon!",
3030
},
31-
trigger: scheduleDate.toDate(),
31+
trigger: {
32+
date: scheduleDate.toDate(),
33+
channelId: "event_reminders",
34+
},
3235
});
3336
}
3437

0 commit comments

Comments
 (0)