Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/development' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
LeGeek01 committed Mar 14, 2024
2 parents 292b581 + 65afdd3 commit 6040ce0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fetch/background/Grades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const notifyGrades = async (grades: PapillonGrades[]) => {
title: lastGrade.description ? getClosestGradeEmoji(lastGrade.subject.name) + ' ' + lastGrade.description : getClosestGradeEmoji(lastGrade.subject.name) + ' ' + 'Nouvelle note',
body: `Vous avez eu ${lastGrade.grade.value.value}/${lastGrade.grade.out_of.value} ${goodGrade ? '! 👏' : ''}`,
android: {
channelId: 'grades',
channelId: 'new-grade',
pressAction: {
id: 'default',
},
Expand Down
72 changes: 70 additions & 2 deletions fetch/background/Helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import notifee, { AuthorizationStatus } from '@notifee/react-native';
import notifee, { AuthorizationStatus, AndroidImportance } from '@notifee/react-native';
import { Platform } from 'react-native';

const getAllNotifs = async () => {
try {
Expand All @@ -25,7 +26,7 @@ const checkCanNotify = async (type = 'notificationsEnabled') => {
}

console.log('[background fetch] authorized:', authorized, 'canNotify:', canNotify, 'enabled:', enabled);

if(authorized) RegisterNotifChannel()
return authorized && canNotify && enabled;
};

Expand All @@ -44,6 +45,73 @@ const SetNotified = async (id: string) => {
}
};

const RegisterNotifChannel = async () => {
if(Platform.OS === "ios") return;
let groups = [
{
name: 'Nouvelles données disponibles',
description: 'Notifications en arrière-plan',
id: 'newdata-group'
},
{
name: 'Rappels',
description: 'Notifications de rappels',
id: 'remind-group'
},
{
name: 'Notifications silencieuses',
description: 'Notifications en arrière-plan',
id: 'silent-group'
}
]
let channels = [
{
id: 'silent',
groupId: 'silent-group',
name: 'Données en arrière-plan',
description: 'Notifie quand l\'application récupère les données en arrière-plan',
importance: AndroidImportance.LOW
},
{
name: 'Rappels de devoirs',
id: 'works-remind',
groupId: 'remind-group',
description: 'Notifications de rappels de devoirs',
importance: AndroidImportance.HIGH
},
{
name: 'Rappels de cours',
id: 'course-remind',
groupId: 'remind-group',
description: 'Notifications de rappels de cours (configurable dans l\'application)',
importance: AndroidImportance.HIGH
},
{
name: 'Modification de cours',
id: 'course-edit',
groupId: 'newdata-group',
description: 'Notifications de modification de cours (cours annulé, modifié, remplacement...)',
importance: AndroidImportance.HIGH
},
{
name: 'Nouvelles notes',
id: 'new-grade',
groupId: 'newdata-group',
description: 'Notifications d\'une nouvelle note',
importance: AndroidImportance.HIGH
},
{
name: 'Nouvelles actualités',
id: 'new-news',
groupId: 'newdata-group',
description: 'Indique quand une nouvelle actualité est disponible',
importance: AndroidImportance.HIGH
},
]
await notifee.createChannelGroups(groups)
await notifee.createChannels(channels)
}

export {
checkCanNotify,
DidNotified,
Expand Down
2 changes: 1 addition & 1 deletion fetch/background/Homeworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const notifyHomeworks = async (homeworks: PapillonHomework[]) => {
title: '📝 Travail à faire pour demain',
body: `Il vous reste ${countUndoneHomeworks} devoirs à faire pour demain.`,
android: {
channelId: 'homeworks',
channelId: 'works-remind',
},
ios: {
sound: 'papillon_ding.wav',
Expand Down
2 changes: 1 addition & 1 deletion fetch/background/Lessons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const notifyLessons = async (lessons: PapillonLesson[]) => {
subtitle: formatCoursName(lesson.subject?.name),
body: body,
android: {
channelId: 'getpapillon',
channelId: 'course-edit',
},
ios: {
sound: 'papillon_ding.wav',
Expand Down

0 comments on commit 6040ce0

Please sign in to comment.