Started notifications refactor

This commit is contained in:
Raphael Sofaer 2011-02-28 10:24:42 -08:00
parent 00ebf6469b
commit 809ee8a678
10 changed files with 64 additions and 24 deletions

View file

@ -6,7 +6,7 @@
module Job module Job
class MailRequestAcceptance < Base class MailRequestAcceptance < Base
@queue = :mail @queue = :mail
def self.perform_delegate(recipient_id, sender_id) def self.perform_delegate(recipient_id, sender_id, target_id)
Notifier.request_accepted(recipient_id, sender_id).deliver Notifier.request_accepted(recipient_id, sender_id).deliver
end end
end end

View file

@ -6,7 +6,7 @@
module Job module Job
class MailRequestReceived < Base class MailRequestReceived < Base
@queue = :mail @queue = :mail
def self.perform_delegate(recipient_id, sender_id) def self.perform_delegate(recipient_id, sender_id, target_id)
Notifier.new_request(recipient_id, sender_id).deliver Notifier.new_request(recipient_id, sender_id).deliver
end end
end end

View file

@ -31,18 +31,7 @@ class Notification < ActiveRecord::Base
end end
def email_the_user(target, actor) def email_the_user(target, actor)
case self.action self.recipient.mail(self.mail_job, self.recipient_id, actor.id, target.id)
when "new_request"
self.recipient.mail(Job::MailRequestReceived, self.recipient_id, actor.id)
when "request_accepted"
self.recipient.mail(Job::MailRequestAcceptance, self.recipient_id, actor.id)
when "comment_on_post"
self.recipient.mail(Job::MailCommentOnPost, self.recipient_id, actor.id, target.id)
when "also_commented"
self.recipient.mail(Job::MailAlsoCommented, self.recipient_id, actor.id, target.id)
when "mentioned"
self.recipient.mail(Job::MailMentioned, self.recipient_id, actor.id, target.id)
end
end end
private private

View file

@ -0,0 +1,5 @@
class Notifications::AlsoCommented < Notification
def mail_job
Job::MailAlsoCommented
end
end

View file

@ -0,0 +1,5 @@
class Notifications::CommentOnPost < Notification
def mail_job
Job::MailCommentOnPost
end
end

View file

@ -0,0 +1,5 @@
class Notifications::Mentioned < Notification
def mail_job
Job::MailMentioned
end
end

View file

@ -0,0 +1,5 @@
class Notifications::NewRequest < Notification
def mail_job
Job::MailRequestReceived
end
end

View file

@ -0,0 +1,5 @@
class Notifications::RequestAccepted < Notification
def mail_job
Job::MailRequestAcceptance
end
end

View file

@ -62,10 +62,6 @@ class NotificationMultiplePeople < ActiveRecord::Migration
end end
def self.down def self.down
remove_index :notification_actors, :notification_id raise ActiveRecord::IrreversibleMigration.new
remove_index :notification_actors, [:notification_id, :person_id]
remove_index :notification_actors, :person_id
drop_table :notification_actors
end end
end end

View file

@ -0,0 +1,30 @@
class NotificationSubclasses < ActiveRecord::Migration
def self.up
add_column :notifications, :type, :string, :null => :false
{:new_request => 'Notifications::NewRequest',
:request_accepted => 'Notifications::RequestAccepted',
:comment_on_post => 'Notifications::CommentOnPost',
:also_commented => 'Notifications::AlsoCommented',
:mentioned => 'Notifications::Mentioned'
}.each_pair do |key, value|
execute("UPDATE notifications
set type = #{value}
where action = #{key.to_s}")
end
remove_column :notifications, :action
end
def self.down
add_column :notifications, :action, :string
{:new_request => 'Notifications::NewRequest',
:request_accepted => 'Notifications::RequestAccepted',
:comment_on_post => 'Notifications::CommentOnPost',
:also_commented => 'Notifications::AlsoCommented',
:mentioned => 'Notifications::Mentioned'
}.each_pair do |key, value|
execute("UPDATE notifications
set action = #{key.to_s}
where type = #{value}")
remove_column :notifications, :type
end
end