This repository was archived by the owner on Jan 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
FEATURE: Add banner prompt for user consent #14
Merged
featheredtoast
merged 1 commit into
discourse:master
from
featheredtoast:consent-prompt-banner
Apr 6, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
assets/javascripts/discourse/components/push-notification-consent.js.es6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { default as computed } from 'ember-addons/ember-computed-decorators'; | ||
|
||
import { | ||
subscribe as subscribePushNotification, | ||
unsubscribe as unsubscribePushNotification, | ||
isPushNotificationsSupported, | ||
keyValueStore as pushNotificationKeyValueStore, | ||
userSubscriptionKey as pushNotificationUserSubscriptionKey, | ||
userDismissedPrompt as pushNotificationUserDismissedPrompt, | ||
} from 'discourse/plugins/discourse-push-notifications/discourse/lib/push-notifications'; | ||
|
||
import { | ||
context, | ||
unsubscribe as unsubscribeToNotificationAlert | ||
} from 'discourse/lib/desktop-notifications'; | ||
|
||
import KeyValueStore from 'discourse/lib/key-value-store'; | ||
const desktopNotificationkeyValueStore = new KeyValueStore(context); | ||
|
||
export default Ember.Component.extend({ | ||
@computed | ||
bannerDismissed: { | ||
set(value) { | ||
const user = this.currentUser; | ||
pushNotificationKeyValueStore.setItem(pushNotificationUserDismissedPrompt(user), value); | ||
return pushNotificationKeyValueStore.getItem(pushNotificationUserDismissedPrompt(user)); | ||
}, | ||
get() { | ||
return pushNotificationKeyValueStore.getItem(pushNotificationUserDismissedPrompt(Discourse.User.current())); | ||
} | ||
}, | ||
|
||
@computed | ||
showPushNotificationPrompt() { | ||
return (this.siteSettings.push_notifications_enabled && | ||
this.siteSettings.push_notifications_prompt && | ||
Notification.permission !== "denied" && | ||
isPushNotificationsSupported() && this.currentUser | ||
); | ||
}, | ||
|
||
@computed | ||
pushNotificationSubscribed: { | ||
set(value) { | ||
const user = this.currentUser; | ||
pushNotificationKeyValueStore.setItem(pushNotificationUserSubscriptionKey(user), value); | ||
return pushNotificationKeyValueStore.getItem(pushNotificationUserSubscriptionKey(user)); | ||
}, | ||
get() { | ||
return pushNotificationKeyValueStore.getItem(pushNotificationUserSubscriptionKey(Discourse.User.current())); | ||
} | ||
}, | ||
|
||
actions: { | ||
subscribe() { | ||
subscribePushNotification(() => { | ||
desktopNotificationkeyValueStore.setItem('notifications-disabled', 'disabled'); | ||
unsubscribeToNotificationAlert(this.messageBus, this.currentUser); | ||
this.setProperties({bannerDismissed: true, pushNotificationSubscribed: 'subscribed'}); | ||
}, this.siteSettings.vapid_public_key_bytes); | ||
}, | ||
dismiss() { | ||
this.set("bannerDismissed", true); | ||
} | ||
} | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
assets/javascripts/discourse/templates/components/push-notification-consent.hbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{#if showPushNotificationPrompt}} | ||
{{#unless bannerDismissed}} | ||
{{#unless pushNotificationSubscribed}} | ||
<div class="wrap"> | ||
<div class="row"> | ||
<div class="consent_banner alert alert-info"> | ||
<div class="close" {{action "dismiss"}}><i class="fa fa-times d-icon d-icon-times"></i></div> | ||
{{i18n 'discourse_push_notifications.consent_prompt'}} <a {{action "subscribe"}}>{{i18n 'discourse_push_notifications.consent_enable'}}</a>. | ||
</div> | ||
</div> | ||
</div> | ||
{{/unless}} | ||
{{/unless}} | ||
{{/if}} |
1 change: 1 addition & 0 deletions
1
...javascripts/discourse/templates/connectors/below-site-header/push-notification-prompt.hbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{push-notification-consent}} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.push-notification-prompt { | ||
position: relative; | ||
top: 82px; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an opportunity to re-use
{{discourse-banner}}
instead?