Class: ForumThread
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ForumThread
- Extended by:
- FriendlyId
- Defined in:
- app/models/forum_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.
80 81 82 |
# File 'app/models/forum_thread.rb', line 80 def notify_users [] end |
#subscribed?(user) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/forum_thread.rb', line 34 def subscribed?(user) return false if user.nil? subscription = subscription_for(user) if subscription.present? subscription.subscription_type == "optin" else forum_posts.where(user_id: user.id).any? end end |
#subscribed_reason(user) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/forum_thread.rb', line 58 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 forum_posts.where(user_id: user.id).any? I18n.t(".receiving_notifications_because_posted") else I18n.t(".not_receiving_notifications") end end |
#subscribed_users ⇒ Object
25 26 27 |
# File 'app/models/forum_thread.rb', line 25 def subscribed_users (users + optin_subscribers).uniq - optout_subscribers end |
#subscription_for(user) ⇒ Object
29 30 31 32 |
# File 'app/models/forum_thread.rb', line 29 def subscription_for(user) return nil if user.nil? forum_subscriptions.find_by(user_id: user.id) end |
#toggle_subscription(user) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/forum_thread.rb', line 46 def toggle_subscription(user) subscription = subscription_for(user) if subscription.present? subscription.toggle! elsif forum_posts.where(user_id: user.id).any? forum_subscriptions.create(user: user, subscription_type: "optout") else forum_subscriptions.create(user: user, subscription_type: "optin") end end |