Last active
July 7, 2016 13:26
-
-
Save fahrradflucht/98f2101c35f4677fc059 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Contact < ApplicationRecord | |
before_save :update_status_notifications | |
#... | |
def update_status_notifications | |
# Clear notifications | |
unless status_notification_ids.empty? | |
status_notification_ids.each do |id| | |
UserMailer.dequeue_status_notification(id) | |
end | |
status_notification_ids = [] | |
end | |
# Queue notifications | |
queue_status_notifications if last_meeting | |
end | |
def queue_status_notifications | |
status_middle_date = last_meeting + ideal_contact_frequency | |
if status_middle_date > Date.today | |
job = UserMailer.queue_status_middle_notification(self, wait_until: status_middle_date.to_time) | |
status_notification_ids << job.provider_job_id | |
end | |
status_bad_date = last_meeting + minimum_contact_frequency | |
if status_bad_date > Date.today | |
job = UserMailer.queue_status_bad_notification(self, wait_until: status_bad_date.to_time) | |
status_notification_ids << job.provider_job_id | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment