wip
This commit is contained in:
parent
f48d7a0826
commit
9d4d0cecdb
4 changed files with 34 additions and 20 deletions
|
|
@ -7,7 +7,8 @@ class Notification < ActiveRecord::Base
|
||||||
include Diaspora::Socketable
|
include Diaspora::Socketable
|
||||||
|
|
||||||
belongs_to :recipient, :class_name => 'User'
|
belongs_to :recipient, :class_name => 'User'
|
||||||
has_many :actors, :class_name => 'Person', :through => :notification_actors
|
has_many :notification_actors
|
||||||
|
has_many :actors, :class_name => 'Person', :through => :notification_actors, :source => :person
|
||||||
belongs_to :target, :polymorphic => true
|
belongs_to :target, :polymorphic => true
|
||||||
|
|
||||||
def self.for(recipient, opts={})
|
def self.for(recipient, opts={})
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ class Person < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :owner, :class_name => 'User'
|
belongs_to :owner, :class_name => 'User'
|
||||||
|
|
||||||
|
has_many :notification_actors
|
||||||
has_many :notifications, :through => :notification_actors
|
has_many :notifications, :through => :notification_actors
|
||||||
|
|
||||||
before_destroy :remove_all_traces
|
before_destroy :remove_all_traces
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,45 @@
|
||||||
class NotificationMultiplePeople < ActiveRecord::Migration
|
class NotificationMultiplePeople < ActiveRecord::Migration
|
||||||
def self.up
|
def self.up
|
||||||
create_table :notification_actors do |t|
|
create_table :notification_actors do |t|
|
||||||
t.integer :notifications_id
|
t.integer :notification_id
|
||||||
t.integer :person_id
|
t.integer :person_id
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index :notification_actors, :notifications_id
|
add_index :notification_actors, :notification_id
|
||||||
add_index :notification_actors, [:notifications_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
|
||||||
|
|
||||||
execute "INSERT INTO notification_actors (id, person_id) " +
|
execute "INSERT INTO notification_actors (notification_id, person_id) " +
|
||||||
" SELECT id , actor_id " +
|
" SELECT id , actor_id " +
|
||||||
" FROM notifications"
|
" FROM notifications"
|
||||||
|
|
||||||
|
#TODO in sql
|
||||||
|
#bump up target to status message id if comment_on_post, also_commented
|
||||||
|
['comment_on_post', 'also_commented'].each do |type|
|
||||||
|
|
||||||
|
Notification.where(:type => 'comment_on_post').all.each{|n|
|
||||||
|
n.target_id => Comment.find(n.target_id).post}
|
||||||
|
|
||||||
|
#for each user
|
||||||
|
all = Notification.where(:type => 'comment_on_post', :user => user).all
|
||||||
|
first = all.first
|
||||||
|
all[1..all.length-1].each{ |a|
|
||||||
|
first << a.notification_actors
|
||||||
|
a.delete
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# all notification of same type with the same
|
||||||
|
|
||||||
|
|
||||||
|
remove_column :notification, :actor_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.down
|
def self.down
|
||||||
remove_index :notification_actors, :notifications_id
|
remove_index :notification_actors, :notification_id
|
||||||
remove_index :notification_actors, [:notifications_id, :person_id]
|
remove_index :notification_actors, [:notification_id, :person_id]
|
||||||
remove_index :notification_actors, :person_id
|
remove_index :notification_actors, :person_id
|
||||||
|
|
||||||
drop_table :notification_actors
|
drop_table :notification_actors
|
||||||
|
|
|
||||||
16
db/schema.rb
16
db/schema.rb
|
|
@ -47,7 +47,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
||||||
t.text "youtube_titles"
|
t.text "youtube_titles"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "comments", ["guid"], :name => "index_comments_on_guid", :unique => true
|
add_index "comments", ["guid"], :name => "index_comments_on_guid", :unique => true
|
||||||
|
|
@ -61,7 +60,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
||||||
t.boolean "pending", :default => true, :null => false
|
t.boolean "pending", :default => true, :null => false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "contacts", ["mongo_id"], :name => "index_contacts_on_mongo_id"
|
add_index "contacts", ["mongo_id"], :name => "index_contacts_on_mongo_id"
|
||||||
|
|
@ -86,7 +84,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
||||||
t.integer "aspect_id"
|
t.integer "aspect_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "invitations", ["aspect_id"], :name => "index_invitations_on_aspect_id"
|
add_index "invitations", ["aspect_id"], :name => "index_invitations_on_aspect_id"
|
||||||
|
|
@ -294,14 +291,14 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
||||||
add_index "mongo_users", ["mongo_id"], :name => "index_mongo_users_on_mongo_id", :unique => true
|
add_index "mongo_users", ["mongo_id"], :name => "index_mongo_users_on_mongo_id", :unique => true
|
||||||
|
|
||||||
create_table "notification_actors", :force => true do |t|
|
create_table "notification_actors", :force => true do |t|
|
||||||
t.integer "notifications_id"
|
t.integer "notification_id"
|
||||||
t.integer "person_id"
|
t.integer "person_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "notification_actors", ["notifications_id", "person_id"], :name => "index_notification_actors_on_notifications_id_and_person_id", :unique => true
|
add_index "notification_actors", ["notification_id", "person_id"], :name => "index_notification_actors_on_notification_id_and_person_id", :unique => true
|
||||||
add_index "notification_actors", ["notifications_id"], :name => "index_notification_actors_on_notifications_id"
|
add_index "notification_actors", ["notification_id"], :name => "index_notification_actors_on_notification_id"
|
||||||
add_index "notification_actors", ["person_id"], :name => "index_notification_actors_on_person_id"
|
add_index "notification_actors", ["person_id"], :name => "index_notification_actors_on_person_id"
|
||||||
|
|
||||||
create_table "notifications", :force => true do |t|
|
create_table "notifications", :force => true do |t|
|
||||||
|
|
@ -313,7 +310,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
||||||
t.boolean "unread", :default => true, :null => false
|
t.boolean "unread", :default => true, :null => false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "notifications", ["mongo_id"], :name => "index_notifications_on_mongo_id"
|
add_index "notifications", ["mongo_id"], :name => "index_notifications_on_mongo_id"
|
||||||
|
|
@ -329,7 +325,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
||||||
t.integer "owner_id"
|
t.integer "owner_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "people", ["diaspora_handle"], :name => "index_people_on_diaspora_handle", :unique => true
|
add_index "people", ["diaspora_handle"], :name => "index_people_on_diaspora_handle", :unique => true
|
||||||
|
|
@ -365,7 +360,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
||||||
t.text "youtube_titles"
|
t.text "youtube_titles"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "posts", ["guid"], :name => "index_posts_on_guid"
|
add_index "posts", ["guid"], :name => "index_posts_on_guid"
|
||||||
|
|
@ -390,7 +384,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
||||||
t.integer "person_id", :null => false
|
t.integer "person_id", :null => false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "profiles", ["first_name", "last_name", "searchable"], :name => "index_profiles_on_first_name_and_last_name_and_searchable"
|
add_index "profiles", ["first_name", "last_name", "searchable"], :name => "index_profiles_on_first_name_and_last_name_and_searchable"
|
||||||
|
|
@ -405,7 +398,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
||||||
t.integer "aspect_id"
|
t.integer "aspect_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "requests", ["mongo_id"], :name => "index_requests_on_mongo_id"
|
add_index "requests", ["mongo_id"], :name => "index_requests_on_mongo_id"
|
||||||
|
|
@ -422,8 +414,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do
|
||||||
t.string "nickname"
|
t.string "nickname"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
|
||||||
t.string "user_mongo_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "services", ["mongo_id"], :name => "index_services_on_mongo_id"
|
add_index "services", ["mongo_id"], :name => "index_services_on_mongo_id"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue