From 222dbaf5c23b41eabb75a83784bd4d110e981547 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 7 Dec 2024 16:11:31 -0500 Subject: Daily upvote email now includes details about webmention likes --- app/helpers/votes_helper.rb | 32 ++++++++++++++++++++++ app/mailers/vote_mailer.rb | 2 ++ app/views/vote_mailer/daily_report_email.html.haml | 4 +-- app/views/vote_mailer/daily_report_email.text.erb | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 app/helpers/votes_helper.rb (limited to 'app') diff --git a/app/helpers/votes_helper.rb b/app/helpers/votes_helper.rb new file mode 100644 index 0000000..169d7bf --- /dev/null +++ b/app/helpers/votes_helper.rb @@ -0,0 +1,32 @@ +module VotesHelper + + def voters_list(votes, html = false) + voters = votes.select {|v| !v.liker_url.nil?}.map do |v| + if html + tag.strong(link_to v.liker_name, v.liker_url) + else + "#{v.liker_name} (#{v.liker_url})" + end + end + + anons = votes.select {|v| v.liker_url.nil?}.size + if anons > 0 + if voters.empty? && anons == 1 + if html + voters << tag.strong("A guest") + else + voters << "A guest" + end + else + if html + voters << tag.strong(pluralize(anons, "guest")) + else + voters << pluralize(anons, "guest") + end + end + end + + to_sentence(voters) + end + +end diff --git a/app/mailers/vote_mailer.rb b/app/mailers/vote_mailer.rb index 77ac3d1..90d2868 100644 --- a/app/mailers/vote_mailer.rb +++ b/app/mailers/vote_mailer.rb @@ -1,4 +1,6 @@ class VoteMailer < ApplicationMailer + helper :votes + 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 diff --git a/app/views/vote_mailer/daily_report_email.html.haml b/app/views/vote_mailer/daily_report_email.html.haml index ab54df2..33458f1 100644 --- a/app/views/vote_mailer/daily_report_email.html.haml +++ b/app/views/vote_mailer/daily_report_email.html.haml @@ -3,6 +3,6 @@ %ul - @entries.each do |entry| %li - %strong= pluralize(entry.size, "person") - left an upvote on + = voters_list(entry, html: true) + upvoted = 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 index 22ea368..5fc0b31 100644 --- a/app/views/vote_mailer/daily_report_email.text.erb +++ b/app/views/vote_mailer/daily_report_email.text.erb @@ -1,5 +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) %>) +- <%= voters_list(entry) %> upvoted <%= entry.first.votable.title %> (<%= url_for(entry.first.votable) %>) <% end %> -- cgit 1.4.1