Sha256: 00abe981eb9ea4a36d96ef9a2f34db62db924d0f1d1cc3141a4c61394029755f

Contents?: true

Size: 851 Bytes

Versions: 25

Compression:

Stored size: 851 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, length: { maximum: Decidim.config.maximum_conversation_message_length }
      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

25 entries across 25 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.28.4 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.27.9 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.29.0 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.28.3 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.27.8 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.29.0.rc4 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.29.0.rc3 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.29.0.rc2 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.29.0.rc1 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.28.2 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.27.7 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.28.1 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.27.6 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.28.0 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.27.5 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.28.0.rc5 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.28.0.rc4 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.27.4 app/forms/decidim/messaging/conversation_form.rb
decidim-core-0.27.3 app/forms/decidim/messaging/conversation_form.rb