From 9681897e9ace534c4559fa9be20aa86af1a42e13 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 7 Dec 2024 10:33:07 -0500 Subject: Add daily upvote email like AO3 kudos --- app/mailers/vote_mailer.rb | 7 +++++++ app/models/quote.rb | 4 ++++ app/views/vote_mailer/daily_report_email.html.haml | 8 ++++++++ app/views/vote_mailer/daily_report_email.text.erb | 5 +++++ 4 files changed, 24 insertions(+) create mode 100644 app/mailers/vote_mailer.rb create mode 100644 app/views/vote_mailer/daily_report_email.html.haml create mode 100644 app/views/vote_mailer/daily_report_email.text.erb (limited to 'app') diff --git a/app/mailers/vote_mailer.rb b/app/mailers/vote_mailer.rb new file mode 100644 index 0000000..77ac3d1 --- /dev/null +++ b/app/mailers/vote_mailer.rb @@ -0,0 +1,7 @@ +class VoteMailer < ApplicationMailer + def daily_report_email + @entries = params[:votes].group_by { |v| "#{v.votable_type}_#{v.votable_id}" }.values + # weird way of getting the admin's email + mail to: User.first.email, subject: "[Four Island] You have upvotes!" + end +end diff --git a/app/models/quote.rb b/app/models/quote.rb index 518d53b..3301667 100644 --- a/app/models/quote.rb +++ b/app/models/quote.rb @@ -17,6 +17,10 @@ class Quote < ApplicationRecord scope :published, -> { where(state: :published) } scope :pending, -> { where(state: :pending) } + def title + "Quote \##{id}" + end + def published_date created_at.strftime("%B %d %Y at %I:%M:%S") + created_at.strftime(" %p").downcase + created_at.strftime(" %Z") end diff --git a/app/views/vote_mailer/daily_report_email.html.haml b/app/views/vote_mailer/daily_report_email.html.haml new file mode 100644 index 0000000..ab54df2 --- /dev/null +++ b/app/views/vote_mailer/daily_report_email.html.haml @@ -0,0 +1,8 @@ +%p + Users have upvoted content on Four Island in the last day! +%ul + - @entries.each do |entry| + %li + %strong= pluralize(entry.size, "person") + left an upvote on + = link_to entry.first.votable.title, entry.first.votable, style: "font-weight: bold; font-style: italic" diff --git a/app/views/vote_mailer/daily_report_email.text.erb b/app/views/vote_mailer/daily_report_email.text.erb new file mode 100644 index 0000000..22ea368 --- /dev/null +++ b/app/views/vote_mailer/daily_report_email.text.erb @@ -0,0 +1,5 @@ +Users have upvoted content on Four Island in the last day! + +<% @entries.each do |entry| %> +- <%= pluralize(entry.size, "person") %> left an upvote on <%= entry.first.votable.title %> (<%= url_for(entry.first.votable) %>) +<% end %> -- cgit 1.4.1