Sha256: 1334c972dc9198938f46f7bf3de029d621e2d16370ca061ea60293f7988207dc

Contents?: true

Size: 757 Bytes

Versions: 7

Compression:

Stored size: 757 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    class CommentVotedEvent < Decidim::Events::SimpleEvent
      include Decidim::Comments::CommentEvent

      i18n_attributes :upvotes
      i18n_attributes :downvotes

      def initialize(resource:, event_name:, user:, user_role: nil, extra: nil)
        resource = target_resource(resource)
        super
      end

      def upvotes
        extra[:upvotes]
      end

      def downvotes
        extra[:downvotes]
      end

      private

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

      def target_resource(t_resource)
        t_resource.is_a?(Decidim::Comments::Comment) ? t_resource.root_commentable : t_resource
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-comments-0.25.2 app/events/decidim/comments/comment_voted_event.rb
decidim-comments-0.25.1 app/events/decidim/comments/comment_voted_event.rb
decidim-comments-0.25.0 app/events/decidim/comments/comment_voted_event.rb
decidim-comments-0.25.0.rc4 app/events/decidim/comments/comment_voted_event.rb
decidim-comments-0.25.0.rc3 app/events/decidim/comments/comment_voted_event.rb
decidim-comments-0.25.0.rc2 app/events/decidim/comments/comment_voted_event.rb
decidim-comments-0.25.0.rc1 app/events/decidim/comments/comment_voted_event.rb