diff --git a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 index 3085f0ee8..55b3039e9 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 @@ -71,11 +71,17 @@ export default Discourse.DiscoveryController.extend({ }); }, - dismissRead: function() { + dismissRead: function(operationType) { var self = this, selected = this.get('selected'), - operation = { type: 'change_notification_level', + operation; + + if(operationType === "posts"){ + operation = { type: 'dismiss_posts' }; + } else { + operation = { type: 'change_notification_level', notification_level_id: Discourse.Topic.NotificationLevel.REGULAR }; + } var promise; if (selected.length > 0) { diff --git a/app/assets/javascripts/discourse/templates/discovery/topics.js.handlebars b/app/assets/javascripts/discourse/templates/discovery/topics.js.handlebars index a9314ea7e..808baf017 100644 --- a/app/assets/javascripts/discourse/templates/discovery/topics.js.handlebars +++ b/app/assets/javascripts/discourse/templates/discovery/topics.js.handlebars @@ -2,7 +2,8 @@ {{#if showDismissAtTop}}
{{#if showDismissRead}} - + + {{/if}} {{#if showResetNew}} @@ -89,7 +90,8 @@ {{/if}} {{#if allLoaded}} {{#if showDismissRead}} - + + {{/if}} {{#if showResetNew}} diff --git a/app/assets/javascripts/discourse/templates/mobile/discovery/topics.js.handlebars b/app/assets/javascripts/discourse/templates/mobile/discovery/topics.js.handlebars index 3702817a6..ae08623ad 100644 --- a/app/assets/javascripts/discourse/templates/mobile/discovery/topics.js.handlebars +++ b/app/assets/javascripts/discourse/templates/mobile/discovery/topics.js.handlebars @@ -30,7 +30,8 @@ {{/if}} {{#if allLoaded}} {{#if showDismissRead}} - + + {{/if}} {{#if showResetNew}} diff --git a/app/assets/stylesheets/desktop/topic-list.scss b/app/assets/stylesheets/desktop/topic-list.scss index f3d4fc91d..42e24c171 100644 --- a/app/assets/stylesheets/desktop/topic-list.scss +++ b/app/assets/stylesheets/desktop/topic-list.scss @@ -282,6 +282,7 @@ button.dismiss-read { float: right; margin-bottom: 5px; + margin-left: 10px; } .category-notification-menu .dropdown-menu { diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index f8499072f..675ef61c0 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -726,7 +726,10 @@ en: topics: bulk: reset_read: "Reset Read" - dismiss_read: "Dismiss Unread" + dismiss_posts: "Dismiss Posts" + dismiss_posts_tooltip: "Skip unread posts" + dismiss_topics: "Dismiss Topics" + dismiss_topics_tooltip: "Clear unread topics and reset tracking state to regular" dismiss_new: "Dismiss New" toggle: "toggle bulk selection of topics" actions: "Bulk Actions" diff --git a/lib/topics_bulk_action.rb b/lib/topics_bulk_action.rb index eb04a2903..c54f314ef 100644 --- a/lib/topics_bulk_action.rb +++ b/lib/topics_bulk_action.rb @@ -8,7 +8,7 @@ class TopicsBulkAction end def self.operations - %w(change_category close change_notification_level reset_read) + %w(change_category close change_notification_level reset_read dismiss_posts) end def perform! @@ -19,6 +19,18 @@ class TopicsBulkAction private + def dismiss_posts + sql = " + UPDATE topic_users tu + SET seen_post_count = t.posts_count , last_read_post_number = highest_post_number + FROM topics t + WHERE t.id = tu.topic_id AND tu.user_id = :user_id AND t.id IN (:topic_ids) + " + + Topic.exec_sql(sql, user_id: @user.id, topic_ids: @topic_ids) + @changed_ids.concat @topic_ids + end + def reset_read PostTiming.destroy_for(@user.id, @topic_ids) end diff --git a/spec/components/topics_bulk_action_spec.rb b/spec/components/topics_bulk_action_spec.rb index 00e56aa3a..97e9215fc 100644 --- a/spec/components/topics_bulk_action_spec.rb +++ b/spec/components/topics_bulk_action_spec.rb @@ -3,6 +3,19 @@ require_dependency 'topics_bulk_action' describe TopicsBulkAction do + describe "dismiss_posts" do + it "dismisses posts" do + post1 = create_post + create_post(topic_id: post1.topic_id) + + TopicsBulkAction.new(post1.user, [post1.topic_id], type: 'dismiss_posts').perform! + + tu = TopicUser.find_by(user_id: post1.user_id, topic_id: post1.topic_id) + tu.last_read_post_number.should == 2 + tu.seen_post_count = 2 + end + end + describe "invalid operation" do let(:user) { Fabricate.build(:user) }