Class: Decidim::Messaging::ReplyToConversation

Inherits:
Command
  • Object
show all
Defined in:
decidim-core/app/commands/decidim/messaging/reply_to_conversation.rb

Overview

A command with all the business logic for replying to a conversation

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(conversation, form) ⇒ ReplyToConversation

Public: Initializes the command.

conversation - The conversation to be updated. form - A form object with the params.



11
12
13
14
# File 'decidim-core/app/commands/decidim/messaging/reply_to_conversation.rb', line 11

def initialize(conversation, form)
  @conversation = conversation
  @form = form
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid, together with the message.

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'decidim-core/app/commands/decidim/messaging/reply_to_conversation.rb', line 22

def call
  if form.invalid?
    message.valid?
    return broadcast(:invalid, message.errors.full_messages)
  end

  if message.save
    notify_interlocutors
    notify_comanagers if sender.is_a?(UserGroup)

    broadcast(:ok, message)
  else
    broadcast(:invalid, message.errors.full_messages)
  end
end