mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 22:47:29 +08:00
FEATURE: Nice Topic, Good Topic and Great Topic badges
Note we will revoke all old badges post badges that went to post #1 and instead get topic badges
This commit is contained in:
parent
61bcde6284
commit
7f3797b635
|
@ -13,6 +13,9 @@ class Badge < ActiveRecord::Base
|
||||||
FirstQuote = 15
|
FirstQuote = 15
|
||||||
ReadGuidelines = 16
|
ReadGuidelines = 16
|
||||||
Reader = 17
|
Reader = 17
|
||||||
|
NiceTopic = 18
|
||||||
|
GoodTopic = 19
|
||||||
|
GreatTopic = 20
|
||||||
|
|
||||||
# other consts
|
# other consts
|
||||||
AutobiographerMinBioLength = 10
|
AutobiographerMinBioLength = 10
|
||||||
|
@ -165,12 +168,12 @@ SQL
|
||||||
(:backfill OR u.id IN (:user_ids) )
|
(:backfill OR u.id IN (:user_ids) )
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
def self.like_badge(count)
|
def self.like_badge(count, is_topic)
|
||||||
# we can do better with dates, but its hard work
|
# we can do better with dates, but its hard work
|
||||||
"
|
"
|
||||||
SELECT p.user_id, p.id post_id, p.updated_at granted_at
|
SELECT p.user_id, p.id post_id, p.updated_at granted_at
|
||||||
FROM badge_posts p
|
FROM badge_posts p
|
||||||
WHERE p.like_count >= #{count.to_i} AND
|
WHERE #{is_topic ? "p.post_number = 1" : "p.post_number > 1" } AND p.like_count >= #{count.to_i} AND
|
||||||
(:backfill OR p.id IN (:post_ids) )
|
(:backfill OR p.id IN (:post_ids) )
|
||||||
"
|
"
|
||||||
end
|
end
|
||||||
|
|
|
@ -2181,6 +2181,15 @@ en:
|
||||||
great_post:
|
great_post:
|
||||||
name: Great Post
|
name: Great Post
|
||||||
description: Received 50 likes on a post. This badge can be granted multiple times
|
description: Received 50 likes on a post. This badge can be granted multiple times
|
||||||
|
nice_topic:
|
||||||
|
name: Nice Topic
|
||||||
|
description: Received 10 likes on a topic. This badge can be granted multiple times
|
||||||
|
good_post:
|
||||||
|
name: Good Topic
|
||||||
|
description: Received 25 likes on a topic. This badge can be granted multiple times
|
||||||
|
great_post:
|
||||||
|
name: Great Topic
|
||||||
|
description: Received 50 likes on a topic. This badge can be granted multiple times
|
||||||
first_like:
|
first_like:
|
||||||
name: First Like
|
name: First Like
|
||||||
description: Liked a post
|
description: Liked a post
|
||||||
|
|
|
@ -191,20 +191,24 @@ end
|
||||||
#
|
#
|
||||||
# Like system badges.
|
# Like system badges.
|
||||||
like_badges = [
|
like_badges = [
|
||||||
{id: 6, name: "Nice Post", type: BadgeType::Bronze, multiple: true},
|
{id: Badge::NicePost, name: "Nice Post", type: BadgeType::Bronze},
|
||||||
{id: 7, name: "Good Post", type: BadgeType::Silver, multiple: true},
|
{id: Badge::GoodPost, name: "Good Post", type: BadgeType::Silver},
|
||||||
{id: 8, name: "Great Post", type: BadgeType::Gold, multiple: true}
|
{id: Badge::GreatPost, name: "Great Post", type: BadgeType::Gold},
|
||||||
|
{id: Badge::NiceTopic, name: "Nice Topic", type: BadgeType::Bronze, topic: true},
|
||||||
|
{id: Badge::GoodTopic, name: "Good Topic", type: BadgeType::Silver, topic: true},
|
||||||
|
{id: Badge::GreatTopic, name: "Great Topic", type: BadgeType::Gold, topic: true}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
like_badges.each do |spec|
|
like_badges.each do |spec|
|
||||||
Badge.seed do |b|
|
Badge.seed do |b|
|
||||||
b.id = spec[:id]
|
b.id = spec[:id]
|
||||||
b.default_name = spec[:name]
|
b.default_name = spec[:name]
|
||||||
b.badge_type_id = spec[:type]
|
b.badge_type_id = spec[:type]
|
||||||
b.multiple_grant = spec[:multiple]
|
b.multiple_grant = true
|
||||||
b.target_posts = true
|
b.target_posts = true
|
||||||
b.show_posts = true
|
b.show_posts = true
|
||||||
b.query = Badge::Queries.like_badge(Badge.like_badge_counts[spec[:id]])
|
b.query = Badge::Queries.like_badge(Badge.like_badge_counts[spec[:id]], spec[:topic])
|
||||||
b.default_badge_grouping_id = BadgeGrouping::Posting
|
b.default_badge_grouping_id = BadgeGrouping::Posting
|
||||||
b.trigger = Badge::Trigger::PostAction
|
b.trigger = Badge::Trigger::PostAction
|
||||||
b.system = true
|
b.system = true
|
||||||
|
|
|
@ -42,17 +42,17 @@ describe BadgeGranter do
|
||||||
it 'should grant missing badges' do
|
it 'should grant missing badges' do
|
||||||
post = Fabricate(:post, like_count: 30)
|
post = Fabricate(:post, like_count: 30)
|
||||||
2.times {
|
2.times {
|
||||||
BadgeGranter.backfill(Badge.find(Badge::NicePost), post_ids: [post.id])
|
BadgeGranter.backfill(Badge.find(Badge::NiceTopic), post_ids: [post.id])
|
||||||
BadgeGranter.backfill(Badge.find(Badge::GoodPost))
|
BadgeGranter.backfill(Badge.find(Badge::GoodTopic))
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO add welcome
|
# TODO add welcome
|
||||||
post.user.user_badges.pluck(:badge_id).sort.should == [Badge::NicePost,Badge::GoodPost]
|
post.user.user_badges.pluck(:badge_id).sort.should == [Badge::NiceTopic,Badge::GoodTopic]
|
||||||
|
|
||||||
post.user.notifications.count.should == 2
|
post.user.notifications.count.should == 2
|
||||||
|
|
||||||
Badge.find(Badge::NicePost).grant_count.should == 1
|
Badge.find(Badge::NiceTopic).grant_count.should == 1
|
||||||
Badge.find(Badge::GoodPost).grant_count.should == 1
|
Badge.find(Badge::GoodTopic).grant_count.should == 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -187,26 +187,29 @@ describe BadgeGranter do
|
||||||
BadgeGranter.process_queue!
|
BadgeGranter.process_queue!
|
||||||
UserBadge.find_by(user_id: user.id, badge_id: 5).should_not be_nil
|
UserBadge.find_by(user_id: user.id, badge_id: 5).should_not be_nil
|
||||||
|
|
||||||
|
post = create_post(topic: post.topic, user: user)
|
||||||
|
action = PostAction.act(liker, post, PostActionType.types[:like])
|
||||||
|
|
||||||
# Nice post badge
|
# Nice post badge
|
||||||
post.update_attributes like_count: 10
|
post.update_attributes like_count: 10
|
||||||
|
|
||||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: action)
|
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: action)
|
||||||
BadgeGranter.process_queue!
|
BadgeGranter.process_queue!
|
||||||
|
|
||||||
UserBadge.find_by(user_id: user.id, badge_id: 6).should_not be_nil
|
UserBadge.find_by(user_id: user.id, badge_id: Badge::NicePost).should_not be_nil
|
||||||
UserBadge.where(user_id: user.id, badge_id: 6).count.should == 1
|
UserBadge.where(user_id: user.id, badge_id: Badge::NicePost).count.should == 1
|
||||||
|
|
||||||
# Good post badge
|
# Good post badge
|
||||||
post.update_attributes like_count: 25
|
post.update_attributes like_count: 25
|
||||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: action)
|
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: action)
|
||||||
BadgeGranter.process_queue!
|
BadgeGranter.process_queue!
|
||||||
UserBadge.find_by(user_id: user.id, badge_id: 7).should_not be_nil
|
UserBadge.find_by(user_id: user.id, badge_id: Badge::GoodPost).should_not be_nil
|
||||||
|
|
||||||
# Great post badge
|
# Great post badge
|
||||||
post.update_attributes like_count: 50
|
post.update_attributes like_count: 50
|
||||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: action)
|
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: action)
|
||||||
BadgeGranter.process_queue!
|
BadgeGranter.process_queue!
|
||||||
UserBadge.find_by(user_id: user.id, badge_id: 8).should_not be_nil
|
UserBadge.find_by(user_id: user.id, badge_id: Badge::GreatPost).should_not be_nil
|
||||||
|
|
||||||
# Revoke badges on unlike
|
# Revoke badges on unlike
|
||||||
post.update_attributes like_count: 49
|
post.update_attributes like_count: 49
|
||||||
|
|
Loading…
Reference in New Issue
Block a user