Sha256: 74c57528c62756f1f6dbae513cfbe88dbc1e311ce2ec80a90d60151b76bbe781

Contents?: true

Size: 906 Bytes

Versions: 28

Compression:

Stored size: 906 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    class UpcomingMeetingNotificationJob < ApplicationJob
      queue_as :events

      def perform(meeting_id, checksum)
        meeting = Decidim::Meetings::Meeting.find(meeting_id)
        send_notification(meeting) if verify_checksum(meeting, checksum)
      end

      def self.generate_checksum(meeting)
        Digest::MD5.hexdigest("#{meeting.id}-#{meeting.start_time}")
      end

      private

      def send_notification(meeting)
        Decidim::EventsManager.publish(
          event: "decidim.events.meetings.upcoming_meeting",
          event_class: Decidim::Meetings::UpcomingMeetingEvent,
          resource: meeting,
          recipient_ids: meeting.followers.pluck(:id)
        )
      end

      def verify_checksum(meeting, checksum)
        self.class.generate_checksum(meeting) == checksum
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
decidim-meetings-0.15.2 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.15.1 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.15.0 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.14.4 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.14.3 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.14.2 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.14.1 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.13.1 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.12.2 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.13.0 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.12.1 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.13.0.pre1 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.12.0 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.11.2 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.12.0.pre app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.11.1 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.11.0.pre1 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.10.1 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.10.0 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb
decidim-meetings-0.9.3 app/jobs/decidim/meetings/upcoming_meeting_notification_job.rb