60d26cabf0
* Add follow_request notification type The notification type already existed in the backend but was never pushed to the front-end. This also means translation strings were also available for the backend, from the notification mailer. Unlike other notification types, these are off by default, to match what I remember of Gargron's view on the topic: that follow requests should not clutter notifications and should instead be reviewed at the user's own leisure in the dedicated column. Since follow requests have their own column, I've deemed it unnecessary to add a specific tab for them in the notification quick filter. * Show follow request link in single-column if there are pending requests, even if account isn't locked * Push follow requests from notifications to the follow_requests list * Offer to accept or reject follow request from the notification * Redesign follow request notification
64 lines
1.9 KiB
Ruby
64 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::Web::PushSubscriptionsController < Api::Web::BaseController
|
|
respond_to :json
|
|
|
|
before_action :require_user!
|
|
|
|
def create
|
|
active_session = current_session
|
|
|
|
unless active_session.web_push_subscription.nil?
|
|
active_session.web_push_subscription.destroy!
|
|
active_session.update!(web_push_subscription: nil)
|
|
end
|
|
|
|
# Mobile devices do not support regular notifications, so we enable push notifications by default
|
|
alerts_enabled = active_session.detection.device.mobile? || active_session.detection.device.tablet?
|
|
|
|
data = {
|
|
alerts: {
|
|
follow: alerts_enabled,
|
|
follow_request: false,
|
|
favourite: alerts_enabled,
|
|
reblog: alerts_enabled,
|
|
mention: alerts_enabled,
|
|
poll: alerts_enabled,
|
|
},
|
|
}
|
|
|
|
data.deep_merge!(data_params) if params[:data]
|
|
|
|
web_subscription = ::Web::PushSubscription.create!(
|
|
endpoint: subscription_params[:endpoint],
|
|
key_p256dh: subscription_params[:keys][:p256dh],
|
|
key_auth: subscription_params[:keys][:auth],
|
|
data: data,
|
|
user_id: active_session.user_id,
|
|
access_token_id: active_session.access_token_id
|
|
)
|
|
|
|
active_session.update!(web_push_subscription: web_subscription)
|
|
|
|
render json: web_subscription, serializer: REST::WebPushSubscriptionSerializer
|
|
end
|
|
|
|
def update
|
|
params.require([:id])
|
|
|
|
web_subscription = ::Web::PushSubscription.find(params[:id])
|
|
web_subscription.update!(data: data_params)
|
|
|
|
render json: web_subscription, serializer: REST::WebPushSubscriptionSerializer
|
|
end
|
|
|
|
private
|
|
|
|
def subscription_params
|
|
@subscription_params ||= params.require(:subscription).permit(:endpoint, keys: [:auth, :p256dh])
|
|
end
|
|
|
|
def data_params
|
|
@data_params ||= params.require(:data).permit(alerts: [:follow, :follow_request, :favourite, :reblog, :mention, :poll])
|
|
end
|
|
end
|