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

Icons and click action in the service worker. #37

Closed
wants to merge 0 commits into from

Conversation

JLucasRS
Copy link

Notifications now can show icons and open urls when clicked, if provided in the payload from the sever side.

body = data.body,
icon = data.icon;
// Url needs to be acessed from outside this method.
url = data.url
Copy link
Owner

Choose a reason for hiding this comment

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

Can you fix the indent?

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean, do this?

    body = data.body,
    icon = data.icon,
    url = data.url;

url would be undefined in the notificationonclick if I do that. Maybe because I'm creating a new variable or something? I don't know. Anyway, in the pull, the indent is in the same level than the payload, with makes more sense.

@safwanrahman
Copy link
Owner

Thanks a lot for your PR!
Can you please change the ReadMe as well?
Also make the backend changes?

@JLucasRS
Copy link
Author

I will try to change the Readme tomorrow, because i need to go to college right now.

@JLucasRS
Copy link
Author

I changed the Readme and the SW can handle missing urls and/or icons in the payload.

});

self.addEventListener('notificationclick', function (event) {
Copy link
Owner

@safwanrahman safwanrahman May 13, 2018

Choose a reason for hiding this comment

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

I am suspecting this will open same URL for several notification in same instance. As the URL is stored outside the push handeler function scope.

You can check example in MDN documentation
image

@safwanrahman
Copy link
Owner

@JLucasRS Sorry for late review, was quite busy with work as well as university.
Can you please fix as per as the review and let me know if any help is needed?

@safwanrahman
Copy link
Owner

@JLucasRS can you manage some time to work on this?

@JLucasRS
Copy link
Author

@safwanrahman Fixed. Problem is, you can't acess data in 'notificationclick' event, BUT when you register the notification on 'push' event, you can add a key, data, which can be accessed in the 'notificationclick' event trough event.notification.data. So, i added a key called url in the data key, which allow me to access it in the event trough event.notification.data.url.

@safwanrahman
Copy link
Owner

Thanks a lot @JLucasRS . It would be awesome if any person with significant javascript knowledge would review the changes.
@rabbihossain can you please help?

@rabbihossain
Copy link

PR looks good to merge. Thanks for the help.

});

self.addEventListener('notificationclick', function (event) {
Copy link
Owner

@safwanrahman safwanrahman Jul 23, 2018

Choose a reason for hiding this comment

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

It actually add eventlistener to all the notification that is served by the service worker. It should be someething like mentioned in the MDN Documentation. Can you please try to do it like this?

Copy link
Author

Choose a reason for hiding this comment

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

new Notification() seems to throw TypeError and prompts you in the console to use registration.showNotification() instead.

@safwanrahman
Copy link
Owner

Thanks a lot @JLucasRS for the PR! its merged in #49
apologies for taking long to review it.

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