Class: SupportThread
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- SupportThread
- Extended by:
- FriendlyId
- Defined in:
- app/models/support_thread.rb
Instance Method Summary collapse
-
#notify_users ⇒ Object
These are the users to notify on a new thread.
- #subscribed?(user) ⇒ Boolean
- #subscribed_reason(user) ⇒ Object
- #subscribed_users ⇒ Object
- #subscription_for(user) ⇒ Object
- #toggle_subscription(user) ⇒ Object
Instance Method Details
#notify_users ⇒ Object
These are the users to notify on a new thread. Currently this does nothing, but you can override this to provide whatever functionality you like here.
For example: You might use this to send all moderators an email of new threads.
82 83 84 |
# File 'app/models/support_thread.rb', line 82 def notify_users [] end |
#subscribed?(user) ⇒ Boolean
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/support_thread.rb', line 36 def subscribed?(user) return false if user.nil? subscription = subscription_for(user) if subscription.present? subscription.subscription_type == "optin" else support_posts.where(user_id: user.id).any? end end |
#subscribed_reason(user) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/support_thread.rb', line 60 def subscribed_reason(user) return I18n.t('.not_receiving_notifications') if user.nil? subscription = subscription_for(user) if subscription.present? if subscription.subscription_type == "optout" I18n.t('.ignoring_thread') elsif subscription.subscription_type == "optin" I18n.t('.receiving_notifications_because_subscribed') end elsif support_posts.where(user_id: user.id).any? I18n.t('.receiving_notifications_because_posted') else I18n.t('.not_receiving_notifications') end end |
#subscribed_users ⇒ Object
27 28 29 |
# File 'app/models/support_thread.rb', line 27 def subscribed_users (users + optin_subscribers).uniq - optout_subscribers end |
#subscription_for(user) ⇒ Object
31 32 33 34 |
# File 'app/models/support_thread.rb', line 31 def subscription_for(user) return nil if user.nil? support_subscriptions.find_by(user_id: user.id) end |
#toggle_subscription(user) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/support_thread.rb', line 48 def toggle_subscription(user) subscription = subscription_for(user) if subscription.present? subscription.toggle! elsif support_posts.where(user_id: user.id).any? support_subscriptions.create(user: user, subscription_type: "optout") else support_subscriptions.create(user: user, subscription_type: "optin") end end |