FEATURE: allow users to dismiss unread posts

This commit is contained in:
Sam 2014-08-08 16:29:51 +10:00
parent c1cbf1b269
commit 49f738fe27
7 changed files with 45 additions and 7 deletions

View file

@ -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) {

View file

@ -2,7 +2,8 @@
{{#if showDismissAtTop}}
<div class="row">
{{#if showDismissRead}}
<button class='btn dismiss-read' {{action dismissRead}}>{{i18n topics.bulk.dismiss_read}}</button>
<button title="{{i18n topics.bulk.dismiss_topics_tooltip}}" class='btn dismiss-read' {{action dismissRead "topics"}}>{{i18n topics.bulk.dismiss_topics}}</button>
<button title="{{i18n topics.bulk.dismiss_posts_tooltip}}" class='btn dismiss-read' {{action dismissRead "posts"}}>{{i18n topics.bulk.dismiss_posts}}</button>
{{/if}}
{{#if showResetNew}}
<button class='btn dismiss-read' {{action resetNew}}>{{i18n topics.bulk.dismiss_new}}</button>
@ -89,7 +90,8 @@
{{/if}}
{{#if allLoaded}}
{{#if showDismissRead}}
<button class='btn dismiss-read' {{action dismissRead}}>{{i18n topics.bulk.dismiss_read}}</button>
<button title="{{i18n topics.bulk.dismiss_topics_tooltip}}" class='btn dismiss-read' {{action dismissRead "topics"}}>{{i18n topics.bulk.dismiss_topics}}</button>
<button title="{{i18n topics.bulk.dismiss_posts_tooltip}}" class='btn dismiss-read' {{action dismissRead "posts"}}>{{i18n topics.bulk.dismiss_posts}}</button>
{{/if}}
{{#if showResetNew}}
<button class='btn dismiss-read' {{action resetNew}}>{{i18n topics.bulk.dismiss_new}}</button>

View file

@ -30,7 +30,8 @@
{{/if}}
{{#if allLoaded}}
{{#if showDismissRead}}
<button class='btn dismiss-read' {{action dismissRead}}>{{i18n topics.bulk.dismiss_read}}</button>
<button title="{{i18n topics.bulk.dismiss_topics_tooltip}}" class='btn dismiss-read' {{action dismissRead "topics"}}>{{i18n topics.bulk.dismiss_topics}}</button>
<button title="{{i18n topics.bulk.dismiss_posts_tooltip}}" class='btn dismiss-read' {{action dismissRead "posts"}}>{{i18n topics.bulk.dismiss_posts}}</button>
{{/if}}
{{#if showResetNew}}
<button class='btn dismiss-read' {{action resetNew}}>{{i18n topics.bulk.dismiss_new}}</button>

View file

@ -282,6 +282,7 @@
button.dismiss-read {
float: right;
margin-bottom: 5px;
margin-left: 10px;
}
.category-notification-menu .dropdown-menu {

View file

@ -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"

View file

@ -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

View file

@ -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) }