From 8fa3d4d0a9893c9bbe75ccaf6ec10768b4fb0355 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Fri, 18 Sep 2020 15:51:24 -0500 Subject: [PATCH] Added emails for reminding past PRO members to upgrade again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Added: - emails for reminding past PRO members to upgrade again --- app/mailers/user_mailer.rb | 29 ++++++++++ .../user_mailer/remind_expired_pro.html.haml | 54 +++++++++++++++++++ .../user_mailer/remind_expired_pro.text.erb | 25 +++++++++ .../remind_expired_account_pro_worker.rb | 21 ++++++++ .../scheduler/remind_expired_pro_scheduler.rb | 45 ++++++++++++++++ config/sidekiq.yml | 3 ++ 6 files changed, 177 insertions(+) create mode 100644 app/views/user_mailer/remind_expired_pro.html.haml create mode 100644 app/views/user_mailer/remind_expired_pro.text.erb create mode 100644 app/workers/remind_expired_account_pro_worker.rb create mode 100644 app/workers/scheduler/remind_expired_pro_scheduler.rb diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index fc1dca52..426e49c0 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -17,6 +17,35 @@ class UserMailer < Devise::Mailer end end + def remind_expired_pro(user, date_range) + @date_range = date_range + valid_date_ranges = ['7', '16', '30', '45', '60', '75', '90'] + + return unless valid_date_ranges.include?(@date_range) + + @resource = user + return if @resource.disabled? + + subject = "Renew GabPRO Today" + case @date_range + when '16' + subject = "Gab’s Mission" + when '30' + subject = "GabPRO Membership" + when '45' + subject = "Renew GabPRO" + when '60' + subject = "Gab Depends On People Like You" + when '75' + subject = "Free Speech Online Powered By You" + when '90' + subject = "Defend Freedom Online With Us" + end + + I18n.with_locale(@resource.locale || I18n.default_locale) do + mail to: @resource.email, subject: subject + end + end def confirmation_instructions(user, token, **) @resource = user @token = token diff --git a/app/views/user_mailer/remind_expired_pro.html.haml b/app/views/user_mailer/remind_expired_pro.html.haml new file mode 100644 index 00000000..3263e851 --- /dev/null +++ b/app/views/user_mailer/remind_expired_pro.html.haml @@ -0,0 +1,54 @@ +%tr + %td{:align => "center", :style => ""} + %h1{:style => "margin:0;font-weight:bold;font-size:20px;color:#444;text-align:center;"}= "Hello " + @resource.account.username + +%tr + %td{:align => "center", :cellspacing => "0", :style => "vertical-align:middle"} + %table + %tbody + %tr + %p{:style => "font-size:16px;color:#444;margin:15px 0;text-align:left;"} + %span Your GabPRO membership expired + - if @date_range == '7' + %span last week. + - elsif @date_range == '16' + %span a few weeks ago. + - elsif @date_range == '30' + %span last month. + - elsif @date_range == '45' + %span about a month ago. + - elsif @date_range == '60' + %span two months ago. + - elsif @date_range == '75' + %span a couple months ago. + - elsif @date_range == '90' + %span a few months ago. + - else + %span recently. + +%tr + %td{:align => "center", :cellspacing => "0", :style => "vertical-align:middle"} + %table + %tbody + %tr + %p{ :style => "margin:0 0 15px 0;text-align:left;" } + - if ['7', '30', '60'].include?(@date_range) + %span{ :style => "font-size:16px;color:#444;text-align:left;" } Thank you so much for supporting our mission of defending free speech online. We hope you please consider renewing your membership. Gab is 100% funded by people like you. + - elsif ['16', '45', '75'].include?(@date_range) + %span{ :style => "font-size:16px;color:#444;text-align:left;" } Gab is 100% funded by people like you, not special interests or big corporate advertisers. Your GabPRO membership has been expired, but we hope you'll please consider upgrading to GabPRO again today. We depend on people like you to help us keep building and to cover operational costs. Thank you for being a valued member of the Gab community! + - else + %span{ :style => "font-size:16px;color:#444;text-align:left;" } Your GabPRO subscription has been expired for a while now, but we hope you'll please consider upgrading to GabPRO again today. We depend on people like you to help us keep building and to cover operational costs. + %p{ :style => "margin:0 0 15px 0;text-align:left;" } + %span{ :style => "font-size:16px;color:#444;text-align:left;" } If you have any questions or need help with anything please feel free to reach out anytime: support@gab.com + %p{ :style => "margin:0 0 15px 0;text-align:left;" } + %span{ :style => "font-size:16px;color:#444;text-align:left;" } Go to + = link_to "https://pro.gab.com", "https://pro.gab.com", :style => "color:#30CE7D;font-size:16px;font-weight:600;text-decoration:underline;" + %span{ :style => "font-size:16px;color:#444;text-align:left;" } to renew your membership. + +%tr + %td{:align => "center", :cellspacing => "0", :style => "vertical-align:middle;padding-top:10px;padding-bottom:30px;"} + %table{ align: 'center', cellspacing: 0, cellpadding: 0 } + %tbody + %tr + %td{ :style => "background-color:#30CE7D;height:56px;border-radius:9999px;color:#fff;" } + = link_to "Renew GabPRO", "https://pro.gab.com", :style => "height:56px;padding:20px 30px;text-decoration:none;color:#fff;font-size:16px;margin:0;" diff --git a/app/views/user_mailer/remind_expired_pro.text.erb b/app/views/user_mailer/remind_expired_pro.text.erb new file mode 100644 index 00000000..7d7b29cd --- /dev/null +++ b/app/views/user_mailer/remind_expired_pro.text.erb @@ -0,0 +1,25 @@ +<%= "Hello " + @resource.account.username %> + +<% if @date_range == '7' %> +Your GabPRO membership expired last week. +<% elsif @date_range == '16' %> +Your GabPRO membership expired last month. +<% else %> +Your GabPRO membership expired last week. +<% end %> + +<% if ['7', '30', '60'].include?(@date_range) %> +Thank you so much for supporting our mission of defending free speech online. We hope you please consider renewing your membership. Gab is 100% funded by people like you. +<% elsif ['16', '45', '75'].include?(@date_range) %> +Gab is 100% funded by people like you, not special interests or big corporate advertisers. Your GabPRO membership has been expired, but we hope you'll please consider upgrading to GabPRO again today. We depend on people like you to help us keep building and to cover operational costs. Thank you for being a valued member of the Gab community! +<% else %> +Your GabPRO subscription has been expired for a while now, but we hope you'll please consider upgrading to GabPRO again today. We depend on people like you to help us keep building and to cover operational costs. +<% end %> + +If you have any questions or need help with anything please feel free to reach out anytime: support@gab.com + +=== + +Go to PRO.GAB.COM to renew your membership + +https://pro.gab.com \ No newline at end of file diff --git a/app/workers/remind_expired_account_pro_worker.rb b/app/workers/remind_expired_account_pro_worker.rb new file mode 100644 index 00000000..522192be --- /dev/null +++ b/app/workers/remind_expired_account_pro_worker.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemindExpiredAccountProWorker + include Sidekiq::Worker + + sidekiq_options queue: 'mailers', retry: 2 + + attr_reader :user + + def perform(acct_id, date_range) + @acct = Account.find(acct_id) + deliver_email(date_range) + end + + private + + def deliver_email(date_range) + UserMailer.remind_expired_pro(@acct.user, date_range).deliver_now! + @acct.user.touch(:last_emailed_at) + end +end diff --git a/app/workers/scheduler/remind_expired_pro_scheduler.rb b/app/workers/scheduler/remind_expired_pro_scheduler.rb new file mode 100644 index 00000000..dceb4d2b --- /dev/null +++ b/app/workers/scheduler/remind_expired_pro_scheduler.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +class Scheduler::RemindExpiredProScheduler + include Sidekiq::Worker + + sidekiq_options retry: 1 + + def perform + expired_accounts(8.days.ago, 7.days.ago).find_each do |acct| + RemindExpiredAccountProWorker.perform_async(acct.id, '7') + end + + expired_accounts(17.days.ago, 16.days.ago).find_each do |acct| + RemindExpiredAccountProWorker.perform_async(acct.id, '16') + end + + expired_accounts(31.days.ago, 30.days.ago).find_each do |acct| + RemindExpiredAccountProWorker.perform_async(acct.id, '30') + end + + expired_accounts(46.days.ago, 45.days.ago).find_each do |acct| + RemindExpiredAccountProWorker.perform_async(acct.id, '45') + end + + expired_accounts(61.days.ago, 60.days.ago).find_each do |acct| + RemindExpiredAccountProWorker.perform_async(acct.id, '60') + end + + expired_accounts(76.days.ago, 75.days.ago).find_each do |acct| + RemindExpiredAccountProWorker.perform_async(acct.id, '75') + end + + expired_accounts(91.days.ago, 90.days.ago).find_each do |acct| + RemindExpiredAccountProWorker.perform_async(acct.id, '90') + end + end + + private + + def expired_accounts(start_date, end_date) + Account.where('is_pro=FALSE AND pro_expires_at BETWEEN ? AND ?', start_date, end_date) + end + + +end diff --git a/config/sidekiq.yml b/config/sidekiq.yml index cf3f252a..148e8a0d 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -6,6 +6,9 @@ - [mailers, 2] - [pull] :schedule: + remind_expired_pro_scheduler: + cron: '0 8 * * *' + class: Scheduler::RemindExpiredProScheduler expiring_pro_scheduler: cron: '0 7 * * *' class: Scheduler::ExpiringProScheduler