Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/jobs/unresolved_topic_email_notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
load File.expand_path("../../../lib/refinements/user_notification_standing_topic.rb", __FILE__)

module Jobs
class UnresolvedTopicEmailNotification < ::Jobs::Scheduled
using DiscourseSolved::Refinements::UserNotificationStandingTopic

every 1.day
def execute(args)
puts "email notification #{email_notification_enabled}"
if email_notification_enabled
unresolved_topics = Topic.joins(:category, :_custom_fields, category: :_custom_fields ).
where(
topic_custom_fields: {
name: 'accepted_answer_post_id',
value: nil
},
category_custom_fields: {
name: 'enable_accepted_answers',
value: 'true'
}
).where(
"topics.created_at <= ?::date + '1 day'::interval",
Date.today - SiteSetting.solved_email_notification_delay.days
)
puts unresolved_topics
unresolved_topics.each do |topic|
begin
email = UserNotifications.new.longstanding_topic(topic.user, { topic: topic })
email.deliver
rescue Exception => e
end
end
end
end

def email_notification_enabled
SiteSetting.solved_email_notification_delay > 0 && SiteSetting.solved_enabled
end
end
end
10 changes: 10 additions & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ en:
empty_box_on_unsolved: "Display an empty box next to unsolved topics"
solved_quote_length: "Number of characters to quote when displaying the solution under the first post"
solved_topics_auto_close_hours: "Auto close topic (n) hours after the last reply once the topic has been marked as solved"
solved_email_notification_delay: "Days until first email notification for unsolved topic sent. Insert '0' for never send email notification for unsolved topic."
solved_email_notification_repeat: "Days of repeated notification sent (After first notification sent). Insert '0' for never send repeated email notification."
reports:
accepted_solutions:
title: "Accepted solutions"
Expand All @@ -15,3 +17,11 @@ en:
no_solutions:
self: "You have no accepted solutions yet."
others: "No accepted solutions."
email:
long_standing_topic_notification:
subject_template: "It is been %{days_since_topic_created} days since you created %{topic_title}. Consider follow up the topic to get more feedback."
text_body_template: >
It is been %{days_since_topic_created} days since you created
%{topic_title}. Consider follow up the topic to get more feedback.<br/>
Topic&#58; %{topic_title}<br/>
Date&#58; %{topic_created_at}<br/>
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ plugins:
client: false
solved_topics_auto_close_hours:
default: 0
solved_email_notification_delay:
default: 0
client: true
23 changes: 23 additions & 0 deletions lib/refinements/user_notification_standing_topic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module DiscourseSolved
module Refinements
module UserNotificationStandingTopic
refine ::UserNotifications do
def longstanding_topic(user, opts)
build_email(user.email,
template: "solved.email.long_standing_topic_notification",
locale: user_locale(user),
email_token: opts[:email_token],
days_since_topic_created: days_since_topic_created(opts[:topic]),
topic_title: opts[:topic].title,
topic_created_at: opts[:topic].created_at.to_date.to_s(:long)
)
end

private
def days_since_topic_created(topic)
(Date.today - topic.created_at.to_date).to_i
end
end
end
end
end
1 change: 1 addition & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
register_asset 'stylesheets/solutions.scss'

after_initialize do
load File.expand_path("../app/jobs/unresolved_topic_email_notification.rb", __FILE__)

# we got to do a one time upgrade
if defined?(UserAction::SOLVED)
Expand Down