Sha256: bffebbb049b901dd06d973d6f9693b10275e0ce9df5e712f7f223d692aa58501

Contents?: true

Size: 776 Bytes

Versions: 6

Compression:

Stored size: 776 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Messaging
    # A form object to be used when users want to message another user.
    class ConversationForm < Decidim::Form
      mimic :conversation

      attribute :body, Decidim::Attributes::CleanString
      attribute :recipient_id, Integer

      validates :body, :recipient, presence: true
      validate :check_recipient

      def recipient
        @recipient ||= Decidim::UserBaseEntity
                       .includes(:following_follows)
                       .where.not(id: context.sender.id)
                       .where(organization: context.sender.organization)
                       .where(id: recipient_id)
      end

      def check_recipient
        !@recipient.empty?
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.24.3 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.24.2 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.24.1 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.24.0 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.24.0.rc2 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.24.0.rc1 app/forms/decidim/messaging/conversation_form.rb