Skip to content

Commit

Permalink
send notifications for fruit ticket gifts and supporter membership
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfiredrill committed Sep 1, 2023
1 parent f1c81ca commit 1d8e0fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/models/fruit_ticket_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
8 changes: 7 additions & 1 deletion app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 1d8e0fe

Please sign in to comment.