FEATURE: automatically delete replies on a topic after N days. (#9209)

This commit is contained in:
Vinoth Kannan
2020-03-19 21:06:31 +05:30
committed by GitHub
parent 0cd502a558
commit aad12822b7
16 changed files with 241 additions and 125 deletions
@@ -1,18 +1,15 @@
import { isEmpty } from "@ember/utils";
import { equal, or, readOnly } from "@ember/object/computed";
import { schedule } from "@ember/runloop";
import Component from "@ember/component";
import discourseComputed, {
observes,
on
} from "discourse-common/utils/decorators";
import discourseComputed, { observes } from "discourse-common/utils/decorators";
import {
PUBLISH_TO_CATEGORY_STATUS_TYPE,
OPEN_STATUS_TYPE,
DELETE_STATUS_TYPE,
REMINDER_TYPE,
CLOSE_STATUS_TYPE,
BUMP_TYPE
BUMP_TYPE,
DELETE_REPLIES_TYPE
} from "discourse/controllers/edit-topic-timer";
export default Component.extend({
@@ -23,15 +20,18 @@ export default Component.extend({
autoBump: equal("selection", BUMP_TYPE),
publishToCategory: equal("selection", PUBLISH_TO_CATEGORY_STATUS_TYPE),
reminder: equal("selection", REMINDER_TYPE),
autoDeleteReplies: equal("selection", DELETE_REPLIES_TYPE),
showTimeOnly: or("autoOpen", "autoDelete", "reminder", "autoBump"),
@discourseComputed(
"topicTimer.updateTime",
showFutureDateInput: or(
"showTimeOnly",
"publishToCategory",
"topicTimer.category_id"
)
saveDisabled(updateTime, publishToCategory, topicTimerCategoryId) {
return isEmpty(updateTime) || (publishToCategory && !topicTimerCategoryId);
"autoClose",
"autoDeleteReplies"
),
@discourseComputed("autoDeleteReplies")
durationType(autoDeleteReplies) {
return autoDeleteReplies ? "days" : "hours";
},
@discourseComputed("topic.visible")
@@ -39,25 +39,6 @@ export default Component.extend({
if (visible) return this.get("topic.category_id");
},
@on("init")
@observes("topicTimer", "topicTimer.execute_at", "topicTimer.duration")
_setUpdateTime() {
let time = null;
const executeAt = this.get("topicTimer.execute_at");
if (executeAt && this.get("topicTimer.based_on_last_post")) {
time = this.get("topicTimer.duration");
} else if (executeAt) {
const closeTime = moment(executeAt);
if (closeTime > moment()) {
time = closeTime.format("YYYY-MM-DD HH:mm");
}
}
this.set("topicTimer.updateTime", time);
},
@observes("selection")
_updateBasedOnLastPost() {
if (!this.autoClose) {
@@ -79,11 +60,5 @@ export default Component.extend({
);
}
});
},
actions: {
onChangeTimerType(value) {
this.set("topicTimer.status_type", value);
}
}
});