Skip to content

Commit

Permalink
first to Dan
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCarstens committed Aug 12, 2018
1 parent 9a1847e commit f61a7e0
Show file tree
Hide file tree
Showing 19 changed files with 978 additions and 592 deletions.
5 changes: 2 additions & 3 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"projects": {
"default": "feedlyapp-9df9a",
"Thomax": "myapp-93470"
"default": "myapp-93470"
}
}
}
40 changes: 0 additions & 40 deletions GoogleService-Info.plist

This file was deleted.

13 changes: 7 additions & 6 deletions config.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.samarth.feedly" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Feedly</name>
<description>An awesome Ionic/Cordova app.</description>
<?xml version='2' encoding='utf-8'?>
<widget id="com.angularfirebase.dynamicsapp" version="0.0.2" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Dynamics App</name>
<description>Learning done better</description>
<author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
<content src="index.html" />
<access origin="*" />
Expand Down Expand Up @@ -85,8 +85,9 @@
<plugin name="cordova-plugin-ionic-keyboard" spec="2.0.5" />
<plugin name="cordova-plugin-camera" spec="~4.0.3" />
<plugin name="cordova-plugin-firebase" spec="^1.0.5" />
<plugin name="cordova-plugin-statusbar" spec="^2.4.2" />
<allow-navigation href="http://196.42.83.63:8100" />
<engine name="ios" spec="4.5.4" />
<engine name="android" spec="7.0.0" />
<engine name="android" spec="7.1.0" />
<engine name="browser" spec="5.0.4" />
<plugin name="cordova-plugin-statusbar" spec="^2.4.2" />
</widget>
6 changes: 6 additions & 0 deletions database.rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rules": {
".read": true,
".write": true
}
}
16 changes: 15 additions & 1 deletion firebase.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
{
"functions": {
"predeploy": [
"predeploy": [],
"source": "functions"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
18 changes: 18 additions & 0 deletions firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"indexes": [
{
"collectionId": "comments",
"state": "READY",
"fields": [
{
"fieldPath": "post",
"mode": "ASCENDING"
},
{
"fieldPath": "created",
"mode": "ASCENDING"
}
]
}
]
}
7 changes: 7 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
22 changes: 18 additions & 4 deletions functions/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 24 additions & 25 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions functions/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
Expand All @@ -11,12 +10,11 @@
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "~5.12.1",
"firebase-functions": "^1.0.3"
"firebase-admin": "~5.13.0",
"firebase-functions": "^2.0.0"
},
"devDependencies": {
"tslint": "^5.8.0",
"typescript": "^2.5.3"
"typescript": "~2.8.3"
},
"private": true
}
39 changes: 33 additions & 6 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as admin from 'firebase-admin';

admin.initializeApp(functions.config().firebase);

const sendNotification = (owner_uid, type) => {
exports.sendNotifications = (owner_uid, type) => {

return new Promise((resolve, reject) => {
return admin.firestore().collection("users").doc(owner_uid).get().then((doc) => {
Expand Down Expand Up @@ -35,6 +35,20 @@ const sendNotification = (owner_uid, type) => {
});
}

} else if(type === "new_post"){
admin.messaging().sendToDevice(doc.data().token, {
data: {
title: "Someone posted on Feedly.",
sound: "default",
body: "Tap to Check"
}
}).then((sent) => {
resolve(sent)
}).catch((err) => {
reject(err)
});
}

}
})
})
Expand All @@ -44,7 +58,7 @@ const sendNotification = (owner_uid, type) => {

}

export const updateLikesCount = functions.https.onRequest((request, response) => {
exports.updateLikesCount = functions.https.onRequest((request, response) => {

console.log(request.body);

Expand All @@ -67,10 +81,11 @@ export const updateLikesCount = functions.https.onRequest((request, response) =>
updateData[`likes.${userId}`] = false;
}

admin.firestore().collection("posts").doc(postId).update(updateData).then(async () => {
admin.firestore().collection("posts").doc(postId).update(updateData)
.then(async () => {

if(action == "like"){
await sendNotification(data.data().owner, "new_like");
await sendNotifications(data.data().owner, "new_like");
}

response.status(200).send("Done")
Expand All @@ -84,7 +99,7 @@ export const updateLikesCount = functions.https.onRequest((request, response) =>

})

export const updateCommentsCount = functions.firestore.document('comments/{commentId}').onCreate(async (event) => {
exports.updateCommentsCount = functions.firestore.document('comments/{commentId}').onCreate(async (event) => {
let data = event.data();

let postId = data.post;
Expand All @@ -99,9 +114,21 @@ export const updateCommentsCount = functions.firestore.document('comments/{comme
"commentsCount": commentsCount
})

return sendNotification(doc.data().owner, "new_comment");;
return sendNotifications(doc.data().owner, "new_comment");;

} else {
return false;
}
})

exports.PostNotif = functions.firestore.document('posts/{postId}').onCreate((event) => __awaiter(this, void 0, void 0, function* () {
let data = event.data();
let postId = data.post;
let doc = yield admin.firestore().collection("posts").doc(postId).get();
if (doc.exists) {
return sendNotifications(doc.data().owner, "new_post");
}
else {
return false;
}
}));
Loading

0 comments on commit f61a7e0

Please sign in to comment.