Merge pull request #293 from warpc/265-new_design_for_activity_feed
[Refs #265] Fix subscribe dublicates
This commit is contained in:
commit
9f9eb23e43
|
@ -33,7 +33,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
||||||
|
|
||||||
when 'Comment'
|
when 'Comment'
|
||||||
if record.commentable.class == Issue
|
if record.commentable.class == Issue
|
||||||
subscribes = record.commentable.subscribes.finder_hack
|
subscribes = record.commentable.subscribes
|
||||||
subscribes.each do |subscribe|
|
subscribes.each do |subscribe|
|
||||||
if record.user_id != subscribe.user_id
|
if record.user_id != subscribe.user_id
|
||||||
UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe)
|
UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe)
|
||||||
|
|
|
@ -73,8 +73,9 @@ class Issue < ActiveRecord::Base
|
||||||
def subscribe_users
|
def subscribe_users
|
||||||
recipients = collect_recipient_ids
|
recipients = collect_recipient_ids
|
||||||
recipients.each do |recipient_id|
|
recipients.each do |recipient_id|
|
||||||
ss = self.subscribes.build(:user_id => recipient_id)
|
if User.find(recipient_id).notifier.new_comment && !self.subscribes.exists?(:user_id => recipient_id)
|
||||||
ss.save!
|
ss = self.subscribes.create(:user_id => recipient_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ class Subscribe < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
scope :finder_hack, order('') # FIXME .subscribes - error; .subscribes.finder_hack - success Oo
|
|
||||||
|
|
||||||
def commit_subscribe?
|
def commit_subscribe?
|
||||||
subscribeable_type == 'Grit::Commit'
|
subscribeable_type == 'Grit::Commit'
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
class DeleteDublicateSubscribes < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
execute <<-SQL
|
||||||
|
DELETE FROM subscribes s
|
||||||
|
WHERE s.id NOT IN (SELECT MIN(s1.id) FROM SUBSCRIBES s1
|
||||||
|
GROUP BY s1.subscribeable_type, s1.user_id, s1.status, s1.subscribeable_id)
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue