diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-07 16:11:31 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-07 16:11:31 -0500 |
commit | 222dbaf5c23b41eabb75a83784bd4d110e981547 (patch) | |
tree | b62c594df5c41e5d3e3ee38d6a543adb1daa8539 | |
parent | a996f3bd05fc480247fd112f23fa3e67f7d5d7b5 (diff) | |
download | thoughts-222dbaf5c23b41eabb75a83784bd4d110e981547.tar.gz thoughts-222dbaf5c23b41eabb75a83784bd4d110e981547.tar.bz2 thoughts-222dbaf5c23b41eabb75a83784bd4d110e981547.zip |
Daily upvote email now includes details about webmention likes
-rw-r--r-- | app/helpers/votes_helper.rb | 32 | ||||
-rw-r--r-- | app/mailers/vote_mailer.rb | 2 | ||||
-rw-r--r-- | app/views/vote_mailer/daily_report_email.html.haml | 4 | ||||
-rw-r--r-- | app/views/vote_mailer/daily_report_email.text.erb | 2 |
4 files changed, 37 insertions, 3 deletions
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 @@ | |||
1 | module VotesHelper | ||
2 | |||
3 | def voters_list(votes, html = false) | ||
4 | voters = votes.select {|v| !v.liker_url.nil?}.map do |v| | ||
5 | if html | ||
6 | tag.strong(link_to v.liker_name, v.liker_url) | ||
7 | else | ||
8 | "#{v.liker_name} (#{v.liker_url})" | ||
9 | end | ||
10 | end | ||
11 | |||
12 | anons = votes.select {|v| v.liker_url.nil?}.size | ||
13 | if anons > 0 | ||
14 | if voters.empty? && anons == 1 | ||
15 | if html | ||
16 | voters << tag.strong("A guest") | ||
17 | else | ||
18 | voters << "A guest" | ||
19 | end | ||
20 | else | ||
21 | if html | ||
22 | voters << tag.strong(pluralize(anons, "guest")) | ||
23 | else | ||
24 | voters << pluralize(anons, "guest") | ||
25 | end | ||
26 | end | ||
27 | end | ||
28 | |||
29 | to_sentence(voters) | ||
30 | end | ||
31 | |||
32 | 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 @@ | |||
1 | class VoteMailer < ApplicationMailer | 1 | class VoteMailer < ApplicationMailer |
2 | helper :votes | ||
3 | |||
2 | def daily_report_email | 4 | def daily_report_email |
3 | @entries = params[:votes].group_by { |v| "#{v.votable_type}_#{v.votable_id}" }.values | 5 | @entries = params[:votes].group_by { |v| "#{v.votable_type}_#{v.votable_id}" }.values |
4 | # weird way of getting the admin's email | 6 | # 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 @@ | |||
3 | %ul | 3 | %ul |
4 | - @entries.each do |entry| | 4 | - @entries.each do |entry| |
5 | %li | 5 | %li |
6 | %strong= pluralize(entry.size, "person") | 6 | = voters_list(entry, html: true) |
7 | left an upvote on | 7 | upvoted |
8 | = link_to entry.first.votable.title, entry.first.votable, style: "font-weight: bold; font-style: italic" | 8 | = 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 @@ | |||
1 | Users have upvoted content on Four Island in the last day! | 1 | Users have upvoted content on Four Island in the last day! |
2 | 2 | ||
3 | <% @entries.each do |entry| %> | 3 | <% @entries.each do |entry| %> |
4 | - <%= pluralize(entry.size, "person") %> left an upvote on <%= entry.first.votable.title %> (<%= url_for(entry.first.votable) %>) | 4 | - <%= voters_list(entry) %> upvoted <%= entry.first.votable.title %> (<%= url_for(entry.first.votable) %>) |
5 | <% end %> | 5 | <% end %> |