Started notifications refactor
This commit is contained in:
parent
00ebf6469b
commit
809ee8a678
10 changed files with 64 additions and 24 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
5
app/models/notifications/also_commented.rb
Normal file
5
app/models/notifications/also_commented.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class Notifications::AlsoCommented < Notification
|
||||||
|
def mail_job
|
||||||
|
Job::MailAlsoCommented
|
||||||
|
end
|
||||||
|
end
|
||||||
5
app/models/notifications/comment_on_post.rb
Normal file
5
app/models/notifications/comment_on_post.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class Notifications::CommentOnPost < Notification
|
||||||
|
def mail_job
|
||||||
|
Job::MailCommentOnPost
|
||||||
|
end
|
||||||
|
end
|
||||||
5
app/models/notifications/mentioned.rb
Normal file
5
app/models/notifications/mentioned.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class Notifications::Mentioned < Notification
|
||||||
|
def mail_job
|
||||||
|
Job::MailMentioned
|
||||||
|
end
|
||||||
|
end
|
||||||
5
app/models/notifications/new_request.rb
Normal file
5
app/models/notifications/new_request.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class Notifications::NewRequest < Notification
|
||||||
|
def mail_job
|
||||||
|
Job::MailRequestReceived
|
||||||
|
end
|
||||||
|
end
|
||||||
5
app/models/notifications/request_accepted.rb
Normal file
5
app/models/notifications/request_accepted.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class Notifications::RequestAccepted < Notification
|
||||||
|
def mail_job
|
||||||
|
Job::MailRequestAcceptance
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -5,7 +5,7 @@ class NotificationMultiplePeople < ActiveRecord::Migration
|
||||||
t.integer :person_id
|
t.integer :person_id
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index :notification_actors, :notification_id
|
add_index :notification_actors, :notification_id
|
||||||
add_index :notification_actors, [:notification_id, :person_id] , :unique => true
|
add_index :notification_actors, [:notification_id, :person_id] , :unique => true
|
||||||
add_index :notification_actors, :person_id ## if i am not mistaken we don't need this one because we won't query person.notifications
|
add_index :notification_actors, :person_id ## if i am not mistaken we don't need this one because we won't query person.notifications
|
||||||
|
|
@ -14,15 +14,15 @@ class NotificationMultiplePeople < ActiveRecord::Migration
|
||||||
execute "INSERT INTO notification_actors (notification_id, person_id) " +
|
execute "INSERT INTO notification_actors (notification_id, person_id) " +
|
||||||
" SELECT id , actor_id " +
|
" SELECT id , actor_id " +
|
||||||
" FROM notifications"
|
" FROM notifications"
|
||||||
|
|
||||||
#update the notifications to reference the post
|
#update the notifications to reference the post
|
||||||
execute "UPDATE notifications, comments " +
|
execute "UPDATE notifications, comments " +
|
||||||
"SET notifications.target_id = comments.post_id, " +
|
"SET notifications.target_id = comments.post_id, " +
|
||||||
"target_type = 'Post' " +
|
"target_type = 'Post' " +
|
||||||
"WHERE (notifications.target_id = comments.id " +
|
"WHERE (notifications.target_id = comments.id " +
|
||||||
"AND (notifications.action = 'comment_on_post' " +
|
"AND (notifications.action = 'comment_on_post' " +
|
||||||
"OR notifications.action = 'also_commented'))"
|
"OR notifications.action = 'also_commented'))"
|
||||||
|
|
||||||
#select all the notifications to keep
|
#select all the notifications to keep
|
||||||
execute "CREATE TEMPORARY TABLE keep_table " +
|
execute "CREATE TEMPORARY TABLE keep_table " +
|
||||||
"(SELECT id as keep_id, actor_id , target_type , target_id , recipient_id , action " +
|
"(SELECT id as keep_id, actor_id , target_type , target_id , recipient_id , action " +
|
||||||
|
|
@ -49,7 +49,7 @@ class NotificationMultiplePeople < ActiveRecord::Migration
|
||||||
|
|
||||||
#delete all the notifications that need to be deleted
|
#delete all the notifications that need to be deleted
|
||||||
execute "DELETE notifications.* " +
|
execute "DELETE notifications.* " +
|
||||||
"FROM notifications, keep_delete " +
|
"FROM notifications, keep_delete " +
|
||||||
"WHERE notifications.id != keep_delete.keep_id AND "+
|
"WHERE notifications.id != keep_delete.keep_id AND "+
|
||||||
"notifications.target_type = keep_delete.target_type AND "+
|
"notifications.target_type = keep_delete.target_type AND "+
|
||||||
"notifications.target_id = keep_delete.target_id AND "+
|
"notifications.target_id = keep_delete.target_id AND "+
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
30
db/migrate/20110228180709_notification_subclasses.rb
Normal file
30
db/migrate/20110228180709_notification_subclasses.rb
Normal 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
|
||||||
Loading…
Reference in a new issue