FEATURE: new FirstReplyByEmail bronze badge
This commit is contained in:
parent
49f8a2baa7
commit
e97e0bb311
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue