Class: Decidim::Comments::NewCommentNotificationCreator

Inherits:
Object
  • Object
show all
Defined in:
decidim-comments/app/services/decidim/comments/new_comment_notification_creator.rb

Overview

This class handles what events must be triggered, and to what users, after a comment is created. Handles these cases:

  • A user is mentioned in the comment

  • My comment is replied

  • A user I'm following has created a comment/reply

  • A new comment has been created on a resource, and I should be notified.

A given user will only receive one of these notifications, for a given comment. The comment author will never be notified about their own comment. If need be, the code to handle this cases can be swapped easily.

Instance Method Summary collapse

Constructor Details

#initialize(comment, mentioned_users, mentioned_groups = nil) ⇒ NewCommentNotificationCreator

comment - the Comment from which to generate notifications. mentioned_users - An ActiveRecord::Relation of the users that have been

mentioned

mentioned_groups - And ActiveRecord::Relation of the user_groups that have

been mentioned

22
23
24
25
26
27
# File 'decidim-comments/app/services/decidim/comments/new_comment_notification_creator.rb', line 22

def initialize(comment, mentioned_users, mentioned_groups = nil)
  @comment = comment
  @mentioned_users = mentioned_users
  @mentioned_groups = mentioned_groups
  @already_notified_users = [comment.author]
end

Instance Method Details

#createObject

Generates the notifications for the given comment.

Returns nothing.


32
33
34
35
36
37
38
39
# File 'decidim-comments/app/services/decidim/comments/new_comment_notification_creator.rb', line 32

def create
  notify_mentioned_users
  notify_mentioned_groups
  notify_parent_comment_author
  notify_author_followers
  notify_user_group_followers
  notify_commentable_recipients
end