Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add 'auto delete after last post' topic timer (#36662)

David Taylor051efbc2504b
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index c3e07b9673a..654b218c319 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3842,6 +3842,8 @@ en:
title: "Auto-Close Topic After Last Post"
auto_delete:
title: "Auto-Delete Topic"
+ auto_delete_after_last_post:
+ title: "Auto-Delete Topic After Last Post"
auto_bump:
title: "Auto-Bump Topic"
reminder:
@@ -3854,6 +3856,7 @@ en:
auto_close: "This topic will automatically close %{timeLeft}."
auto_publish_to_category: "This topic will be published to <a href=%{categoryUrl}>#%{categoryName}</a> %{timeLeft}."
auto_close_after_last_post: "This topic will close %{duration} after the last reply."
+ auto_delete_after_last_post: "This topic will be deleted %{duration} after the last reply."
auto_delete: "This topic will be automatically deleted %{timeLeft}."
auto_bump: "This topic will be automatically bumped %{timeLeft}."
auto_reminder: "You will be reminded about this topic %{timeLeft}."
diff --git a/frontend/discourse/app/components/edit-topic-timer-form.gjs b/frontend/discourse/app/components/edit-topic-timer-form.gjs
index 34fa0663c37..df47e21fd24 100644
--- a/frontend/discourse/app/components/edit-topic-timer-form.gjs
+++ b/frontend/discourse/app/components/edit-topic-timer-form.gjs
@@ -10,6 +10,7 @@ import {
BUMP_TYPE,
CLOSE_AFTER_LAST_POST_STATUS_TYPE,
CLOSE_STATUS_TYPE,
+ DELETE_AFTER_LAST_POST_STATUS_TYPE,
DELETE_REPLIES_TYPE,
DELETE_STATUS_TYPE,
OPEN_STATUS_TYPE,
@@ -64,7 +65,15 @@ export default class EditTopicTimerForm extends Component {
}
get useDuration() {
- return this.autoCloseAfterLastPost || this.autoDeleteReplies;
+ return (
+ this.autoCloseAfterLastPost ||
+ this.autoDeleteAfterLastPost ||
+ this.autoDeleteReplies
+ );
+ }
+
+ get autoDeleteAfterLastPost() {
+ return this.statusType === DELETE_AFTER_LAST_POST_STATUS_TYPE;
}
get autoCloseAfterLastPost() {
@@ -87,6 +96,11 @@ export default class EditTopicTimerForm extends Component {
this.args.topicTimer.based_on_last_post
) {
return CLOSE_AFTER_LAST_POST_STATUS_TYPE;
+ } else if (
+ statusType === DELETE_STATUS_TYPE &&
+ this.args.topicTimer.based_on_last_post
+ ) {
+ return DELETE_AFTER_LAST_POST_STATUS_TYPE;
} else {
return statusType;
}
diff --git a/frontend/discourse/app/components/modal/edit-topic-timer.gjs b/frontend/discourse/app/components/modal/edit-topic-timer.gjs
index ca8920dd026..8a173c2b192 100644
--- a/frontend/discourse/app/components/modal/edit-topic-timer.gjs
+++ b/frontend/discourse/app/components/modal/edit-topic-timer.gjs
@@ -16,6 +16,7 @@ export const CLOSE_AFTER_LAST_POST_STATUS_TYPE = "close_after_last_post";
export const OPEN_STATUS_TYPE = "open";
export const PUBLISH_TO_CATEGORY_STATUS_TYPE = "publish_to_category";
export const DELETE_STATUS_TYPE = "delete";
+export const DELETE_AFTER_LAST_POST_STATUS_TYPE = "delete_after_last_post";
export const BUMP_TYPE = "bump";
export const DELETE_REPLIES_TYPE = "delete_replies";
@@ -69,6 +70,10 @@ export default class EditTopicTimer extends Component {
id: DELETE_STATUS_TYPE,
name: i18n("topic.auto_delete.title"),
});
+ types.push({
+ id: DELETE_AFTER_LAST_POST_STATUS_TYPE,
+ name: i18n("topic.auto_delete_after_last_post.title"),
+ });
}
types.push({
@@ -160,7 +165,10 @@ export default class EditTopicTimer extends Component {
@action
onChangeStatusType(value) {
- const basedOnLastPost = CLOSE_AFTER_LAST_POST_STATUS_TYPE === value;
+ const basedOnLastPost = [
+ CLOSE_AFTER_LAST_POST_STATUS_TYPE,
+ DELETE_AFTER_LAST_POST_STATUS_TYPE,
+ ].includes(value);
this.topicTimer.based_on_last_post = basedOnLastPost;
this.args.model.updateTopicTimerProperty(
"based_on_last_post",
@@ -205,6 +213,9 @@ export default class EditTopicTimer extends Component {
if (statusType === CLOSE_AFTER_LAST_POST_STATUS_TYPE) {
statusType = CLOSE_STATUS_TYPE;
}
+ if (statusType === DELETE_AFTER_LAST_POST_STATUS_TYPE) {
+ statusType = DELETE_STATUS_TYPE;
+ }
await this._setTimer(
this.topicTimer.updateTime,
diff --git a/plugins/automation/lib/discourse_automation/scripts/set_topic_timer.rb b/plugins/automation/lib/discourse_automation/scripts/set_topic_timer.rb
index d60dc8516fb..5cbc7638bc5 100644
--- a/plugins/automation/lib/discourse_automation/scripts/set_topic_timer.rb
+++ b/plugins/automation/lib/discourse_automation/scripts/set_topic_timer.rb
@@ -8,6 +8,7 @@ DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scripts::SET_TOPIC_TIME
{ id: "auto_close", name: "topic.auto_close.title" },
{ id: "auto_close_after_last_post", name: "topic.auto_close_after_last_post.title" },
{ id: "auto_delete", name: "topic.auto_delete.title" },
+ { id: "auto_delete_after_last_post", name: "topic.auto_delete_after_last_post.title" },
{ id: "auto_delete_replies", name: "topic.auto_delete_replies.title" },
{ id: "auto_bump", name: "topic.auto_bump.title" },
],
@@ -47,6 +48,13 @@ DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scripts::SET_TOPIC_TIME
TopicTimer.types[:delete],
(Time.now + duration_minutes.minutes).iso8601,
)
+ when "auto_delete_after_last_post"
+ topic.set_or_create_timer(
+ TopicTimer.types[:delete],
+ nil,
+ based_on_last_post: true,
+ duration_minutes:,
+ )
when "auto_delete_replies"
topic.set_or_create_timer(TopicTimer.types[:delete_replies], nil, duration_minutes:)
when "auto_bump"
diff --git a/plugins/automation/spec/scripts/set_topic_timer_spec.rb b/plugins/automation/spec/scripts/set_topic_timer_spec.rb
index 55b2e2a732b..ef90f436b3d 100644
--- a/plugins/automation/spec/scripts/set_topic_timer_spec.rb
+++ b/plugins/automation/spec/scripts/set_topic_timer_spec.rb
@@ -105,6 +105,26 @@ describe "SetTopicTimer" do
end
end
+ it "handles auto_delete_after_last_post timer" do
+ configure_automation("auto_delete_after_last_post", 60)
+
+ freeze_time do
+ post =
+ PostCreator.new(
+ Fabricate(:admin),
+ raw: "my new topic",
+ title: "Test topic for timer",
+ ).create!
+
+ timer = post.topic.reload.topic_timers[0]
+ expect(timer).not_to be_nil
+ expect(timer.status_type).to eq(TopicTimer.types[:delete])
+ expect(timer.execute_at).to be_within(1.second).of(60.minutes.from_now)
+ expect(timer.duration_minutes).to eq(60)
+ expect(timer.based_on_last_post).to eq(true)
+ end
+ end
+
it "handles auto_bump timer" do
configure_automation("auto_bump", 60)