mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06:00
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:
parent
94883dd326
commit
90c3695ab0
@ -57,9 +57,12 @@ addBulkButton("showNotificationLevel", "notification_level", {
|
|||||||
icon: "d-regular",
|
icon: "d-regular",
|
||||||
class: "btn-default",
|
class: "btn-default",
|
||||||
});
|
});
|
||||||
addBulkButton("resetRead", "reset_read", {
|
addBulkButton("deletePostTiming", "defer", {
|
||||||
icon: "backward",
|
icon: "circle",
|
||||||
class: "btn-default",
|
class: "btn-default",
|
||||||
|
buttonVisible() {
|
||||||
|
return this.currentUser.enable_defer;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
addBulkButton("unlistTopics", "unlist_topics", {
|
addBulkButton("unlistTopics", "unlist_topics", {
|
||||||
icon: "far-eye-slash",
|
icon: "far-eye-slash",
|
||||||
@ -299,8 +302,8 @@ export default Controller.extend(ModalFunctionality, {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
resetRead() {
|
deletePostTiming() {
|
||||||
this.performAndRefresh({ type: "reset_read" });
|
this.performAndRefresh({ type: "destroy_post_timing" });
|
||||||
},
|
},
|
||||||
|
|
||||||
removeTags() {
|
removeTags() {
|
||||||
|
@ -20,7 +20,7 @@ acceptance("Topic - Bulk Actions", function (needs) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("bulk select - modal", async function (assert) {
|
test("bulk select - modal", async function (assert) {
|
||||||
updateCurrentUser({ moderator: true });
|
updateCurrentUser({ moderator: true, enable_defer: true });
|
||||||
await visit("/latest");
|
await visit("/latest");
|
||||||
await click("button.bulk-select");
|
await click("button.bulk-select");
|
||||||
|
|
||||||
@ -65,9 +65,7 @@ acceptance("Topic - Bulk Actions", function (needs) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
queryAll(".bulk-buttons")
|
queryAll(".bulk-buttons").html().includes(I18n.t("topics.bulk.defer")),
|
||||||
.html()
|
|
||||||
.includes(I18n.t("topics.bulk.reset_read")),
|
|
||||||
"it shows an option to reset read"
|
"it shows an option to reset read"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ class TopicsController < ApplicationController
|
|||||||
topic_id = params[:topic_id].to_i
|
topic_id = params[:topic_id].to_i
|
||||||
|
|
||||||
if params[:last].to_s == "1"
|
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
|
else
|
||||||
PostTiming.destroy_for(current_user.id, [topic_id])
|
PostTiming.destroy_for(current_user.id, [topic_id])
|
||||||
end
|
end
|
||||||
|
@ -58,8 +58,8 @@ class PostTiming < ActiveRecord::Base
|
|||||||
record_new_timing(args) if rows == 0
|
record_new_timing(args) if rows == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.destroy_last_for(user, topic_id)
|
def self.destroy_last_for(user, topic_id: nil, topic: nil)
|
||||||
topic = Topic.find(topic_id)
|
topic ||= Topic.find(topic_id)
|
||||||
post_number = user.staff? ? topic.highest_staff_post_number : topic.highest_post_number
|
post_number = user.staff? ? topic.highest_staff_post_number : topic.highest_post_number
|
||||||
|
|
||||||
last_read = post_number - 1
|
last_read = post_number - 1
|
||||||
|
@ -2500,7 +2500,7 @@ en:
|
|||||||
clear_all: "Clear All"
|
clear_all: "Clear All"
|
||||||
unlist_topics: "Unlist Topics"
|
unlist_topics: "Unlist Topics"
|
||||||
relist_topics: "Relist Topics"
|
relist_topics: "Relist Topics"
|
||||||
reset_read: "Reset Read"
|
defer: "Defer"
|
||||||
delete: "Delete Topics"
|
delete: "Delete Topics"
|
||||||
dismiss: "Dismiss"
|
dismiss: "Dismiss"
|
||||||
dismiss_read: "Dismiss all unread"
|
dismiss_read: "Dismiss all unread"
|
||||||
|
@ -12,7 +12,7 @@ class TopicsBulkAction
|
|||||||
|
|
||||||
def self.operations
|
def self.operations
|
||||||
@operations ||= %w(change_category close archive change_notification_level
|
@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
|
move_messages_to_inbox change_tags append_tags remove_tags
|
||||||
relist dismiss_topics)
|
relist dismiss_topics)
|
||||||
end
|
end
|
||||||
@ -98,8 +98,11 @@ class TopicsBulkAction
|
|||||||
@changed_ids = rows.map { |row| row[:topic_id] }
|
@changed_ids = rows.map { |row| row[:topic_id] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_read
|
def destroy_post_timing
|
||||||
PostTiming.destroy_for(@user.id, @topic_ids)
|
topics.each do |t|
|
||||||
|
PostTiming.destroy_last_for(@user, topic: t)
|
||||||
|
@changed_ids << t.id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_category
|
def change_category
|
||||||
|
@ -197,11 +197,18 @@ describe TopicsBulkAction do
|
|||||||
end
|
end
|
||||||
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
|
it "delegates to PostTiming.destroy_for" do
|
||||||
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'reset_read')
|
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'destroy_post_timing')
|
||||||
PostTiming.expects(:destroy_for).with(topic.user_id, [topic.id])
|
topic_ids = nil
|
||||||
topic_ids = tba.perform!
|
expect { topic_ids = tba.perform! }.to change { PostTiming.count }.by(-1)
|
||||||
|
expect(topic_ids).to contain_exactly(topic.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ describe PostTiming do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it '#destroy_last_for decrements the reads count for a post' do
|
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
|
expect(post.reload.reads).to eq initial_read_count
|
||||||
end
|
end
|
||||||
@ -193,7 +193,7 @@ describe PostTiming do
|
|||||||
post.topic.update!(updated_at: 10.minutes.ago)
|
post.topic.update!(updated_at: 10.minutes.ago)
|
||||||
PostTiming.process_timings(post.user, post.topic_id, 1, [[post.post_number, 100]])
|
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)
|
expect(post.user.user_stat.reload.first_unread_at).to eq_time(post.topic.updated_at)
|
||||||
end
|
end
|
||||||
@ -203,7 +203,7 @@ describe PostTiming do
|
|||||||
post.topic.update!(updated_at: 10.minutes.ago)
|
post.topic.update!(updated_at: 10.minutes.ago)
|
||||||
PostTiming.process_timings(post.user, post.topic_id, 1, [[post.post_number, 100]])
|
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)
|
expect(post.user.user_stat.reload.first_unread_pm_at).to eq_time(post.topic.updated_at)
|
||||||
end
|
end
|
||||||
@ -217,7 +217,7 @@ describe PostTiming do
|
|||||||
topic.allowed_groups << group
|
topic.allowed_groups << group
|
||||||
PostTiming.process_timings(user, topic.id, 1, [[post.post_number, 100]])
|
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)
|
expect(GroupUser.find_by(user: user, group: group).first_unread_pm_at)
|
||||||
.to eq_time(post.topic.updated_at)
|
.to eq_time(post.topic.updated_at)
|
||||||
|
Loading…
Reference in New Issue
Block a user