help_center 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/LICENSE.txt +21 -21
  4. data/README.md +168 -164
  5. data/Rakefile +10 -10
  6. data/app/assets/stylesheets/help_center.scss +140 -139
  7. data/app/controllers/help_center/application_controller.rb +37 -37
  8. data/app/controllers/help_center/notifications_controller.rb +19 -19
  9. data/app/controllers/help_center/support_categories_controller.rb +58 -58
  10. data/app/controllers/help_center/support_posts_controller.rb +72 -72
  11. data/app/controllers/help_center/support_threads_controller.rb +82 -82
  12. data/app/helpers/help_center/support_posts_helper.rb +29 -29
  13. data/app/helpers/help_center/support_threads_helper.rb +28 -28
  14. data/app/jobs/help_center/support_post_notification_job.rb +42 -42
  15. data/app/jobs/help_center/support_thread_notification_job.rb +40 -40
  16. data/app/mailers/help_center/user_mailer.rb +28 -28
  17. data/app/models/support_category.rb +16 -13
  18. data/app/models/support_post.rb +15 -15
  19. data/app/models/support_subscription.rb +19 -19
  20. data/app/models/support_thread.rb +85 -85
  21. data/app/views/help_center/support_categories/_form.html.erb +39 -35
  22. data/app/views/help_center/support_categories/_support_thread.html.erb +25 -25
  23. data/app/views/help_center/support_categories/edit.html.erb +7 -7
  24. data/app/views/help_center/support_categories/index.html.erb +19 -19
  25. data/app/views/help_center/support_categories/new.html.erb +5 -5
  26. data/app/views/help_center/support_categories/show.html.erb +19 -20
  27. data/app/views/help_center/support_posts/_form.html.erb +47 -47
  28. data/app/views/help_center/support_posts/_support_post.html.erb +57 -57
  29. data/app/views/help_center/support_posts/edit.html.erb +23 -23
  30. data/app/views/help_center/support_threads/_form.html.erb +49 -49
  31. data/app/views/help_center/support_threads/_support_thread.html.erb +25 -25
  32. data/app/views/help_center/support_threads/edit.html.erb +7 -7
  33. data/app/views/help_center/support_threads/index.html.erb +19 -19
  34. data/app/views/help_center/support_threads/new.html.erb +5 -5
  35. data/app/views/help_center/support_threads/show.html.erb +29 -42
  36. data/app/views/help_center/user_mailer/new_post.html.erb +9 -9
  37. data/app/views/help_center/user_mailer/new_thread.html.erb +9 -9
  38. data/app/views/layouts/help_center.html.erb +130 -128
  39. data/app/views/shared/_category_actions.html.erb +16 -0
  40. data/app/views/shared/_spacer.html.erb +1 -1
  41. data/app/views/shared/_thread_actions.html.erb +16 -0
  42. data/bin/console +14 -14
  43. data/bin/setup +8 -8
  44. data/config/locales/en.yml +56 -55
  45. data/config/routes.rb +24 -24
  46. data/db/migrate/20170417012930_create_support_categories.rb +19 -19
  47. data/db/migrate/20170417012931_create_support_threads.rb +18 -18
  48. data/db/migrate/20170417012933_create_support_subscriptions.rb +11 -11
  49. data/help_center.gemspec +27 -29
  50. data/lib/generators/help_center/controllers_generator.rb +13 -13
  51. data/lib/generators/help_center/helpers_generator.rb +13 -13
  52. data/lib/generators/help_center/views_generator.rb +13 -13
  53. data/lib/help_center.rb +23 -23
  54. data/lib/help_center/engine.rb +10 -10
  55. data/lib/help_center/slack.rb +22 -22
  56. data/lib/help_center/support_user.rb +10 -10
  57. data/lib/help_center/version.rb +3 -3
  58. metadata +7 -19
  59. data/help_center-0.0.1.gem +0 -0
