class Decidim::Meetings::LeaveMeeting

This command is executed when the user leaves a meeting.

def call

Broadcasts :ok if successful, :invalid otherwise.

and the registration exists.
Destroys a meeting registration if the meeting has registrations enabled
def call
  return broadcast(:invalid) unless registration
  @meeting.with_lock do
    destroy_registration
    destroy_questionnaire_answers
    decrement_score
  end
  broadcast(:ok)
end

def decrement_score

def decrement_score
  Decidim::Gamification.decrement_score(@user, :attended_meetings)
end

def destroy_questionnaire_answers

def destroy_questionnaire_answers
  questionnaire_answers.try(:destroy_all)
end

def destroy_registration

def destroy_registration
  registration.destroy!
end

def initialize(meeting, user)

user - The user leaving the meeting.
meeting - The current instance of the meeting to be left.

Initializes a LeaveMeeting Command.
def initialize(meeting, user)
  @meeting = meeting
  @user = user
end

def questionnaire_answers

def questionnaire_answers
  questionnaire = Decidim::Forms::Questionnaire.find_by(questionnaire_for_id: @meeting)
  questionnaire.answers.where(user: @user) if questionnaire.present?
end

def registration

def registration
  @registration ||= Decidim::Meetings::Registration.find_by(meeting: @meeting, user: @user)
end