FEATURE: Rename Reset Read bulk action to Defer (#15972)

It is enabled only if defer is enabled in user options too and if the
button shows up in the topic's footer.
This commit is contained in:
Bianca Nenciu 2022-02-21 22:45:01 +02:00 committed by GitHub
parent 94883dd326
commit 90c3695ab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 23 deletions

View File

@ -57,9 +57,12 @@ addBulkButton("showNotificationLevel", "notification_level", {
icon: "d-regular",
class: "btn-default",
});
addBulkButton("resetRead", "reset_read", {
icon: "backward",
addBulkButton("deletePostTiming", "defer", {
icon: "circle",
class: "btn-default",
buttonVisible() {
return this.currentUser.enable_defer;
},
});
addBulkButton("unlistTopics", "unlist_topics", {
icon: "far-eye-slash",
@ -299,8 +302,8 @@ export default Controller.extend(ModalFunctionality, {
);
},
resetRead() {
this.performAndRefresh({ type: "reset_read" });
deletePostTiming() {
this.performAndRefresh({ type: "destroy_post_timing" });
},
removeTags() {

View File

@ -20,7 +20,7 @@ acceptance("Topic - Bulk Actions", function (needs) {
});
test("bulk select - modal", async function (assert) {
updateCurrentUser({ moderator: true });
updateCurrentUser({ moderator: true, enable_defer: true });
await visit("/latest");
await click("button.bulk-select");
@ -65,9 +65,7 @@ acceptance("Topic - Bulk Actions", function (needs) {
);
assert.ok(
queryAll(".bulk-buttons")
.html()
.includes(I18n.t("topics.bulk.reset_read")),
queryAll(".bulk-buttons").html().includes(I18n.t("topics.bulk.defer")),
"it shows an option to reset read"
);

View File

@ -292,7 +292,7 @@ class TopicsController < ApplicationController
topic_id = params[:topic_id].to_i
if params[:last].to_s == "1"
PostTiming.destroy_last_for(current_user, topic_id)
PostTiming.destroy_last_for(current_user, topic_id: topic_id)
else
PostTiming.destroy_for(current_user.id, [topic_id])
end

View File

@ -58,8 +58,8 @@ class PostTiming < ActiveRecord::Base
record_new_timing(args) if rows == 0
end
def self.destroy_last_for(user, topic_id)
topic = Topic.find(topic_id)
def self.destroy_last_for(user, topic_id: nil, topic: nil)
topic ||= Topic.find(topic_id)
post_number = user.staff? ? topic.highest_staff_post_number : topic.highest_post_number
last_read = post_number - 1

View File

@ -2500,7 +2500,7 @@ en:
clear_all: "Clear All"
unlist_topics: "Unlist Topics"
relist_topics: "Relist Topics"
reset_read: "Reset Read"
defer: "Defer"
delete: "Delete Topics"
dismiss: "Dismiss"
dismiss_read: "Dismiss all unread"

View File

@ -12,7 +12,7 @@ class TopicsBulkAction
def self.operations
@operations ||= %w(change_category close archive change_notification_level
reset_read dismiss_posts delete unlist archive_messages
destroy_post_timing dismiss_posts delete unlist archive_messages
move_messages_to_inbox change_tags append_tags remove_tags
relist dismiss_topics)
end
@ -98,8 +98,11 @@ class TopicsBulkAction
@changed_ids = rows.map { |row| row[:topic_id] }
end
def reset_read
PostTiming.destroy_for(@user.id, @topic_ids)
def destroy_post_timing
topics.each do |t|
PostTiming.destroy_last_for(@user, topic: t)
@changed_ids << t.id
end
end
def change_category

View File

@ -197,11 +197,18 @@ describe TopicsBulkAction do
end
end
describe "reset_read" do
describe "destroy_post_timing" do
fab!(:fist_post) { Fabricate(:post, topic: topic) }
before do
PostTiming.process_timings(topic.user, topic.id, 10, [[1, 10]])
end
it "delegates to PostTiming.destroy_for" do
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'reset_read')
PostTiming.expects(:destroy_for).with(topic.user_id, [topic.id])
topic_ids = tba.perform!
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'destroy_post_timing')
topic_ids = nil
expect { topic_ids = tba.perform! }.to change { PostTiming.count }.by(-1)
expect(topic_ids).to contain_exactly(topic.id)
end
end

View File

@ -176,7 +176,7 @@ describe PostTiming do
end
it '#destroy_last_for decrements the reads count for a post' do
PostTiming.destroy_last_for(post.user, post.topic_id)
PostTiming.destroy_last_for(post.user, topic_id: post.topic_id)
expect(post.reload.reads).to eq initial_read_count
end
@ -193,7 +193,7 @@ describe PostTiming do
post.topic.update!(updated_at: 10.minutes.ago)
PostTiming.process_timings(post.user, post.topic_id, 1, [[post.post_number, 100]])
PostTiming.destroy_last_for(post.user, post.topic_id)
PostTiming.destroy_last_for(post.user, topic_id: post.topic_id)
expect(post.user.user_stat.reload.first_unread_at).to eq_time(post.topic.updated_at)
end
@ -203,7 +203,7 @@ describe PostTiming do
post.topic.update!(updated_at: 10.minutes.ago)
PostTiming.process_timings(post.user, post.topic_id, 1, [[post.post_number, 100]])
PostTiming.destroy_last_for(post.user, post.topic_id)
PostTiming.destroy_last_for(post.user, topic_id: post.topic_id)
expect(post.user.user_stat.reload.first_unread_pm_at).to eq_time(post.topic.updated_at)
end
@ -217,7 +217,7 @@ describe PostTiming do
topic.allowed_groups << group
PostTiming.process_timings(user, topic.id, 1, [[post.post_number, 100]])
PostTiming.destroy_last_for(user, topic.id)
PostTiming.destroy_last_for(user, topic_id: topic.id)
expect(GroupUser.find_by(user: user, group: group).first_unread_pm_at)
.to eq_time(post.topic.updated_at)