forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: staff can set a timer to remind them about a topic
- Loading branch information
Showing
20 changed files
with
255 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Jobs | ||
class TopicReminder < Jobs::Base | ||
|
||
def execute(args) | ||
topic_timer = TopicTimer.find_by(id: args[:topic_timer_id]) | ||
|
||
topic = topic_timer&.topic | ||
user = topic_timer&.user | ||
|
||
if topic_timer.blank? || topic.blank? || user.blank? || | ||
topic_timer.execute_at > Time.zone.now | ||
return | ||
end | ||
|
||
user.notifications.create!( | ||
notification_type: Notification.types[:topic_reminder], | ||
topic_id: topic.id, | ||
post_number: 1, | ||
data: { topic_title: topic.title, display_username: user.username }.to_json | ||
) | ||
|
||
topic_timer.trash!(Discourse.system_user) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
db/migrate/20170515203721_add_public_type_to_topic_timers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class AddPublicTypeToTopicTimers < ActiveRecord::Migration | ||
def up | ||
add_column :topic_timers, :public_type, :boolean, default: true | ||
|
||
execute("drop index idx_topic_id_status_type_deleted_at") rescue nil | ||
|
||
# Only one public timer per topic (close, open, delete): | ||
execute <<~SQL | ||
CREATE UNIQUE INDEX idx_topic_id_public_type_deleted_at | ||
ON topic_timers (topic_id) | ||
WHERE public_type = TRUE | ||
AND deleted_at IS NULL | ||
SQL | ||
end | ||
|
||
def down | ||
execute "DROP INDEX idx_topic_id_public_type_deleted_at" | ||
|
||
execute <<~SQL | ||
CREATE UNIQUE INDEX idx_topic_id_status_type_deleted_at | ||
ON topic_timers (topic_id, status_type) | ||
WHERE deleted_at IS NULL | ||
SQL | ||
|
||
remove_column :topic_timers, :public_type | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.