diff --git a/app/jobs/onceoff/grand_first_reply_by_email.rb b/app/jobs/onceoff/grand_first_reply_by_email.rb new file mode 100644 index 000000000..12fbb86e5 --- /dev/null +++ b/app/jobs/onceoff/grand_first_reply_by_email.rb @@ -0,0 +1,31 @@ +module Jobs + + class GrantFirstReplyByEmail < Jobs::Onceoff + def execute_onceoff(args) + to_award = {} + + Post.select(:id, :created_at, :user_id) + .secured(Guardian.new) + .visible + .public_posts + .where(via_email: true) + .where("post_number > 1") + .find_in_batches do |group| + group.each do |p| + to_award[p.user_id] ||= { post_id: p.id, created_at: p.created_at } + end + end + + to_award.each do |user_id, opts| + user = User.where(id: user_id).first + BadgeGranter.grant(badge, user, opts) if user + end + end + + def badge + @badge ||= Badge.find(Badge::FirstReplyByEmail) + end + + end + +end diff --git a/app/jobs/onceoff/grant_emoji.rb b/app/jobs/onceoff/grant_emoji.rb index 9a57423d6..3b9608ec5 100644 --- a/app/jobs/onceoff/grant_emoji.rb +++ b/app/jobs/onceoff/grant_emoji.rb @@ -18,12 +18,16 @@ module Jobs end end - badge = Badge.find(Badge::FirstEmoji) to_award.each do |user_id, opts| - BadgeGranter.grant(badge, User.find(user_id), opts) + user = User.where(id: user_id).first + BadgeGranter.grant(badge, user, opts) if user end end + def badge + @badge ||= Badge.find(Badge::FirstEmoji) + end + end end diff --git a/app/jobs/onceoff/grant_onebox.rb b/app/jobs/onceoff/grant_onebox.rb index 113f2e542..3dadbd16d 100644 --- a/app/jobs/onceoff/grant_onebox.rb +++ b/app/jobs/onceoff/grant_onebox.rb @@ -28,13 +28,16 @@ module Jobs end - badge = Badge.find(Badge::FirstOnebox) to_award.each do |user_id, opts| user = User.where(id: user_id).first BadgeGranter.grant(badge, user, opts) if user end end + def badge + @badge ||= Badge.find(Badge::FirstOnebox) + end + end end diff --git a/app/models/badge.rb b/app/models/badge.rb index 55e1d81f3..4a2105a10 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -1,6 +1,6 @@ class Badge < ActiveRecord::Base - # NOTE: These badge ids are not in order! They are grouped logically. When picking an id - # search for it. + # NOTE: These badge ids are not in order! They are grouped logically. + # When picking an id, *search* for it. Welcome = 5 NicePost = 6 @@ -17,6 +17,7 @@ class Badge < ActiveRecord::Base FirstMention = 40 FirstEmoji = 41 FirstOnebox = 42 + FirstReplyByEmail = 43 ReadGuidelines = 16 Reader = 17 diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 6438a804a..7f2a04b79 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -3095,6 +3095,11 @@ en: name: First Onebox description: Posted a link that was oneboxed long_description: This badge is granted the first time you post a link on a line by itself, which was then automatically expanded into a onebox with a brief summary of the link, a title, and (when available) a picture. + first_reply_by_email: + name: First Reply By Email + description: Replied to a Post via email + long_description: | + This badge is granted the first time you reply to a post via email :e-mail:. admin_login: success: "Email Sent" diff --git a/db/fixtures/006_badges.rb b/db/fixtures/006_badges.rb index b9fc82f80..bf99aa53a 100644 --- a/db/fixtures/006_badges.rb +++ b/db/fixtures/006_badges.rb @@ -400,6 +400,20 @@ Badge.seed do |b| b.system = true end +Badge.seed do |b| + b.id = Badge::FirstReplyByEmail + b.default_name = "First Reply By Email" + b.badge_type_id = BadgeType::Bronze + b.multiple_grant = false + b.target_posts = true + b.show_posts = true + b.query = nil + b.badge_grouping_id = BadgeGrouping::GettingStarted + b.default_badge_grouping_id = BadgeGrouping::GettingStarted + b.trigger = Badge::Trigger::PostProcessed + b.system = true +end + Badge.where("NOT system AND id < 100").each do |badge| new_id = [Badge.maximum(:id) + 1, 100].max old_id = badge.id