Class: Decidim::Messaging::ReplyToConversation

Inherits:
Rectify::Command
  • Object
show all
Defined in:
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

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 'app/commands/decidim/messaging/reply_to_conversation.rb', line 11

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

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

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

  • :invalid if the form wasn’t valid and we couldn’t proceed.

Returns nothing.



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

def call
  return broadcast(:invalid) if form.invalid?

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

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