diff --git a/app/jobs/unresolved_topic_email_notification.rb b/app/jobs/unresolved_topic_email_notification.rb
new file mode 100644
index 00000000..65286836
--- /dev/null
+++ b/app/jobs/unresolved_topic_email_notification.rb
@@ -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
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 25ccf273..539789a7 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -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"
@@ -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.
+ Topic: %{topic_title}
+ Date: %{topic_created_at}
diff --git a/config/settings.yml b/config/settings.yml
index da6d43ee..3cc7e268 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -16,3 +16,6 @@ plugins:
client: false
solved_topics_auto_close_hours:
default: 0
+ solved_email_notification_delay:
+ default: 0
+ client: true
diff --git a/lib/refinements/user_notification_standing_topic.rb b/lib/refinements/user_notification_standing_topic.rb
new file mode 100644
index 00000000..52cb5dbf
--- /dev/null
+++ b/lib/refinements/user_notification_standing_topic.rb
@@ -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
diff --git a/plugin.rb b/plugin.rb
index cb3d809a..c51cebf9 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -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)