FEATURE: remove muted topics from suggested and latest

This commit is contained in:
Sam Saffron 2015-11-02 09:20:22 +11:00
parent 0d15dbd886
commit 606b10445e
4 changed files with 19 additions and 0 deletions

View File

@ -68,6 +68,8 @@ const User = RestModel.extend({
adminPath: url('username_lower', "/admin/users/%@"),
mutedTopicsPath: url('/latest?state=muted'),
@computed("username")
username_lower(username) {
return username.toLowerCase();

View File

@ -235,6 +235,13 @@
<div class="instructions">{{i18n 'user.muted_categories_instructions'}}</div>
</div>
<div class="control-group topics">
<label class="control-label">{{i18n 'categories.topics'}}</label>
<div class="controls topic-controls">
<a href="{{unbound model.mutedTopicsPath}}">{{i18n 'user.muted_topics_link'}}</a>
</div>
</div>
<div class="control-group muting">
<label class="control-label">{{i18n 'user.users'}}</label>
<div class="controls category-controls">

View File

@ -470,6 +470,7 @@ en:
users: "Users"
muted_users: "Muted"
muted_users_instructions: "Suppress all notifications from these users."
muted_topics_link: "Show muted topics"
staff_counters:
flags_given: "helpful flags"

View File

@ -201,6 +201,7 @@ class TopicQuery
def latest_results(options={})
result = default_results(options)
result = remove_muted_topics(result, @user) unless options && options[:state] = "muted".freeze
result = remove_muted_categories(result, @user, exclude: options[:category])
result
end
@ -215,6 +216,7 @@ class TopicQuery
# TODO does this make sense or should it be ordered on created_at
# it is ordering on bumped_at now
result = TopicQuery.new_filter(default_results(options.reverse_merge(:unordered => true)), @user.treat_as_new_topic_start_date)
result = remove_muted_topics(result, @user)
result = remove_muted_categories(result, @user, exclude: options[:category])
suggested_ordering(result, options)
end
@ -395,6 +397,13 @@ class TopicQuery
@guardian.filter_allowed_categories(result)
end
def remove_muted_topics(list, user)
if user
list = list.where('tu.notification_level <> :muted', muted: TopicUser.notification_levels[:muted])
end
list
end
def remove_muted_categories(list, user, opts=nil)
category_id = get_category_id(opts[:exclude]) if opts