diff --git a/app/models/notification.rb b/app/models/notification.rb index bd43f019..ff8a650f 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -50,90 +50,134 @@ class Notification < ApplicationRecord ] private - def set_message + def set_message_key + self.message_key = "notifications.#{self.notification_type}" + end + + def set_message_params # TODO i18n - self.message = case self.notification_type + case self.notification_type when "strawberry_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the strawbur badge!" when "lemon_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the lemoner badge!" when "orange_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the orangey badge!" when "banana_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the banaynay badge!" when "cabbage_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the evil cabbage badge!" when "watermelon_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the watermel badge!" when "pineapple_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the pineapplee badge!" when "limer_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the limer badge!" when "dragionfruit badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the dragionfruit badge!" when "blueberrinies badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the blueberrinies badge!" when "beamsprout_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the beamsprout badge!" when "dj_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the DJ badge!" when "vj_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the VJ badge!" when "supporter_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the supporter badge!" when "gold_supporter_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the gold supporter badge!" when "emerald_supporter_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the emerald supporter badge!" when "duckle_badge_award" + self.message_params = { username: self.user.username } "#{self.user.username} got the duckle badge! :duckle: what the heck..." when "level_up" + self.message_params = { username: self.user.username, level: self.user.level } "#{self.user.username} reached level #{self.user.level}!" when "experience_point_award" + self.message_params = { amount: self.source.amount, award_type: self.source.award_type } "You got #{self.source.amount} #{self.source.award_type} points!" when "fruit_ticket_gift" + self.message_params = { username: self.user.username, amount: self.user.amount } "#{self.source.from_user.username} sent you Ƒ#{self.source.amount} fruit tickets!" when "supporter_fruit_ticket_stipend" + self.message_params = { amount: self.user.amount } "You got Ƒ#{self.source.amount} fruit tickets for supporting datafruits. The bank of fruit tickets thanks you for your support!" when "track_playback_ticket_payment" + self.message_params = { amount: self.user.amount } "You got Ƒ#{self.source.amount} fruit tickets for your contributions!" when "glorp_lottery_winner" + self.message_params = { username: self.user.username, amount: self.source.amount, award_type: self.source.award_type } ":#{self.source.award_type.split("py").first}:!!! #{self.user.username} got #{self.source.amount} #{self.source.award_type} points!" when "show_comment" + self.message_params = { title: self.source.title } "#{self.source.title} has a new comment!" when "patreon_sub" + self.message_params = { name: self.source.name } # TODO figure out which tier somehow # "#{self.source.name} subscribed to the #{self.source.tier_name} tier on patreon!" "#{self.source.name} subscribed to the patreon!" when "new_thread" + self.message_params = { title: self.source.title } "New thread posted in da fruit standz: #{self.source.title}" when "new_thread_reply" + self.message_params = { title: self.source.title } "New reply to thread #{self.source.title}" when "new_wiki_page" + self.message_params = { title: self.source.title } "New wiki page created: #{self.source.title}" when "wiki_page_update" + self.message_params = { title: self.source.title } "wiki page #{self.source.title} was updated!" when "new_datafruiter" + self.message_params = { username: self.user.username } "new datafruiter on the loose, #{self.source.username} joined!" when "profile_update" + self.message_params = { username: self.user.username } "#{self.source.username}'s bio was updated!" when "avatar_update" + self.message_params = { username: self.user.username, image_url: self.source.image.url(:thumb) } "#{self.source.username}'s fruitification emblem was updated: #{self.source.image.url(:thumb)}" when "new_podcast" + self.message_params = { title: self.source.title } "New archive published: #{self.source.title}" when "shrimpo_started" + self.message_params = { title: self.source.title } "#{self.source.title} shrimpo started!!!!!" when "shrimpo_entry" + self.message_params = { title: self.source.title, entries_count: self.source.shrimpo.shrimpo_entries.count, emoji: self.source.shrimpo.emoji } "#{self.source.shrimpo.emoji} Someone shrimpoed for #{self.source.shrimpo.title} ! There are #{self.source.shrimpo.shrimpo_entries.count} total entries now." when "shrimpo_voting_started" + self.message_params = { title: self.source.title } "#{self.source.title} shrimpo ended! Time to vote!" when "shrimpo_comment" + self.message_params = { title: self.source.title } "#{self.source.title} has a new comment!" when "shrimpo_entry_comment" + self.message_params = { title: self.source.title } "#{self.source.title} has a new comment!" when "fruit_ticket_stimulus" + self.message_params = { amount: self.user.amount } "You received a stimulus from the bank of fruit tix: Ƒ#{self.source.amount}" when "shrimpo_deposit_return" + self.message_params = { amount: self.user.amount } "Your shrimpo deposit was returned for Ƒ#{self.source.amount}" end end diff --git a/db/migrate/20250218024456_add_message_keys_params_to_notifications.rb b/db/migrate/20250218024456_add_message_keys_params_to_notifications.rb new file mode 100644 index 00000000..d7f43336 --- /dev/null +++ b/db/migrate/20250218024456_add_message_keys_params_to_notifications.rb @@ -0,0 +1,6 @@ +class AddMessageKeysParamsToNotifications < ActiveRecord::Migration[7.0] + def change + add_column :notifications, :message_key, :string + add_column :notifications, :message_params, :jsonb, default: {} + end +end diff --git a/db/schema.rb b/db/schema.rb index eaf27184..97fae85c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2025_01_27_015236) do +ActiveRecord::Schema[7.0].define(version: 2025_02_18_024456) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -196,6 +196,8 @@ t.string "source_type" t.boolean "read", default: false, null: false t.string "url" + t.string "message_key" + t.jsonb "message_params", default: {} t.index ["user_id"], name: "index_notifications_on_user_id" end