Add settings page for push notifications
This commit is contained in:
parent
c8f5511a38
commit
752cf1506b
|
@ -4,6 +4,8 @@ class Ajax::WebPushController < AjaxController
|
|||
def key
|
||||
certificate = Rpush::Webpush::App.find_by(name: "webpush").certificate
|
||||
|
||||
@response[:status] = :okay
|
||||
@response[:success] = true
|
||||
@response[:key] = JSON.parse(certificate)["public_key"]
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Settings::PushNotificationsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
|
||||
def index
|
||||
@subscriptions = current_user.web_push_subscriptions
|
||||
end
|
||||
end
|
|
@ -14,7 +14,7 @@ export function enableHandler (event: Event): void {
|
|||
return;
|
||||
}
|
||||
|
||||
post('/ajax/web_push', {
|
||||
post('/ajax/webpush', {
|
||||
body: {
|
||||
subscription
|
||||
},
|
||||
|
|
|
@ -108,6 +108,7 @@
|
|||
"components/mobile-nav",
|
||||
"components/notifications",
|
||||
"components/profile",
|
||||
"components/push-settings",
|
||||
"components/question",
|
||||
"components/smiles",
|
||||
"components/themes",
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
.push-notifications {
|
||||
&-unavailable {
|
||||
body.cap-service-worker.cap-notification & {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
.card.push-notifications-settings
|
||||
.card-body
|
||||
%p= t('.description')
|
||||
%p= t('.subscription_count', count: subscriptions.count)
|
||||
|
||||
.push-notifications-unavailable.text-danger
|
||||
%i.fa.fa-warning
|
||||
= t('.unsupported')
|
||||
|
||||
.push-notifications-current-target.d-none.text-success
|
||||
%i.fa.fa-check
|
||||
= t('.current_target')
|
||||
|
||||
.button-group{ role: 'group' }
|
||||
%button.btn.btn-primary{ data: { action: 'push-enable' } }= t('.subscribe')
|
||||
%button.btn.btn-primary{ data: { action: 'push-disable' } }= t('.unsubscribe_current')
|
||||
%button.btn.btn-danger{ data: { action: 'push-remove-all' } }= t('.unsubscribe_all')
|
|
@ -0,0 +1,4 @@
|
|||
= render "settings/push_notifications", subscriptions: @subscriptions
|
||||
|
||||
- provide(:title, generate_title(t(".title")))
|
||||
- parent_layout "user/settings"
|
|
@ -8,6 +8,7 @@
|
|||
= list_group_item t(".mutes"), settings_muted_path
|
||||
= list_group_item t(".blocks"), settings_blocks_path
|
||||
= list_group_item t(".theme"), edit_settings_theme_path
|
||||
= list_group_item t(".push_notifications"), settings_push_notifications_path
|
||||
= list_group_item t(".data"), settings_data_path
|
||||
= list_group_item t(".export"), settings_export_path
|
||||
|
||||
|
|
|
@ -531,6 +531,18 @@ en:
|
|||
body: "Raised content includes all the different boxes and panels you can see across the site."
|
||||
accent:
|
||||
example: "Some text on top of a accented area on a raised element!"
|
||||
push_notifications:
|
||||
index:
|
||||
title: "Push Notifications"
|
||||
subscription_count:
|
||||
zero: "You are not currently subscribed to push notifications on any devices."
|
||||
one: "You are currently receiving push notifications on one device."
|
||||
other: "You are currently receiving push notifications on %{count} devices."
|
||||
unsupported: "This browser does not support push notifications."
|
||||
current_target: "You are currently receiving push notifications on this device."
|
||||
subscribe: "Enable on this device"
|
||||
unsubscribe_current: "Disable on this device"
|
||||
unsubscribe_all: "Disable on all devices"
|
||||
shared:
|
||||
links:
|
||||
about: "About"
|
||||
|
@ -594,6 +606,8 @@ en:
|
|||
theme: "Theme"
|
||||
data: "Your Data"
|
||||
export: "Export"
|
||||
blocks: "Blocks"
|
||||
push_notifications: "Push Notifications"
|
||||
moderation:
|
||||
inbox:
|
||||
header:
|
||||
|
|
|
@ -89,6 +89,8 @@ Rails.application.routes.draw do
|
|||
|
||||
get :data, to: "data#index"
|
||||
|
||||
resources :push_notifications, only: %i[index]
|
||||
|
||||
namespace :two_factor_authentication do
|
||||
get :otp_authentication, to: "otp_authentication#index"
|
||||
patch :otp_authentication, to: "otp_authentication#update"
|
||||
|
|
Loading…
Reference in New Issue