forked from PapillonApp/papillon-v6
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'PapillonApp:development' into main
- Loading branch information
Showing
25 changed files
with
1,691 additions
and
3,070 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
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
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,40 @@ | ||
import notifee from '@notifee/react-native'; | ||
import {getContextValues} from '../../utils/AppContext'; | ||
import {checkCanNotify, DidNotified} from './Helper'; | ||
|
||
const SelfReminder = async () => { | ||
console.log('[background fetch] Running self reminder'); | ||
const now = new Date(); | ||
|
||
const canNotify: boolean = await checkCanNotify('notifications_BagReminderEnabled'); | ||
const didNotify: boolean = await DidNotified('hw_' + now.getTime()); | ||
if (!canNotify || didNotify) return; | ||
|
||
if (now.getHours() >= 8 && now.getHours() <= 10) { | ||
let dataInstance = await getContextValues().dataProvider; | ||
await dataInstance.getTimetable(now).then(async (timetable) => { | ||
console.log('[background fetch] fetched cours'); | ||
const cours = timetable.filter(cours => { | ||
if (cours.isCancelled) return false; | ||
if (cours.start.split('T')[0] !== now.toISOString().split('T')[0]) return false; | ||
return true; | ||
}); | ||
if (cours.length > 0) { | ||
await notifee.displayNotification({ | ||
id: 'self_' + now.getTime(), | ||
title: '🍽️ Pense à réserver le self !', | ||
body: 'Il est temps d\'aller réserver le self pour ce midi.', | ||
android: { | ||
channelId: 'self-remind', | ||
}, | ||
ios: { | ||
sound: 'papillon_ding.wav', | ||
threadId: 'notifications_SelfReminderEnabled', | ||
}, | ||
}); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
export default SelfReminder; |
Oops, something went wrong.