Class: TopicNotifier
- Inherits:
-
Object
- Object
- TopicNotifier
- Defined in:
- app/models/topic_notifier.rb
Instance Method Summary collapse
-
#initialize(topic) ⇒ TopicNotifier
constructor
A new instance of TopicNotifier.
- #muted?(user_id) ⇒ Boolean
-
#toggle_mute(user_id) ⇒ Object
Enable/disable the mute on the topic.
- #watch_topic!(user_id, reason = :created_topic) ⇒ Object
Constructor Details
#initialize(topic) ⇒ TopicNotifier
Returns a new instance of TopicNotifier.
4 5 6 |
# File 'app/models/topic_notifier.rb', line 4 def initialize(topic) @topic = topic end |
Instance Method Details
#muted?(user_id) ⇒ Boolean
28 29 30 31 |
# File 'app/models/topic_notifier.rb', line 28 def muted?(user_id) tu = @topic.topic_users.find_by(user_id: user_id) tu && tu.notification_level == levels[:muted] end |
#toggle_mute(user_id) ⇒ Object
Enable/disable the mute on the topic
24 25 26 |
# File 'app/models/topic_notifier.rb', line 24 def toggle_mute(user_id) change_level user_id, (muted?(user_id) ? levels[:regular] : levels[:muted]) end |
#watch_topic!(user_id, reason = :created_topic) ⇒ Object
19 20 21 |
# File 'app/models/topic_notifier.rb', line 19 def watch_topic!(user_id, reason = :created_topic) change_level user_id, :watching, reason end |