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 am 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) ⇒ NewCommentNotificationCreator

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

mentioned


20
21
22
23
24
# File 'decidim-comments/app/services/decidim/comments/new_comment_notification_creator.rb', line 20

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

Instance Method Details

#createObject

Generates the notifications for the given comment.

Returns nothing.



29
30
31
32
33
34
# File 'decidim-comments/app/services/decidim/comments/new_comment_notification_creator.rb', line 29

def create
  notify_mentioned_users
  notify_parent_comment_author
  notify_author_followers
  notify_commentable_recipients
end