FEATURE: exclude muted categories from the latest and new tabs
This commit is contained in:
parent
f7bf4b2dc3
commit
d0a6dd88df
|
@ -43,15 +43,6 @@ class CategoryUser < ActiveRecord::Base
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def notification_level1=(val)
|
|
||||||
val = Symbol === val ? CategoryUser.notification_levels[val] : val
|
|
||||||
attributes[:notification_level] = val
|
|
||||||
end
|
|
||||||
|
|
||||||
def notification_level1
|
|
||||||
attributes[:notification_level]
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.apply_default_to_topic(topic, level, reason)
|
def self.apply_default_to_topic(topic, level, reason)
|
||||||
|
|
|
@ -53,7 +53,7 @@ class TopicQuery
|
||||||
|
|
||||||
# The latest view of topics
|
# The latest view of topics
|
||||||
def list_latest
|
def list_latest
|
||||||
create_list(:latest)
|
TopicList.new(:latest, @user, latest_results)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The starred topics
|
# The starred topics
|
||||||
|
@ -278,9 +278,29 @@ class TopicQuery
|
||||||
|
|
||||||
def new_results(options={})
|
def new_results(options={})
|
||||||
result = TopicQuery.new_filter(default_results(options), @user.treat_as_new_topic_start_date)
|
result = TopicQuery.new_filter(default_results(options), @user.treat_as_new_topic_start_date)
|
||||||
|
result = remove_muted_categories(result, @user)
|
||||||
suggested_ordering(result, options)
|
suggested_ordering(result, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def latest_results(options={})
|
||||||
|
result = default_results(options)
|
||||||
|
remove_muted_categories(result, @user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_muted_categories(list, user)
|
||||||
|
if user
|
||||||
|
list = list.where("NOT EXISTS(
|
||||||
|
SELECT 1 FROM category_users cu
|
||||||
|
WHERE cu.user_id = ? AND
|
||||||
|
cu.category_id = topics.category_id AND
|
||||||
|
cu.notification_level = ?
|
||||||
|
)", user.id, CategoryUser.notification_levels[:muted])
|
||||||
|
end
|
||||||
|
|
||||||
|
list
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def unread_results(options={})
|
def unread_results(options={})
|
||||||
result = TopicQuery.unread_filter(default_results(options.reverse_merge(:unordered => true)))
|
result = TopicQuery.unread_filter(default_results(options.reverse_merge(:unordered => true)))
|
||||||
.order('CASE WHEN topics.user_id = tu.user_id THEN 1 ELSE 2 END')
|
.order('CASE WHEN topics.user_id = tu.user_id THEN 1 ELSE 2 END')
|
||||||
|
|
|
@ -70,6 +70,17 @@ describe TopicQuery do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'muted categories' do
|
||||||
|
it 'is removed from new and latest lists' do
|
||||||
|
category = Fabricate(:category)
|
||||||
|
topic = Fabricate(:topic, category: category)
|
||||||
|
CategoryUser.create!(user_id: user.id,
|
||||||
|
category_id: category.id,
|
||||||
|
notification_level: CategoryUser.notification_levels[:muted])
|
||||||
|
topic_query.list_new.topics.map(&:id).should_not include(topic.id)
|
||||||
|
topic_query.list_latest.topics.map(&:id).should_not include(topic.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'a bunch of topics' do
|
context 'a bunch of topics' do
|
||||||
let!(:regular_topic) do
|
let!(:regular_topic) do
|
||||||
|
@ -127,13 +138,11 @@ describe TopicQuery do
|
||||||
context 'list_latest' do
|
context 'list_latest' do
|
||||||
it "returns the topics in the correct order" do
|
it "returns the topics in the correct order" do
|
||||||
topics.map(&:id).should == [pinned_topic, closed_topic, archived_topic, regular_topic].map(&:id)
|
topics.map(&:id).should == [pinned_topic, closed_topic, archived_topic, regular_topic].map(&:id)
|
||||||
end
|
|
||||||
|
|
||||||
it "includes the invisible topic if you're a moderator" do
|
# includes the invisible topic if you're a moderator
|
||||||
TopicQuery.new(moderator).list_latest.topics.include?(invisible_topic).should be_true
|
TopicQuery.new(moderator).list_latest.topics.include?(invisible_topic).should be_true
|
||||||
end
|
|
||||||
|
|
||||||
it "includes the invisible topic if you're an admin" do
|
# includes the invisible topic if you're an admin" do
|
||||||
TopicQuery.new(admin).list_latest.topics.include?(invisible_topic).should be_true
|
TopicQuery.new(admin).list_latest.topics.include?(invisible_topic).should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,35 +152,29 @@ describe TopicQuery do
|
||||||
TopicQuery.new(admin, sort_order: order, sort_descending: descending ? 'true' : 'false').list_latest.topics.map(&:id)
|
TopicQuery.new(admin, sort_order: order, sort_descending: descending ? 'true' : 'false').list_latest.topics.map(&:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the topics in likes order if requested" do
|
it "returns the topics in correct order" do
|
||||||
|
# returns the topics in likes order if requested
|
||||||
ids_in_order('posts').should == [pinned_topic, archived_topic, regular_topic, invisible_topic, closed_topic].map(&:id)
|
ids_in_order('posts').should == [pinned_topic, archived_topic, regular_topic, invisible_topic, closed_topic].map(&:id)
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the topics in reverse likes order if requested" do
|
# returns the topics in reverse likes order if requested
|
||||||
ids_in_order('posts', false).should == [closed_topic, invisible_topic, regular_topic, archived_topic, pinned_topic].map(&:id)
|
ids_in_order('posts', false).should == [closed_topic, invisible_topic, regular_topic, archived_topic, pinned_topic].map(&:id)
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the topics in likes order if requested" do
|
# returns the topics in likes order if requested
|
||||||
ids_in_order('likes').should == [pinned_topic, regular_topic, archived_topic, invisible_topic, closed_topic].map(&:id)
|
ids_in_order('likes').should == [pinned_topic, regular_topic, archived_topic, invisible_topic, closed_topic].map(&:id)
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the topics in reverse likes order if requested" do
|
# returns the topics in reverse likes order if requested
|
||||||
ids_in_order('likes', false).should == [closed_topic, invisible_topic, archived_topic, regular_topic, pinned_topic].map(&:id)
|
ids_in_order('likes', false).should == [closed_topic, invisible_topic, archived_topic, regular_topic, pinned_topic].map(&:id)
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the topics in views order if requested" do
|
# returns the topics in views order if requested
|
||||||
ids_in_order('views').should == [regular_topic, archived_topic, pinned_topic, closed_topic, invisible_topic].map(&:id)
|
ids_in_order('views').should == [regular_topic, archived_topic, pinned_topic, closed_topic, invisible_topic].map(&:id)
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the topics in reverse views order if requested" do
|
# returns the topics in reverse views order if requested" do
|
||||||
ids_in_order('views', false).should == [invisible_topic, closed_topic, pinned_topic, archived_topic, regular_topic].map(&:id)
|
ids_in_order('views', false).should == [invisible_topic, closed_topic, pinned_topic, archived_topic, regular_topic].map(&:id)
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the topics in posters order if requested" do
|
# returns the topics in posters order if requested" do
|
||||||
ids_in_order('posters').should == [pinned_topic, regular_topic, invisible_topic, closed_topic, archived_topic].map(&:id)
|
ids_in_order('posters').should == [pinned_topic, regular_topic, invisible_topic, closed_topic, archived_topic].map(&:id)
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the topics in reverse posters order if requested" do
|
# returns the topics in reverse posters order if requested" do
|
||||||
ids_in_order('posters', false).should == [archived_topic, closed_topic, invisible_topic, regular_topic, pinned_topic].map(&:id)
|
ids_in_order('posters', false).should == [archived_topic, closed_topic, invisible_topic, regular_topic, pinned_topic].map(&:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -179,6 +182,7 @@ describe TopicQuery do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
context 'after clearring a pinned topic' do
|
context 'after clearring a pinned topic' do
|
||||||
before do
|
before do
|
||||||
pinned_topic.clear_pin_for(user)
|
pinned_topic.clear_pin_for(user)
|
||||||
|
|
Loading…
Reference in New Issue