class Decidim::Meetings::Admin::UpdateMeeting

panel.
This command is executed when the user changes a Meeting from the admin

def call

Broadcasts :ok if successful, :invalid otherwise.

Updates the meeting if valid.
def call
  return broadcast(:invalid) if form.invalid?
  transaction do
    update_meeting!
    send_notification if should_notify_followers?
    schedule_upcoming_meeting_notification if start_time_changed?
  end
  broadcast(:ok, meeting)
end

def important_attributes

def important_attributes
  %w(start_time end_time address)
end

def initialize(form, meeting)

meeting - The current instance of the page to be updated.
form - The form from which to get the data.

Initializes a UpdateMeeting Command.
def initialize(form, meeting)
  @form = form
  @meeting = meeting
end

def schedule_upcoming_meeting_notification

def schedule_upcoming_meeting_notification
  checksum = Decidim::Meetings::UpcomingMeetingNotificationJob.generate_checksum(meeting)
  Decidim::Meetings::UpcomingMeetingNotificationJob
    .set(wait_until: meeting.start_time - 2.days)
    .perform_later(meeting.id, checksum)
end

def send_notification

def send_notification
  Decidim::EventsManager.publish(
    event: "decidim.events.meetings.meeting_updated",
    event_class: Decidim::Meetings::UpdateMeetingEvent,
    resource: meeting,
    followers: meeting.followers
  )
end

def should_notify_followers?

def should_notify_followers?
  important_attributes.any? { |attr| meeting.previous_changes[attr].present? }
end

def start_time_changed?

def start_time_changed?
  meeting.previous_changes["start_time"].present?
end

def update_meeting!

def update_meeting!
  parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
  parsed_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.description, current_organization: form.current_organization).rewrite
  Decidim.traceability.update!(
    meeting,
    form.current_user,
    scope: form.scope,
    category: form.category,
    title: parsed_title,
    description: parsed_description,
    services: form.services_to_persist.map { |service| { "title" => service.title, "description" => service.description } },
    end_time: form.end_time,
    start_time: form.start_time,
    address: form.address,
    latitude: form.latitude,
    longitude: form.longitude,
    location: form.location,
    location_hints: form.location_hints,
    private_meeting: form.private_meeting,
    transparent: form.transparent,
    organizer: form.organizer
  )
end