Skip to content

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

DEV: Add immediate deletion warning for auto-delete-after-last-post timer (#38574)

Isaac Janzen37daea351f92
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index c22be7a0fdd..c34c30dec7a 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3990,6 +3990,9 @@ en:
auto_close_immediate:
one: "The last post in the topic is already %{count} hour old, so the topic will be closed immediately."
other: "The last post in the topic is already %{count} hours old, so the topic will be closed immediately."
+ auto_delete_immediate:
+ one: "The last post in the topic is already %{count} hour old, so the topic will be deleted immediately."
+ other: "The last post in the topic is already %{count} hours old, so the topic will be deleted immediately."
timeline:
back: "Back"
back_description: "Go back to your last unread post"
diff --git a/frontend/discourse/app/components/edit-topic-timer-form.gjs b/frontend/discourse/app/components/edit-topic-timer-form.gjs
index df47e21fd24..737d02c8c50 100644
--- a/frontend/discourse/app/components/edit-topic-timer-form.gjs
+++ b/frontend/discourse/app/components/edit-topic-timer-form.gjs
@@ -156,6 +156,16 @@ export default class EditTopicTimerForm extends Component {
}
}
+ get willDeleteImmediately() {
+ if (this.autoDeleteAfterLastPost && this.args.topicTimer.duration_minutes) {
+ const deleteDate = moment(this.args.topic.last_posted_at).add(
+ this.args.topicTimer.duration_minutes,
+ "minutes"
+ );
+ return deleteDate < moment();
+ }
+ }
+
get willCloseI18n() {
if (this.autoCloseAfterLastPost) {
const diff = Math.round(
@@ -166,6 +176,16 @@ export default class EditTopicTimerForm extends Component {
}
}
+ get willDeleteI18n() {
+ if (this.autoDeleteAfterLastPost) {
+ const diff = Math.round(
+ (new Date() - new Date(this.args.topic.last_posted_at)) /
+ (1000 * 60 * 60)
+ );
+ return i18n("topic.auto_delete_immediate", { count: diff });
+ }
+ }
+
get durationLabel() {
return i18n(
`topic.topic_status_update.num_of_${
@@ -175,7 +195,11 @@ export default class EditTopicTimerForm extends Component {
}
get showTopicTimerInfo() {
- if (!this.statusType || this.willCloseImmediately) {
+ if (
+ !this.statusType ||
+ this.willCloseImmediately ||
+ this.willDeleteImmediately
+ ) {
return false;
}
@@ -268,6 +292,13 @@ export default class EditTopicTimerForm extends Component {
</div>
{{/if}}
+ {{#if this.willDeleteImmediately}}
+ <div class="warning">
+ {{icon "triangle-exclamation"}}
+ {{this.willDeleteI18n}}
+ </div>
+ {{/if}}
+
{{#if this.showTopicTimerInfo}}
<div class="alert alert-info modal-topic-timer-info">
<TopicTimerInfo
diff --git a/frontend/discourse/app/components/modal/edit-topic-timer.gjs b/frontend/discourse/app/components/modal/edit-topic-timer.gjs
index 8a173c2b192..ebccaeafa78 100644
--- a/frontend/discourse/app/components/modal/edit-topic-timer.gjs
+++ b/frontend/discourse/app/components/modal/edit-topic-timer.gjs
@@ -232,6 +232,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(null, null, statusType);
// timer has been removed and we are removing `execute_at`
// which will hide the remove timer button from the modal
diff --git a/frontend/discourse/app/components/topic-timer-info.gjs b/frontend/discourse/app/components/topic-timer-info.gjs
index d7e913b6e7b..368d64cbbdd 100644
--- a/frontend/discourse/app/components/topic-timer-info.gjs
+++ b/frontend/discourse/app/components/topic-timer-info.gjs
@@ -159,6 +159,9 @@ export default class TopicTimerInfo extends Component {
if (this.basedOnLastPost && statusType === "close") {
statusType = "close_after_last_post";
}
+ if (this.basedOnLastPost && statusType === "delete") {
+ statusType = "delete_after_last_post";
+ }
return `topic.status_update_notice.auto_${statusType}`;
}
diff --git a/frontend/discourse/tests/acceptance/topic-edit-timer-test.js b/frontend/discourse/tests/acceptance/topic-edit-timer-test.js
index 26d8f92cace..8600d8b05cb 100644
--- a/frontend/discourse/tests/acceptance/topic-edit-timer-test.js
+++ b/frontend/discourse/tests/acceptance/topic-edit-timer-test.js
@@ -387,6 +387,43 @@ acceptance("Topic - Edit timer", function (needs) {
assert.dom(".topic-timer-heading").doesNotExist();
});
+ test("auto delete after last post", async function (assert) {
+ updateCurrentUser({ moderator: true });
+
+ await visit("/t/internationalization-localization");
+ await click(".toggle-admin-menu");
+ await click(".admin-topic-timer-update button");
+ await select(".timer-type", "delete_after_last_post");
+
+ const interval = selectKit(".select-kit.relative-time-intervals");
+ await interval.expand();
+ await interval.selectRowByValue("hours");
+
+ await fillIn(".relative-time-duration", "2");
+
+ assert
+ .dom(".edit-topic-timer-modal .warning")
+ .matchesText(/last post in the topic is already/);
+
+ const topic = topicFixtures["/t/54077.json"];
+ const lastPostIndex = topic.post_stream.posts.length - 1;
+ const time = topic.post_stream.posts[lastPostIndex].updated_at;
+ this.clock.restore();
+ this.clock = fakeTime(time, this.timezone, true);
+ await fillIn(".relative-time-duration", "6");
+
+ assert
+ .dom(".topic-timer-heading")
+ .hasText("This topic will be deleted 6 hours after the last reply.");
+
+ await interval.expand();
+ await interval.selectRowByValue("days");
+
+ assert
+ .dom(".topic-timer-heading")
+ .hasText("This topic will be deleted 6 days after the last reply.");
+ });
+
test("Close timer removed after manual close", async function (assert) {
updateCurrentUser({ moderator: true, trust_level: 4 });
diff --git a/frontend/discourse/tests/integration/components/topic-timer-info-test.gjs b/frontend/discourse/tests/integration/components/topic-timer-info-test.gjs
new file mode 100644
index 00000000000..74d99bf73fa
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/topic-timer-info-test.gjs
@@ -0,0 +1,27 @@
+import { render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import TopicTimerInfo from "discourse/components/topic-timer-info";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+
+module("Integration | Component | topic-timer-info", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("displays delete after last post notice when basedOnLastPost is true", async function (assert) {
+ const executeAt = moment().add(2, "days").toISOString();
+
+ await render(
+ <template>
+ <TopicTimerInfo
+ @statusType="delete"
+ @basedOnLastPost={{true}}
+ @executeAt={{executeAt}}
+ @durationMinutes={{2880}}
+ />
+ </template>
+ );
+
+ assert
+ .dom(".topic-timer-heading")
+ .matchesText(/will be deleted.*after the last reply/);
+ });
+});