This repository has been archived by the owner on Aug 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feat/scolengo-ng
- Loading branch information
Showing
34 changed files
with
2,018 additions
and
853 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import {getContextValues} from '../../utils/AppContext'; | ||
import notifee from '@notifee/react-native'; | ||
import {PapillonLesson} from '../types/timetable'; | ||
import {checkCanNotify, DidNotified, SetNotified} from './Helper'; | ||
import formatCoursName from '../../utils/FormatCoursName'; | ||
|
||
const now = new Date(); | ||
|
||
const fetchCours = async () => { | ||
if (now.getHours() >= 18 && now.getHours() <= 20) { | ||
console.log('[background fetch] Running cours fetch'); | ||
const tomorrow = new Date(now); | ||
tomorrow.setDate(now.getDate() + 1); | ||
tomorrow.setHours(0, 0, 0, 0); | ||
const tommorowAsString = tomorrow.toISOString().split('T')[0]; | ||
let dataInstance = await getContextValues().dataProvider; | ||
await dataInstance.getTimetable(tomorrow).then(timetable => { | ||
console.log('[background fetch] fetched cours'); | ||
const cours = timetable.filter(cours => { | ||
if (cours.isCancelled) return false; | ||
if (cours.start.split('T')[0] !== tommorowAsString) return false; | ||
return true; | ||
}); | ||
if (cours.length > 0) { | ||
remindBag(cours); | ||
} | ||
}); | ||
} else { | ||
console.log('[background fetch] Skipping cours fetch'); | ||
} | ||
}; | ||
|
||
const remindBag = async (lesson: PapillonLesson[]) => { | ||
const tomorrow = new Date(now); | ||
tomorrow.setDate(now.getDate() + 1); | ||
tomorrow.setHours(0, 0, 0, 0); | ||
|
||
const canNotify: boolean = await checkCanNotify('notifications_BagReminderEnabled'); | ||
const didNotify: boolean = await DidNotified('hw_' + tomorrow.getTime()); | ||
if (!canNotify || didNotify) return; | ||
var body = ''; | ||
var isFirst = true; | ||
lesson.forEach(cours => { | ||
if (!body.includes(cours.subject)) { | ||
let start = new Date(cours.start); | ||
let end = new Date(cours.end); | ||
if (!isFirst) body += '\n'; | ||
isFirst = false; | ||
body += `${('0' + start.getHours()).slice(-2)}:${('0' + start.getMinutes()).slice(-2)} - ${('0' + end.getHours()).slice(-2)}:${('0' + end.getMinutes()).slice(-2)} • ${formatCoursName(cours.subject.name)}`; | ||
} | ||
}); | ||
await notifee.displayNotification({ | ||
id: 'hw_' + tomorrow.getTime(), | ||
title: '🎒 Il est temps de préparer votre sac pour demain !', | ||
body: body, | ||
android: { | ||
channelId: 'bag-remind', | ||
}, | ||
ios: { | ||
sound: 'papillon_ding.wav', | ||
threadId: 'notifications_BagReminderEnabled', | ||
}, | ||
}); | ||
await SetNotified('hw_' + tomorrow.getTime()); | ||
}; | ||
|
||
export default fetchCours; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.