-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
67 lines (54 loc) · 2.16 KB
/
index.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
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendPostCommentNotification = functions.firestore
.document('CommentNotification/{doc_id}')
.onCreate((snap, context) => {
const newValue = snap.data();
const token = newValue.authorRegisterToken;
const commentToken = newValue.commentAuthorToken
const name = newValue.authorName
const comment = newValue.comment
const documentId = newValue.documentId
const commenterImage = newValue.authorImage
const countryCode = newValue.countryCode
const type = 'COMMENT'
const payload = {
data: {
title: name + " commented on your post on Social Note",
token: token,
commentAuthToken: commentToken,
comment: comment,
documentId: documentId,
countryCode:countryCode,
type : type
}
};
return admin.messaging().sendToDevice(token,payload).then(result => {
console.log("Notification sent!");
});
});
exports.sendPostLikeNotification = functions.firestore
.document('LikesNotification/{doc_id}')
.onCreate((snap, context) => {
const newValue = snap.data();
const authorToken = newValue.authorRegisterToken;
const userLikerToken = newValue.userRegisterToken
const name = newValue.userName
const documentId = newValue.documentId
const countryCode = newValue.countryCode
const type = 'LIKE'
const payload = {
data: {
title: name + " liked your post on Social Note",
authorToken: authorToken,
userLikerToken: userLikerToken,
documentId: documentId,
countryCode: countryCode,
type : type
}
};
return admin.messaging().sendToDevice(authorToken,payload).then(result => {
console.log("Notification sent!");
});
});