FEATURE: remove star concept from Discourse

This commit is contained in:
Sam
2015-01-07 12:19:23 +11:00
parent fa8493118b
commit efc717c14a
35 changed files with 50 additions and 448 deletions

View File

@@ -11,7 +11,6 @@ class AdminDashboardData
'users_by_trust_level',
'likes',
'bookmarks',
'starred',
'emails',
'user_to_user_private_messages',
'system_private_messages',

View File

@@ -91,13 +91,7 @@ class Report
end
end
def self.report_starred(report)
basic_report_about report, Topic, :starred_counts_per_day, default_days
add_counts report, TopicUser.where(starred: true), 'topic_users.starred_at'
end
# Post action counts:
def self.report_flags(report)
basic_report_about report, PostAction, :flag_count_by_date, report.start_date, report.end_date
add_counts report, PostAction.where(post_action_type_id: PostActionType.flag_types.values), 'post_actions.created_at'

View File

@@ -141,13 +141,6 @@ class Topic < ActiveRecord::Base
WHERE #{condition[0]})", condition[1])
}
# Helps us limit how many topics can be starred in a day
class StarLimiter < RateLimiter
def initialize(user)
super(user, "starred:#{Date.today}", SiteSetting.max_stars_per_day, 1.day.to_i)
end
end
attr_accessor :ignore_category_auto_close
attr_accessor :skip_callbacks
@@ -612,27 +605,6 @@ class Topic < ActiveRecord::Base
@participants_summary ||= TopicParticipantsSummary.new(self, options).summary
end
# Enable/disable the star on the topic
def toggle_star(user, starred)
Topic.transaction do
TopicUser.change(user, id, {starred: starred}.merge( starred ? {starred_at: DateTime.now, unstarred_at: nil} : {unstarred_at: DateTime.now}))
# Update the star count
exec_sql "UPDATE topics
SET star_count = (SELECT COUNT(*)
FROM topic_users AS ftu
WHERE ftu.topic_id = topics.id
AND ftu.starred = true)
WHERE id = ?", id
if starred
StarLimiter.new(user).performed!
else
StarLimiter.new(user).rollback!
end
end
end
def make_banner!(user)
# only one banner at the same time
previous_banner = Topic.where(archetype: Archetype.banner).first
@@ -662,10 +634,6 @@ class Topic < ActiveRecord::Base
}
end
def self.starred_counts_per_day(sinceDaysAgo=30)
TopicUser.starred_since(sinceDaysAgo).by_date_starred.count
end
# Even if the slug column in the database is null, topic.slug will return something:
def slug
unless slug = read_attribute(:slug)

View File

@@ -2,9 +2,6 @@ class TopicUser < ActiveRecord::Base
belongs_to :user
belongs_to :topic
scope :starred_since, lambda { |sinceDaysAgo| where('starred_at > ?', sinceDaysAgo.days.ago) }
scope :by_date_starred, -> { group('date(starred_at)').order('date(starred_at)') }
scope :tracking, lambda { |topic_id|
where(topic_id: topic_id)
.where("COALESCE(topic_users.notification_level, :regular) >= :tracking",
@@ -86,8 +83,6 @@ class TopicUser < ActiveRecord::Base
TopicUser.transaction do
attrs = attrs.dup
attrs[:starred_at] = DateTime.now if attrs[:starred_at].nil? && attrs[:starred]
if attrs[:notification_level]
attrs[:notifications_changed_at] ||= DateTime.now
attrs[:notifications_reason_id] ||= TopicUser.notification_reasons[:user_changed]

View File

@@ -14,7 +14,6 @@ class UserAction < ActiveRecord::Base
RESPONSE= 6
MENTION = 7
QUOTE = 9
STAR = 10
EDIT = 11
NEW_PRIVATE_MESSAGE = 12
GOT_PRIVATE_MESSAGE = 13
@@ -30,7 +29,6 @@ class UserAction < ActiveRecord::Base
MENTION,
QUOTE,
BOOKMARK,
STAR,
EDIT
].each_with_index.to_a.flatten]
@@ -240,35 +238,8 @@ SQL
builder.exec
end
def self.synchronize_starred
exec_sql("
DELETE FROM user_actions ua
WHERE action_type = :star
AND NOT EXISTS (
SELECT 1 FROM topic_users tu
WHERE
tu.user_id = ua.user_id AND
tu.topic_id = ua.target_topic_id AND
starred
)", star: UserAction::STAR)
exec_sql("INSERT INTO user_actions
(action_type, user_id, target_topic_id, target_post_id, acting_user_id, created_at, updated_at)
SELECT :star, tu.user_id, tu.topic_id, -1, tu.user_id, tu.starred_at, tu.starred_at
FROM topic_users tu
WHERE starred AND NOT EXISTS(
SELECT 1 FROM user_actions ua
WHERE tu.user_id = ua.user_id AND
tu.topic_id = ua.target_topic_id AND
ua.action_type = :star
)
", star: UserAction::STAR)
end
def self.ensure_consistency!
self.synchronize_target_topic_ids
self.synchronize_starred
end
def self.update_like_count(user_id, action_type, delta)
@@ -294,7 +265,7 @@ SQL
end
unless (guardian.user && guardian.user.id == user_id) || guardian.is_staff?
builder.where("a.action_type not in (#{BOOKMARK},#{STAR})")
builder.where("a.action_type not in (#{BOOKMARK})")
builder.where("t.visible")
end

View File

@@ -9,27 +9,6 @@ class UserActionObserver < ActiveRecord::Observer
log_topic(model)
when (model.is_a?(Post))
log_post(model)
when (model.is_a?(TopicUser))
log_topic_user(model)
end
end
def log_topic_user(model)
action = UserAction::STAR
row = {
action_type: action,
user_id: model.user_id,
acting_user_id: model.user_id,
target_topic_id: model.topic_id,
target_post_id: -1,
created_at: model.starred_at
}
if model.starred
UserAction.log_action!(row)
else
UserAction.remove_action!(row)
end
end