FEATURE: Topic timer for bumping a topic in the future

This commit is contained in:
David Taylor
2019-01-04 13:08:04 +00:00
parent c5b7bda198
commit 5bf16d7d10
6 changed files with 82 additions and 3 deletions

View File

@@ -9,7 +9,8 @@ import {
OPEN_STATUS_TYPE,
DELETE_STATUS_TYPE,
REMINDER_TYPE,
CLOSE_STATUS_TYPE
CLOSE_STATUS_TYPE,
BUMP_TYPE
} from "discourse/controllers/edit-topic-timer";
export default Ember.Component.extend({
@@ -17,12 +18,18 @@ export default Ember.Component.extend({
autoOpen: Ember.computed.equal("selection", OPEN_STATUS_TYPE),
autoClose: Ember.computed.equal("selection", CLOSE_STATUS_TYPE),
autoDelete: Ember.computed.equal("selection", DELETE_STATUS_TYPE),
autoBump: Ember.computed.equal("selection", BUMP_TYPE),
publishToCategory: Ember.computed.equal(
"selection",
PUBLISH_TO_CATEGORY_STATUS_TYPE
),
reminder: Ember.computed.equal("selection", REMINDER_TYPE),
showTimeOnly: Ember.computed.or("autoOpen", "autoDelete", "reminder"),
showTimeOnly: Ember.computed.or(
"autoOpen",
"autoDelete",
"reminder",
"autoBump"
),
@computed(
"topicTimer.updateTime",

View File

@@ -8,6 +8,7 @@ export const OPEN_STATUS_TYPE = "open";
export const PUBLISH_TO_CATEGORY_STATUS_TYPE = "publish_to_category";
export const DELETE_STATUS_TYPE = "delete";
export const REMINDER_TYPE = "reminder";
export const BUMP_TYPE = "bump";
export default Ember.Controller.extend(ModalFunctionality, {
loading: false,
@@ -31,6 +32,10 @@ export default Ember.Controller.extend(ModalFunctionality, {
{
id: PUBLISH_TO_CATEGORY_STATUS_TYPE,
name: I18n.t("topic.publish_to_category.title")
},
{
id: BUMP_TYPE,
name: I18n.t("topic.auto_bump.title")
}
];
if (this.currentUser.get("staff")) {

View File

@@ -0,0 +1,20 @@
module Jobs
class BumpTopic < Jobs::Base
def execute(args)
topic_timer = TopicTimer.find_by(id: args[:topic_timer_id] || args[:topic_status_update_id])
topic = topic_timer&.topic
if topic_timer.blank? || topic.blank? || topic_timer.execute_at > Time.zone.now
return
end
if Guardian.new(topic_timer.user).can_create_post_on_topic?(topic)
topic.add_small_action(Discourse.system_user, "autobumped", nil, bump: true)
end
topic_timer.trash!(Discourse.system_user)
end
end
end

View File

@@ -42,7 +42,8 @@ class TopicTimer < ActiveRecord::Base
open: 2,
publish_to_category: 3,
delete: 4,
reminder: 5
reminder: 5,
bump: 6
)
end
@@ -108,6 +109,14 @@ class TopicTimer < ActiveRecord::Base
Jobs.cancel_scheduled_job(:topic_reminder, topic_timer_id: id)
end
def cancel_auto_bump_job
Jobs.cancel_scheduled_job(:bump_topic, topic_timer_id: id)
end
def schedule_auto_bump_job(time)
Jobs.enqueue_at(time, :bump_topic, topic_timer_id: id)
end
def schedule_auto_open_job(time)
return unless topic
topic.update_status('closed', true, user) if !topic.closed