Sha256: a149fceb540acd82230a889681206406f2025a7beb458721a0816c747945f8fc

Contents?: true

Size: 781 Bytes

Versions: 5

Compression:

Stored size: 781 Bytes

Contents

# frozen-string_literal: true

module Decidim
  module Comments
    class CommentCreatedEvent < Decidim::Events::SimpleEvent
      include Decidim::Events::AuthorEvent

      delegate :author, to: :comment

      def i18n_scope
        "decidim.events.comments.comment_created.#{comment_type}"
      end

      def resource_path
        resource_locator.path(url_params)
      end

      def resource_url
        resource_locator.url(url_params)
      end

      private

      def comment
        @comment ||= Decidim::Comments::Comment.find(extra[:comment_id])
      end

      def comment_type
        comment.depth.zero? ? :comment : :reply
      end

      def url_params
        comment_type == :comment ? {} : { anchor: "comment_#{comment.id}" }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-comments-0.10.1 app/events/decidim/comments/comment_created_event.rb
decidim-comments-0.10.0 app/events/decidim/comments/comment_created_event.rb
decidim-comments-0.9.3 app/events/decidim/comments/comment_created_event.rb
decidim-comments-0.9.2 app/events/decidim/comments/comment_created_event.rb
decidim-comments-0.9.1 app/events/decidim/comments/comment_created_event.rb