Created
April 29, 2014 12:29
-
-
Save madsheep/c0e20777fb4f08e2e032 to your computer and use it in GitHub Desktop.
not simple at all
This file contains 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 Membership | |
belongs_to :user | |
belogns_to :group | |
after_save :send_notifications, if: ->(m) { m.accepted_changed? && m.accepted? } | |
def send_notifications | |
Resque.enqeue(NotificationMailerWorker, self.id, user.id) | |
Resque.enqeue(PushNotifcations::NewMembershipWorker, self.id, user.id) | |
admins = group.admins - user | |
admins.each do |admin| | |
Resque.enqeue(NotificationMailerForAdminWorker, self.id, user.id) | |
Resque.enqeue(PushNotifcations::NewMembershipWorkerForAdmin, self.id, user.id) | |
end | |
end | |
end | |
class NotificationMailerWorker | |
def perform(membership_id, user_id) | |
membership = Membership.find(membership_id) | |
user = User.find(user_id) | |
NotificationMailer.accepted(membership, user).deliver! | |
end | |
end | |
class PushNotifcations::NewMembershipWorker | |
def perform(membership_id, user_id) | |
membership = Membership.find(membership_id) | |
user = User.find(user_id) | |
PushNotifcations::NewMembership.new(membership, user).dispatch! | |
end | |
end | |
class NotificationMailerForAdminWorker | |
def perform(membership_id, admin_id) | |
membership = Membership.find(membership_id) | |
admin = User.find(admin_id) | |
NotificationMailer.accepted_admin(membership, admin).deliver! | |
end | |
end | |
class PushNotifcations::NewMembershipWorkerForAdmin | |
def perform(membership_id, admin_id) | |
membership = Membership.find(membership_id) | |
admin = User.find(admin_id) | |
PushNotifcations::NewMembershipForAdmin.new(membership, admin).dispatch! | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment