Sha256: d1b818074448c4d1cc7197cdf8285a86a357b34a5b47839fc61901d3597f4425

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

# frozen-string_literal: true

module Decidim
  module Comments
    # This module is used to be included in events triggered by comments.
    #
    module CommentEvent
      extend ActiveSupport::Concern
      include Decidim::Events::AuthorEvent

      included do
        def resource_path
          resource_locator.path(url_params)
        end

        def resource_url
          resource_locator.url(url_params)
        end

        def resource_text
          comment.formatted_body
        end

        def author
          comment.normalized_author
        end

        def author_presenter
          return unless author

          @author_presenter ||= case author
                                when Decidim::User
                                  Decidim::UserPresenter.new(author)
                                when Decidim::UserGroup
                                  Decidim::UserGroupPresenter.new(author)
                                end
        end

        private

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-comments-0.23.1.rc1 app/events/decidim/comments/comment_event.rb
decidim-comments-0.23.0 app/events/decidim/comments/comment_event.rb
decidim-comments-0.22.0 app/events/decidim/comments/comment_event.rb