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
@@ -3,7 +3,10 @@ import { cancel, later } from "@ember/runloop";
import Component from "@ember/component";
import { iconHTML } from "discourse-common/lib/icon-library";
import Category from "discourse/models/category";
import { REMINDER_TYPE } from "discourse/controllers/edit-topic-timer";
import {
REMINDER_TYPE,
DELETE_REPLIES_TYPE
} from "discourse/controllers/edit-topic-timer";
import ENV from "discourse-common/config/environment";
export default Component.extend({
@@ -28,7 +31,13 @@ export default Component.extend({
},
renderTopicTimer() {
if (!this.executeAt || this.executeAt < moment()) {
const isDeleteRepliesType = this.statusType === DELETE_REPLIES_TYPE;
if (
!isDeleteRepliesType &&
!this.basedOnLastPost &&
(!this.executeAt || this.executeAt < moment())
) {
this.set("showTopicTimer", null);
return;
}
@@ -40,7 +49,7 @@ export default Component.extend({
const statusUpdateAt = moment(this.executeAt);
const duration = moment.duration(statusUpdateAt - moment());
const minutesLeft = duration.asMinutes();
if (minutesLeft > 0) {
if (minutesLeft > 0 || isDeleteRepliesType || this.basedOnLastPost) {
let rerenderDelay = 1000;
if (minutesLeft > 2160) {
rerenderDelay = 12 * 60 * 60000;
@@ -51,11 +60,15 @@ export default Component.extend({
} else if (minutesLeft > 2) {
rerenderDelay = 60000;
}
let autoCloseHours = this.duration || 0;
let durationHours = parseInt(this.duration, 0) || 0;
if (isDeleteRepliesType) {
durationHours *= 24;
}
let options = {
timeLeft: duration.humanize(true),
duration: moment.duration(autoCloseHours, "hours").humanize()
duration: moment.duration(durationHours, "hours").humanize()
};
const categoryId = this.categoryId;