hackatime/app/controllers/settings/notifications_controller.rb
Mahad Kalam 1f695850e5
Bring back Mailkick (#1021)
* Sources say Charlie Kick is stable. Please god

* Some tests + guards + unsub URL fix

* Fix lockfile!

* bin/rubocop -A

* if this does not work I am going to kms

* phew
2026-03-01 14:26:54 +00:00

36 lines
1.1 KiB
Ruby

class Settings::NotificationsController < Settings::BaseController
def show
render_notifications
end
def update
list = "weekly_summary"
enabled = params.dig(:user, :weekly_summary_email_enabled)
begin
if enabled == "1" || enabled == true
@user.subscribe(list) unless @user.subscribed?(list)
else
@user.unsubscribe(list) if @user.subscribed?(list)
end
PosthogService.capture(@user, "settings_updated", { fields: [ "weekly_summary_email_enabled" ] })
redirect_to my_settings_notifications_path, notice: "Settings updated successfully"
rescue => e
Sentry.capture_exception(e)
Rails.logger.error("Failed to update notification settings: #{e.message}")
flash.now[:error] = "Failed to update settings, sorry :("
render_notifications(status: :unprocessable_entity)
end
end
private
def render_notifications(status: :ok)
render_settings_page(
active_section: "notifications",
settings_update_path: my_settings_notifications_path,
status: status
)
end
end