-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifications.js
71 lines (54 loc) · 1.58 KB
/
notifications.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import Expo from 'expo-server-sdk';
const expo = new Expo();
const mongo = require('./mongoCommunication');
export const startTimer = (_uuid, _time) => {
console.log('Starting the timer');
setTimeout(() => { checkIn(_uuid); }, _time*60000);
}
const checkIn = (_uuid) => {
console.log('Stopping the timer');
mongo.getHookupDetails(_uuid)
.then((_response) => {
console.log('Hookup Details Claimed: ', _response);
if(_response.isHookingUp) {
console.log('Send check-in alert');
sendAlert(_response.expoTokens, _response.hookUpDetails.username);
} else {
console.log('Were not hooking up');
}
})
.catch((_error) => {
console.log('Hookup details could not be gotten.');
});
}
const sendAlert = (_tokenArray, _hookupName) => {
console.log('Send the alert');
//# TO-DO : only send to the one user
let notifications = [];
let message = 'You hooked up with ' + _hookupName + '. Let us know alls well.';
for (let pushToken of _tokenArray) {
if(!Expo.isExpoPushToken(pushToken)) {
console.log(`Push token ${pushToken} is not a valid Expo push token`);
continue;
}
notifications.push({
to: pushToken,
sound: 'default',
title: 'Carabiner',
body: message,
data: { message }
});
}
let chunks = expo.chunkPushNotifications(notifications);
console.log('preparing to send chunks');
(async () => {
for (let chunk of chunks) {
try {
let receipts = await expo.sendPushNotificationsAsync(chunk);
console.log(receipts);
} catch (error) {
console.error(error);
}
}
})();
}