@@ -1,29 +1,29 @@
1
- module HelpCenter::SupportPostsHelper
2
- # Override this to use avatars from other places than Gravatar
3
- def avatar_tag(email)
4
- gravatar_image_tag(email, gravatar: { size: 40 }, class: "rounded avatar")
5
- end
6
-
7
- def support_category_link(category)
8
- link_to category.name, help_center.support_category_path(category),
9
- style: "color: #{category.color}"
10
- end
11
-
12
- # Override this method to provide your own content formatting like Markdown
13
- def formatted_content(text)
14
- simple_format(text)
15
- end
16
-
17
- def support_post_classes(support_post)
18
- klasses = ["support-post", "card", "mb-3"]
19
- klasses << "solved" if support_post.solved?
20
- klasses << "original-poster" if support_post.user == @support_thread.user
21
- klasses
22
- end
23
-
24
- def support_user_badge(user)
25
- if user.respond_to?(:moderator) && user.moderator?
26
- content_tag :span, "Mod", class: "badge badge-default"
27
- end
28
- end
29
- end
1
+ module HelpCenter::SupportPostsHelper
2
+ # Override this to use avatars from other places than Gravatar
3
+ def avatar_tag(email)
4
+ gravatar_image_tag(email, gravatar: { size: 40 }, class: "rounded avatar")
5
+ end
6
+
7
+ def support_category_link(category)
8
+ link_to category.name, help_center.support_category_path(category),
9
+ style: "color: #{category.color}"
10
+ end
11
+
12
+ # Override this method to provide your own content formatting like Markdown
13
+ def formatted_content(text)
14
+ simple_format(text)
15
+ end
16
+
17
+ def support_post_classes(support_post)
18
+ klasses = ["support-post", "card", "mb-3"]
19
+ klasses << "solved" if support_post.solved?
20
+ klasses << "original-poster" if support_post.user == @support_thread.user
21
+ klasses
22
+ end
23
+
24
+ def support_user_badge(user)
25
+ if user.respond_to?(:moderator) && user.moderator?
26
+ content_tag :span, "Mod", class: "badge badge-default"
27
+ end
28
+ end
29
+ end
@@ -1,28 +1,28 @@
1
- module HelpCenter::SupportThreadsHelper
2
- # Used for flagging links in the navbar as active
3
- def support_link_to(path, opts={}, &block)
4
- link_to path, class: support_link_class(path, opts), &block
5
- end
6
-
7
- def support_link_class(matches, opts={})
8
- case matches
9
- when Array
10
- "active" if matches.any?{ |m| request.path.starts_with?(m) }
11
- when String
12
- "active" if opts.fetch(:exact, false) ? request.path == matches : request.path.starts_with?(matches)
13
- end
14
- end
15
-
16
- # A nice hack to manipulate the layout so we can have sub-layouts
17
- # without any changes in the user's application.
18
- #
19
- # We use this for rendering the sidebar layout for all the support pages
20
- #
21
- # https://mattbrictson.com/easier-nested-layouts-in-rails
22
- #
23
- def parent_layout(layout)
24
- @view_flow.set(:layout, output_buffer)
25
- output = render(file: "layouts/#{layout}")
26
- self.output_buffer = ActionView::OutputBuffer.new(output)
27
- end
28
- end
1
+ module HelpCenter::SupportThreadsHelper
2
+ # Used for flagging links in the navbar as active
3
+ def support_link_to(path, opts={}, &block)
4
+ link_to path, class: support_link_class(path, opts), &block
5
+ end
6
+
7
+ def support_link_class(matches, opts={})
8
+ case matches
9
+ when Array
10
+ "active" if matches.any?{ |m| request.path.starts_with?(m) }
11
+ when String
12
+ "active" if opts.fetch(:exact, false) ? request.path == matches : request.path.starts_with?(matches)
13
+ end
14
+ end
15
+
16
+ # A nice hack to manipulate the layout so we can have sub-layouts
17
+ # without any changes in the user's application.
18
+ #
19
+ # We use this for rendering the sidebar layout for all the support pages
20
+ #
21
+ # https://mattbrictson.com/easier-nested-layouts-in-rails
22
+ #
23
+ def parent_layout(layout)
24
+ @view_flow.set(:layout, output_buffer)
25
+ output = render(template: "layouts/#{layout}")
26
+ self.output_buffer = ActionView::OutputBuffer.new(output)
27
+ end
28
+ end
@@ -1,42 +1,42 @@
1
- class HelpCenter::SupportPostNotificationJob < ApplicationJob
2
- include HelpCenter::Engine.routes.url_helpers
3
-
4
- def perform(support_post)
5
- send_emails(support_post) if HelpCenter.send_email_notifications
6
- send_webhook(support_post) if HelpCenter.send_slack_notifications
7
- end
8
-
9
- def send_emails(support_post)
10
- support_thread = support_post.support_thread
11
- users = support_thread.subscribed_users - [support_post.user]
12
- users.each do |user|
13
- HelpCenter::UserMailer.new_post(support_post, user).deliver_later
14
- end
15
- end
16
-
17
- def send_webhook(support_post)
18
- slack_webhook_url = Rails.application.secrets.help_center_slack_url
19
- return if slack_webhook_url.blank?
20
-
21
- support_thread = support_post.support_thread
22
- payload = {
23
- fallback: "#{support_post.user.name} replied to <#{support_thread_url(support_thread, anchor: ActionView::RecordIdentifier.dom_id(support_post))}|#{support_thread.title}>",
24
- pretext: "#{support_post.user.name} replied to <#{support_thread_url(support_thread, anchor: ActionView::RecordIdentifier.dom_id(support_post))}|#{support_thread.title}>",
25
- fields: [
26
- {
27
- title: "Thread",
28
- value: support_thread.title,
29
- short: true
30
- },
31
- {
32
- title: "Posted By",
33
- value: support_post.user.name,
34
- short: true,
35
- },
36
- ],
37
- ts: support_post.created_at.to_i
38
- }
39
-
40
- HelpCenter::Slack.new(slack_webhook_url).post(payload)
41
- end
42
- end
1
+ class HelpCenter::SupportPostNotificationJob < ApplicationJob
2
+ include HelpCenter::Engine.routes.url_helpers
3
+
4
+ def perform(support_post)
5
+ send_emails(support_post) if HelpCenter.send_email_notifications
6
+ send_webhook(support_post) if HelpCenter.send_slack_notifications
7
+ end
8
+
9
+ def send_emails(support_post)
10
+ support_thread = support_post.support_thread
11
+ users = support_thread.subscribed_users - [support_post.user]
12
+ users.each do |user|
13
+ HelpCenter::UserMailer.new_post(support_post, user).deliver_later
14
+ end
15
+ end
16
+
17
+ def send_webhook(support_post)
18
+ slack_webhook_url = Rails.application.secrets.help_center_slack_url
19
+ return if slack_webhook_url.blank?
20
+
21
+ support_thread = support_post.support_thread
22
+ payload = {
23
+ fallback: "#{support_post.user.name} replied to <#{support_thread_url(support_thread, anchor: ActionView::RecordIdentifier.dom_id(support_post))}|#{support_thread.title}>",
24
+ pretext: "#{support_post.user.name} replied to <#{support_thread_url(support_thread, anchor: ActionView::RecordIdentifier.dom_id(support_post))}|#{support_thread.title}>",
25
+ fields: [
26
+ {
27
+ title: "Thread",
28
+ value: support_thread.title,
29
+ short: true
30
+ },
31
+ {
32
+ title: "Posted By",
33
+ value: support_post.user.name,
34
+ short: true,
35
+ },
36
+ ],
37
+ ts: support_post.created_at.to_i
38
+ }
39
+
40
+ HelpCenter::Slack.new(slack_webhook_url).post(payload)
41
+ end
42
+ end
@@ -1,40 +1,40 @@
1
- class HelpCenter::SupportThreadNotificationJob < ApplicationJob
2
- include HelpCenter::Engine.routes.url_helpers
3
-
4
- def perform(support_thread)
5
- send_emails(support_thread) if HelpCenter.send_email_notifications
6
- send_webhook(support_thread) if HelpCenter.send_slack_notifications
7
- end
8
-
9
- def send_emails(support_thread)
10
- support_thread.notify_users.each do |user|
11
- HelpCenter::UserMailer.new_thread(support_thread, user).deliver_later
12
- end
13
- end
14
-
15
- def send_webhook(support_thread)
16
- slack_webhook_url = Rails.application.secrets.simple_discussion_slack_url
17
- return if slack_webhook_url.blank?
18
-
19
- support_post = support_thread.support_posts.first
20
- payload = {
21
- fallback: "A new discussion was started: <#{support_thread_url(support_thread, anchor: ActionView::RecordIdentifier.dom_id(support_posts))}|#{support_thread.title}>",
22
- pretext: "A new discussion was started: <#{support_thread_url(support_thread, anchor: ActionView::RecordIdentifier.dom_id(support_posts))}|#{support_thread.title}>",
23
- fields: [
24
- {
25
- title: "Thread",
26
- value: support_thread.title,
27
- short: true
28
- },
29
- {
30
- title: "Posted By",
31
- value: support_post.user.name,
32
- short: true,
33
- },
34
- ],
35
- ts: support_post.created_at.to_i
36
- }
37
-
38
- HelpCenter::Slack.new(slack_webhook_url).post(payload)
39
- end
40
- end
1
+ class HelpCenter::SupportThreadNotificationJob < ApplicationJob
2
+ include HelpCenter::Engine.routes.url_helpers
3
+
4
+ def perform(support_thread)
5
+ send_emails(support_thread) if HelpCenter.send_email_notifications
6
+ send_webhook(support_thread) if HelpCenter.send_slack_notifications
7
+ end
8
+
9
+ def send_emails(support_thread)
10
+ support_thread.notify_users.each do |user|
11
+ HelpCenter::UserMailer.new_thread(support_thread, user).deliver_later
12
+ end
13
+ end
14
+
15
+ def send_webhook(support_thread)
16
+ slack_webhook_url = Rails.application.secrets.simple_discussion_slack_url
17
+ return if slack_webhook_url.blank?
18
+
19
+ support_post = support_thread.support_posts.first
20
+ payload = {
21
+ fallback: "A new discussion was started: <#{support_thread_url(support_thread, anchor: ActionView::RecordIdentifier.dom_id(support_posts))}|#{support_thread.title}>",
22
+ pretext: "A new discussion was started: <#{support_thread_url(support_thread, anchor: ActionView::RecordIdentifier.dom_id(support_posts))}|#{support_thread.title}>",
23
+ fields: [
24
+ {
25
+ title: "Thread",
26
+ value: support_thread.title,
27
+ short: true
28
+ },
29
+ {
30
+ title: "Posted By",
31
+ value: support_post.user.name,
32
+ short: true,
33
+ },
34
+ ],
35
+ ts: support_post.created_at.to_i
36
+ }
37
+
38
+ HelpCenter::Slack.new(slack_webhook_url).post(payload)
39
+ end
40
+ end
@@ -1,28 +1,28 @@
1
- class HelpCenter::UserMailer < ApplicationMailer
2
- # You can set the default `from` address in ApplicationMailer
3
-
4
- helper HelpCenter::SupportPostsHelper
5
- helper HelpCenter::Engine.routes.url_helpers
6
-
7
- def new_thread(support_thread, recipient)
8
- @support_thread = support_thread
9
- @support_post = support_thread.support_posts.first
10
- @recipient = recipient
11
-
12
- mail(
13
- to: "#{@recipient.name} <#{@recipient.email}>",
14
- subject: @support_thread.title
15
- )
16
- end
17
-
18
- def new_post(support_post, recipient)
19
- @support_post = support_post
20
- @support_thread = support_post.support_thread
21
- @recipient = recipient
22
-
23
- mail(
24
- to: "#{@recipient.name} <#{@recipient.email}>",
25
- subject: "New post in #{@support_thread.title}"
26
- )
27
- end
28
- end
1
+ class HelpCenter::UserMailer < ApplicationMailer
2
+ # You can set the default `from` address in ApplicationMailer
3
+
4
+ helper HelpCenter::SupportPostsHelper
5
+ helper HelpCenter::Engine.routes.url_helpers
6
+
7
+ def new_thread(support_thread, recipient)
8
+ @support_thread = support_thread
9
+ @support_post = support_thread.support_posts.first
10
+ @recipient = recipient
11
+
12
+ mail(
13
+ to: "#{@recipient.name} <#{@recipient.email}>",
14
+ subject: @support_thread.title
15
+ )
16
+ end
17
+
18
+ def new_post(support_post, recipient)
19
+ @support_post = support_post
20
+ @support_thread = support_post.support_thread
21
+ @recipient = recipient
22
+
23
+ mail(
24
+ to: "#{@recipient.name} <#{@recipient.email}>",
25
+ subject: "New post in #{@support_thread.title}"
26
+ )
27
+ end
28
+ end
@@ -1,13 +1,16 @@
1
- class SupportCategory < ApplicationRecord
2
- extend FriendlyId
3
- friendly_id :name, use: :slugged
4
-
5
- scope :sorted, ->{ order(position: :asc) }
6
-
7
- validates :name, :slug, :color, presence: true
8
-
9
- def color
10
- colour = super
11
- colour.start_with?("#") ? colour : "##{colour}"
12
- end
13
- end
1
+ class SupportCategory < ApplicationRecord
2
+ extend FriendlyId
3
+ friendly_id :name, use: :slugged
4
+
5
+ has_many :support_threads
6
+ has_rich_text :description
7
+
8
+ scope :sorted, ->{ order(position: :asc) }
9
+
10
+ validates :name, :slug, :color, presence: true
11
+
12
+ def color
13
+ colour = super
14
+ colour.start_with?("#") ? colour : "##{colour}"
15
+ end
16
+ end
@@ -1,15 +1,15 @@
1
- class SupportPost < ApplicationRecord
2
- belongs_to :support_thread, counter_cache: true, touch: true
3
- belongs_to :user
4
- has_many :reactions, as: :reactable
5
-
6
- validates :user_id, :body, presence: true
7
-
8
- scope :sorted, ->{ order(:created_at) }
9
-
10
- after_update :solve_support_thread, if: :solved?
11
-
12
- def solve_support_thread
13
- support_thread.update(solved: true)
14
- end
15
- end
1
+ class SupportPost < ApplicationRecord
2
+ belongs_to :support_thread, counter_cache: true, touch: true
3
+ belongs_to :user
4
+ has_many :reactions, as: :reactable
5
+
6
+ validates :user_id, :body, presence: true
7
+
8
+ scope :sorted, ->{ order(:created_at) }
9
+
10
+ after_update :solve_support_thread, if: :solved?
11
+
12
+ def solve_support_thread
13
+ support_thread.update(solved: true)
14
+ end
15
+ end
@@ -1,19 +1,19 @@
1
- class SupportSubscription < ApplicationRecord
2
- belongs_to :support_thread
3
- belongs_to :user
4
-
5
- scope :optin, ->{ where(subscription_type: :optin) }
6
- scope :optout, ->{ where(subscription_type: :optout) }
7
-
8
- validates :subscription_type, presence: true, inclusion: { in: %w{ optin optout } }
9
- validates :user_id, uniqueness: { scope: :support_thread_id }
10
-
11
- def toggle!
12
- case subscription_type
13
- when "optin"
14
- update(subscription_type: "optout")
15
- when "optout"
16
- update(subscription_type: "optin")
17
- end
18
- end
19
- end
1
+ class SupportSubscription < ApplicationRecord
2
+ belongs_to :support_thread
3
+ belongs_to :user
4
+
5
+ scope :optin, ->{ where(subscription_type: :optin) }
6
+ scope :optout, ->{ where(subscription_type: :optout) }
7
+
8
+ validates :subscription_type, presence: true, inclusion: { in: %w{ optin optout } }
9
+ validates :user_id, uniqueness: { scope: :support_thread_id }
10
+
11
+ def toggle!
12
+ case subscription_type
13
+ when "optin"
14
+ update(subscription_type: "optout")
15
+ when "optout"
16
+ update(subscription_type: "optin")
17
+ end
18
+ end
19
+ end
@@ -1,85 +1,85 @@
1
- class SupportThread < ApplicationRecord
2
- extend FriendlyId
3
- friendly_id :title, use: :slugged
4
-
5
- belongs_to :support_category
6
- belongs_to :user
7
- has_many :support_posts
8
- has_many :support_subscriptions
9
- has_many :optin_subscribers, ->{ where(support_subscriptions: { subscription_type: :optin }) }, through: :support_subscriptions, source: :user
10
- has_many :optout_subscribers, ->{ where(support_subscriptions: { subscription_type: :optout }) }, through: :support_subscriptions, source: :user
11
- has_many :users, through: :support_posts
12
-
13
- has_rich_text :content
14
-
15
- accepts_nested_attributes_for :support_posts
16
-
17
- validates :support_category, presence: true
18
- validates :user_id, :title, presence: true
19
- validates_associated :support_posts
20
-
21
- scope :pinned_first, ->{ order(pinned: :desc) }
22
- scope :solved, ->{ where(solved: true) }
23
- scope :sorted, ->{ order(position: :asc) }
24
- scope :unpinned, ->{ where.not(pinned: true) }
25
- scope :unsolved, ->{ where.not(solved: true) }
26
-
27
- def subscribed_users
28
- (users + optin_subscribers).uniq - optout_subscribers
29
- end
30
-
31
- def subscription_for(user)
32
- return nil if user.nil?
33
- support_subscriptions.find_by(user_id: user.id)
34
- end
35
-
36
- def subscribed?(user)
37
- return false if user.nil?
38
-
39
- subscription = subscription_for(user)
40
-
41
- if subscription.present?
42
- subscription.subscription_type == "optin"
43
- else
44
- support_posts.where(user_id: user.id).any?
45
- end
46
- end
47
-
48
- def toggle_subscription(user)
49
- subscription = subscription_for(user)
50
-
51
- if subscription.present?
52
- subscription.toggle!
53
- elsif support_posts.where(user_id: user.id).any?
54
- support_subscriptions.create(user: user, subscription_type: "optout")
55
- else
56
- support_subscriptions.create(user: user, subscription_type: "optin")
57
- end
58
- end
59
-
60
- def subscribed_reason(user)
61
- return I18n.t('.not_receiving_notifications') if user.nil?
62
-
63
- subscription = subscription_for(user)
64
-
65
- if subscription.present?
66
- if subscription.subscription_type == "optout"
67
- I18n.t('.ignoring_thread')
68
- elsif subscription.subscription_type == "optin"
69
- I18n.t('.receiving_notifications_because_subscribed')
70
- end
71
- elsif support_posts.where(user_id: user.id).any?
72
- I18n.t('.receiving_notifications_because_posted')
73
- else
74
- I18n.t('.not_receiving_notifications')
75
- end
76
- end
77
-
78
- # These are the users to notify on a new thread. Currently this does nothing,
79
- # but you can override this to provide whatever functionality you like here.
80
- #
81
- # For example: You might use this to send all moderators an email of new threads.
82
- def notify_users
83
- []
84
- end
85
- end
1
+ class SupportThread < ApplicationRecord
2
+ extend FriendlyId
3
+ friendly_id :title, use: :slugged
4
+
5
+ belongs_to :support_category
6
+ belongs_to :user
7
+ has_many :support_posts
8
+ has_many :support_subscriptions
9
+ has_many :optin_subscribers, ->{ where(support_subscriptions: { subscription_type: :optin }) }, through: :support_subscriptions, source: :user
10
+ has_many :optout_subscribers, ->{ where(support_subscriptions: { subscription_type: :optout }) }, through: :support_subscriptions, source: :user
11
+ has_many :users, through: :support_posts
12
+
13
+ has_rich_text :content
14
+
15
+ accepts_nested_attributes_for :support_posts
16
+
17
+ validates :support_category, presence: true
18
+ validates :user_id, :title, presence: true
19
+ validates_associated :support_posts
20
+
21
+ scope :pinned_first, ->{ order(pinned: :desc) }
22
+ scope :solved, ->{ where(solved: true) }
23
+ scope :sorted, ->{ order(position: :asc) }
24
+ scope :unpinned, ->{ where.not(pinned: true) }
25
+ scope :unsolved, ->{ where.not(solved: true) }
26
+
27
+ def subscribed_users
28
+ (users + optin_subscribers).uniq - optout_subscribers
29
+ end
30
+
31
+ def subscription_for(user)
32
+ return nil if user.nil?
33
+ support_subscriptions.find_by(user_id: user.id)
34
+ end
35
+
36
+ def subscribed?(user)
37
+ return false if user.nil?
38
+
39
+ subscription = subscription_for(user)
40
+
41
+ if subscription.present?
42
+ subscription.subscription_type == "optin"
43
+ else
44
+ support_posts.where(user_id: user.id).any?
45
+ end
46
+ end
47
+
48
+ def toggle_subscription(user)
49
+ subscription = subscription_for(user)
50
+
51
+ if subscription.present?
52
+ subscription.toggle!
53
+ elsif support_posts.where(user_id: user.id).any?
54
+ support_subscriptions.create(user: user, subscription_type: "optout")
55
+ else
56
+ support_subscriptions.create(user: user, subscription_type: "optin")
57
+ end
58
+ end
59
+
60
+ def subscribed_reason(user)
61
+ return I18n.t('.not_receiving_notifications') if user.nil?
62
+
63
+ subscription = subscription_for(user)
64
+
65
+ if subscription.present?
66
+ if subscription.subscription_type == "optout"
67
+ I18n.t('.ignoring_thread')
68
+ elsif subscription.subscription_type == "optin"
69
+ I18n.t('.receiving_notifications_because_subscribed')
70
+ end
71
+ elsif support_posts.where(user_id: user.id).any?
72
+ I18n.t('.receiving_notifications_because_posted')
73
+ else
74
+ I18n.t('.not_receiving_notifications')
75
+ end
76
+ end
77
+
78
+ # These are the users to notify on a new thread. Currently this does nothing,
79
+ # but you can override this to provide whatever functionality you like here.
80
+ #
81
+ # For example: You might use this to send all moderators an email of new threads.
82
+ def notify_users
83
+ []
84
+ end
85
+ end