diff --git a/app/models/fruit_ticket_transaction.rb b/app/models/fruit_ticket_transaction.rb index 56f100d9..bcbf0c75 100644 --- a/app/models/fruit_ticket_transaction.rb +++ b/app/models/fruit_ticket_transaction.rb @@ -4,6 +4,8 @@ class FruitTicketTransaction < ApplicationRecord validate :to_or_from_user_is_present + after_create :maybe_send_notification + # how do you get fruit tickets # - people listen to your show # - 1 fruit ticket for every listener? @@ -67,4 +69,13 @@ def to_or_from_user_is_present errors.add(:from_user, "from_user to to_user must be present") end end + + def maybe_send_notification + case self.transaction_type + when "user_gift" + Notification.create! source: self, send_to_chat: false, user: to_user, notification_type: "fruit_ticket_gift" + when "supporter_membership" + Notification.create! source: self, send_to_chat: false, user: to_user, notification_type: "supporter_fruit_ticket_stipend" + end + end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 882876f0..f944e6dc 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -20,7 +20,9 @@ class Notification < ApplicationRecord :vj_badge_award, :supporter_badge_award, :level_up, - :experience_point_award + :experience_point_award, + :fruit_ticket_gift, + :supporter_fruit_ticket_stipend ] private @@ -58,6 +60,10 @@ def set_message "#{self.user.username} reached level #{self.user.level}!" when "experience_point_award" "You got #{self.source.amount} #{self.source.award_type} points!" + when "fruit_ticket_gift" + "#{self.source.from_user.username" sent you Ƒ#{self.source.amount} fruit tickets!" + when "supporter_membership" + "You got Ƒ#{self.source.amount} fruit tickets for supporting datafruits. The bank of fruit tickets thanks you for your support!" end end