Class: Decidim::Meetings::JoinMeeting

Inherits:
Rectify::Command
  • Object
show all
Defined in:
decidim-meetings/app/commands/decidim/meetings/join_meeting.rb

Overview

This command is executed when the user joins a meeting.

Instance Method Summary collapse

Constructor Details

#initialize(meeting, user, registration_form) ⇒ JoinMeeting

Initializes a JoinMeeting Command.

meeting - The current instance of the meeting to be joined. user - The user joining the meeting. registration_form - A form object with params; can be a questionnaire.


12
13
14
15
16
17
# File 'decidim-meetings/app/commands/decidim/meetings/join_meeting.rb', line 12

def initialize(meeting, user, registration_form)
  @meeting = meeting
  @user = user
  @user_group = Decidim::UserGroup.find_by(id: registration_form.user_group_id)
  @registration_form = registration_form
end

Instance Method Details

#callObject

Creates a meeting registration if the meeting has registrations enabled and there are available slots.

Broadcasts :ok if successful, :invalid otherwise.


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'decidim-meetings/app/commands/decidim/meetings/join_meeting.rb', line 23

def call
  meeting.with_lock do
    return broadcast(:invalid) unless can_join_meeting?
    return broadcast(:invalid_form) unless registration_form.valid?

    answer_questionnaire
    create_registration
    accept_invitation
    send_email_confirmation
    send_notification_confirmation
    notify_admin_over_percentage
    increment_score
  end
  follow_meeting
  broadcast(:ok)
end