mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-02 11:59:17 -05:00
Create rarity levels for using up all likes
This commit is contained in:
parent
e84d5549ef
commit
25c26dcd51
2 changed files with 33 additions and 20 deletions
|
@ -28,7 +28,9 @@ class Badge < ActiveRecord::Base
|
||||||
FamousLink = 30
|
FamousLink = 30
|
||||||
Admired = 31
|
Admired = 31
|
||||||
GivesBack = 32
|
GivesBack = 32
|
||||||
Generous = 33
|
OutOfLove = 33
|
||||||
|
MyCupRunnethOver = 34
|
||||||
|
CrazyInLove = 35
|
||||||
|
|
||||||
# other consts
|
# other consts
|
||||||
AutobiographerMinBioLength = 10
|
AutobiographerMinBioLength = 10
|
||||||
|
@ -220,14 +222,6 @@ SQL
|
||||||
HAVING us.likes_given::float / count(*) > 5.0
|
HAVING us.likes_given::float / count(*) > 5.0
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
Generous = <<-SQL
|
|
||||||
SELECT uh.target_user_id AS user_id, MIN(uh.created_at) AS granted_at
|
|
||||||
FROM user_histories AS uh
|
|
||||||
WHERE uh.action = #{UserHistory.actions[:rate_limited_like]}
|
|
||||||
AND (:backfill OR uh.target_user_id IN (:user_ids))
|
|
||||||
GROUP BY uh.target_user_id
|
|
||||||
SQL
|
|
||||||
|
|
||||||
def self.invite_badge(count,trust_level)
|
def self.invite_badge(count,trust_level)
|
||||||
"
|
"
|
||||||
SELECT u.id user_id, current_timestamp granted_at
|
SELECT u.id user_id, current_timestamp granted_at
|
||||||
|
@ -292,6 +286,17 @@ SQL
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.like_rate_limit(count)
|
||||||
|
<<-SQL
|
||||||
|
SELECT uh.target_user_id AS user_id, MAX(uh.created_at) AS granted_at
|
||||||
|
FROM user_histories AS uh
|
||||||
|
WHERE uh.action = #{UserHistory.actions[:rate_limited_like]}
|
||||||
|
AND (:backfill OR uh.target_user_id IN (:user_ids))
|
||||||
|
GROUP BY uh.target_user_id
|
||||||
|
HAVING COUNT(*) >= #{count}
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
belongs_to :badge_type
|
belongs_to :badge_type
|
||||||
|
@ -313,7 +318,6 @@ SQL
|
||||||
[:badge_type_id, :multiple_grant, :target_posts, :show_posts, :query, :trigger, :auto_revoke, :listable]
|
[:badge_type_id, :multiple_grant, :target_posts, :show_posts, :query, :trigger, :auto_revoke, :listable]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.trust_level_badge_ids
|
def self.trust_level_badge_ids
|
||||||
(1..4).to_a
|
(1..4).to_a
|
||||||
end
|
end
|
||||||
|
|
|
@ -316,17 +316,26 @@ Badge.seed do |b|
|
||||||
b.system = true
|
b.system = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
[
|
||||||
|
[Badge::OutOfLove, "Out of Love", BadgeType::Bronze, 1],
|
||||||
|
[Badge::MyCupRunnethOver, "My Cup Runneth Over", BadgeType::Silver, 5],
|
||||||
|
[Badge::CrazyInLove, "Crazy in Love", BadgeType::Gold, 20],
|
||||||
|
].each do |spec|
|
||||||
|
id, name, level, count = spec
|
||||||
Badge.seed do |b|
|
Badge.seed do |b|
|
||||||
b.id = Badge::Generous
|
b.id = id
|
||||||
b.default_name = "Generous"
|
b.name = name
|
||||||
|
b.default_name = name
|
||||||
b.default_icon = "fa-heart"
|
b.default_icon = "fa-heart"
|
||||||
b.badge_type_id = BadgeType::Silver
|
b.badge_type_id = level
|
||||||
b.query = Badge::Queries::Generous
|
b.query = Badge::Queries.like_rate_limit(count)
|
||||||
b.default_badge_grouping_id = BadgeGrouping::Community
|
b.default_badge_grouping_id = BadgeGrouping::Community
|
||||||
b.trigger = Badge::Trigger::None
|
b.trigger = Badge::Trigger::None
|
||||||
b.auto_revoke = false
|
b.auto_revoke = false
|
||||||
b.system = true
|
b.system = true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
Badge.where("NOT system AND id < 100").each do |badge|
|
Badge.where("NOT system AND id < 100").each do |badge|
|
||||||
new_id = [Badge.maximum(:id) + 1, 100].max
|
new_id = [Badge.maximum(:id) + 1, 100].max
|
||||||
|
|
Loading…
Reference in a new issue