Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding FCM Notifications #133

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

aarshad-devani
Copy link

@aarshad-devani aarshad-devani commented Dec 1, 2019

Adding base code for FCM Notifications

TODO
-Add UI Related code, currently window.alert has been shown
-need to replace firebaseConfig in firebase-messaging-sw.js and notifications.js
-use github variables for Firebase Config

@bhansa
Copy link
Contributor

bhansa commented Dec 1, 2019

Related #63

storageBucket: "pyconhyd.appspot.com",
messagingSenderId: "254977934750",
appId: "1:254977934750:web:9f1ad0357425e5718d828f"
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing brace here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.. sorry :(

@bhansa
Copy link
Contributor

bhansa commented Dec 1, 2019

@aarshad786 test in your local and push the final commit here for the preview.

@bhansa
Copy link
Contributor

bhansa commented Dec 1, 2019

@aarshad786 This looks good, thanks for implementing this 🎉 Please list out the keys/configuration which we have to update since as of now you are using your firebase creds.
@ananyo2012 @inovizz please add your comments.

Copy link
Member

@ananyo2012 ananyo2012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put some comments inline.

Few questions -

  • What kind of json data are we sending in payload to display. Can you specify the format here ?
  • I see the appendMessage function is commented out. Do you plan to add it to this PR or open a new PR for the UI ?
  • Will the app constantly listen to the firebase url. Will this have any impact on the general load on the website ?

importScripts("https://www.gstatic.com/firebasejs/7.5.0/firebase-app.js");
importScripts("https://www.gstatic.com/firebasejs/7.5.0/firebase-messaging.js");

const firebaseConfig = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicate code. Can you move it to a separate script and import the messaging variable from there ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for Firebase-messaging-sw which is basically a background listener all the messages coming in

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is lines 4-14 in this file and line 3-32 in notification.js is duplicte. Please move these lines to separate script and import the messaging variable in both places.

function showToken(currentToken) {
// Show token in console and UI.
const tokenElement = document.querySelector("#token");
!!tokenElement && (tokenElement.textContent = currentToken);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the double ! required here ? document.querySelector returns null if element isn't found

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converting to boolean value using !! to ensure that token exists.. This can be removed but becomes handy when debugging might be required

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so for that shouldn't you be storing !tokenElement in a separate variable and then use it here ? That's how you can debug the variable value for boolean.

if (!isTokenSentToServer()) {
console.log("Sending token to server...");
// TODO(developer): Send the current token to your server.
setTokenSentToServer(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are assuming here token is already sent to server ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token can be sent to server from here.. This will be great way to send targeted notifications rather sending to everyone

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. Can you mention same in the comment ?

assets/js/notifications.js Show resolved Hide resolved
assets/js/notifications.js Show resolved Hide resolved
);
// Show permission UI.
updateUIForPushPermissionRequired();
setTokenSentToServer(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line required ? As per my understanding "sentToServer" should be 1 and it gets set when resetUI() is called after getting permission. Why are we setting it to 0 after that using this function call ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are resetting the variable in storage... once the permission will be received the it is set back again... this is evident in updateUIForPushPermissionRequired() where requestPermission() is called

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this line appear before updateUIForPushPermissionRequired() in that case ?

@ananyo2012
Copy link
Member

Also it would be good if we can see how the notification looks in different devices i.e in web and the mobile PWA app.

@ananyo2012
Copy link
Member

@aarshad786 Let's leave the review comments for now since we need this ready by tomorrow. Just make sure the notification shows correctly. Work on a simple notification display. We need this ready by tomorrow.

@bhansa Can you follow up on this ?

@bhansa
Copy link
Contributor

bhansa commented Dec 9, 2019

Due to time constraint, we were not able to add it in the pyconf website. We will be using this template for HydPy for meetup alerts and future conference websites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants