Files
once-campfire/app/controllers/users/push_subscriptions_controller.rb
Kevin McConnell df76a227dc Hello world
First open source release of Campfire 🎉
2025-08-21 09:31:59 +01:00

31 lines
729 B
Ruby

class Users::PushSubscriptionsController < ApplicationController
before_action :set_push_subscriptions
def index
end
def create
if subscription = @push_subscriptions.find_by(push_subscription_params)
subscription.touch
else
@push_subscriptions.create! push_subscription_params.merge(user_agent: request.user_agent)
end
head :ok
end
def destroy
@push_subscriptions.destroy_by(id: params[:id])
redirect_to user_push_subscriptions_url
end
private
def set_push_subscriptions
@push_subscriptions = Current.user.push_subscriptions
end
def push_subscription_params
params.require(:push_subscription).permit(:endpoint, :p256dh_key, :auth_key)
end
end