diff --git a/app/models/comment.rb b/app/models/comment.rb index c9e8f6c2c..16edcf412 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -59,7 +59,7 @@ class Comment < ActiveRecord::Base end def notification_type(user, person) - if (self.post.author == user.person) && (self.author != user.person) + if self.post.author == user.person return Notifications::CommentOnPost elsif self.post.comments.where(:author_id => user.person.id) != [] && self.author_id != user.person.id return Notifications::AlsoCommented diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 9ba615511..437750310 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -36,19 +36,11 @@ class Conversation < ActiveRecord::Base def participant_handles self.participants.map{|p| p.diaspora_handle}.join(";") end - def participant_handles= handles handles.split(';').each do |handle| self.participants << Webfinger.new(handle).fetch end end - - def participant_users - @participant_users ||= lambda do - user_ids = self.participants.map {|p| p.owner_id}.compact - User.where(:id => user_ids) - end.call - end def last_author self.messages.last.author if self.messages.size > 0 diff --git a/app/models/jobs/http_multi.rb b/app/models/jobs/http_multi.rb index de333e74d..044deb470 100644 --- a/app/models/jobs/http_multi.rb +++ b/app/models/jobs/http_multi.rb @@ -22,8 +22,6 @@ module Jobs def self.perform(user_id, encoded_object_xml, person_ids, dispatcher_class_as_string) user = User.find(user_id) - - #could be bad here people = Person.where(:id => person_ids) dispatcher = dispatcher_class_as_string.constantize diff --git a/app/models/jobs/notify_local_users.rb b/app/models/jobs/notify_local_users.rb index 17f8c6409..f75d5418e 100644 --- a/app/models/jobs/notify_local_users.rb +++ b/app/models/jobs/notify_local_users.rb @@ -9,12 +9,17 @@ module Jobs require File.join(Rails.root, 'app/models/notification') def self.perform(user_ids, object_klass, object_id, person_id) + object = object_klass.constantize.find_by_id(object_id) - users = object.participant_users + + #hax + return if (object.author.diaspora_handle == 'diasporahq@joindiaspora.com' || (object.respond_to?(:relayable?) && object.parent.author.diaspora_handle == 'diasporahq@joindiaspora.com')) + #end hax + + users = User.where(:id => user_ids) person = Person.find_by_id(person_id) - users.each do |user| - Notification.notify(user, object, person) - end + + users.each{|user| Notification.notify(user, object, person) } end end end diff --git a/app/models/jobs/receive_local_batch.rb b/app/models/jobs/receive_local_batch.rb index 8d408c2ef..ec8b781a6 100644 --- a/app/models/jobs/receive_local_batch.rb +++ b/app/models/jobs/receive_local_batch.rb @@ -11,11 +11,7 @@ module Jobs @queue = :receive def self.perform(object_class_string, object_id, recipient_user_ids) - - object = object_class_string.constantize.find(object_id) - - #recipient user ids could be really bad receiver = Postzord::Receiver::LocalBatch.new(object, recipient_user_ids) receiver.perform! end diff --git a/app/models/notification.rb b/app/models/notification.rb index 23b0223be..40711786a 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,7 +1,7 @@ # Copyright (c) 2010-2011, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. - +# class Notification < ActiveRecord::Base require File.join(Rails.root, 'lib/diaspora/web_socket') include Diaspora::Socketable @@ -16,8 +16,6 @@ class Notification < ActiveRecord::Base end def self.notify(recipient, target, actor) - return false if recipient.person == actor #never notify someone if they are the actor, derp - if target.respond_to? :notification_type if note_type = target.notification_type(recipient, actor) if(target.is_a? Comment) || (target.is_a? Like) diff --git a/app/models/person.rb b/app/models/person.rb index 4928fbb77..0d6d40829 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -30,7 +30,6 @@ class Person < ActiveRecord::Base has_many :posts, :foreign_key => :author_id, :dependent => :destroy # This person's own posts has_many :photos, :foreign_key => :author_id, :dependent => :destroy # This person's own photos has_many :comments, :foreign_key => :author_id, :dependent => :destroy # This person's own comments - has_many :likes, :foreign_key => :author_id, :dependent => :destroy # This person's own likes belongs_to :owner, :class_name => 'User' diff --git a/app/views/shared/_publisher.mobile.haml b/app/views/shared/_publisher.mobile.haml index a8182da8c..c3e913380 100644 --- a/app/views/shared/_publisher.mobile.haml +++ b/app/views/shared/_publisher.mobile.haml @@ -20,7 +20,7 @@ %span#publisher_service_icons - if current_user.services - for service in current_user.services - = image_tag "social_media_logos/#{service.provider}-16x16.png", :title => service.provider.titleize, :class => "service_icon dim", :id =>"#{service.provider}", :maxchar => "#{service.class::MAX_CHARACTERS}" + = image_tag "social_media_logos/#{service.provider}-32x32.png", :title => service.provider.titleize, :class => "service_icon dim", :id =>"#{service.provider}", :maxchar => "#{service.class::MAX_CHARACTERS}" %select{:id => "aspect_ids_", :name => "aspect_ids[]", :style => "float:right;"} %option{:value => 'public'} diff --git a/config/application.yml.example b/config/application.yml.example index 218e58b89..99fda42f9 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -18,11 +18,10 @@ defaults: &defaults # Websocket port - should normally be 8080 or 8081. socket_port: 8080 - # Setting the root certificate bundle (this is operating system specific). Defaults: - # CentOS: '/etc/pki/tls/certs/ca-bundle.crt' - # Debian: '/etc/ssl/certs/ca-certificates.crt' - # Gentoo: '/etc/ssl/certs/ca-certificates.crt' - ca_file: '/etc/pki/tls/certs/ca-bundle.crt' + # Setting the root certificate bundle (this is operating system specific). Examples, uncomment one: + ca_file: '/etc/pki/tls/certs/ca-bundle.crt' # CentOS + #ca_file: '/etc/ssl/certs/ca-certificates.crt' # Debian + #ca_file: '/etc/ssl/certs/ca-certificates.crt' # Gentoo # Secure websocket confguration (wss://). # Requires SSL cert and key diff --git a/lib/diaspora/relayable.rb b/lib/diaspora/relayable.rb index c58d0affa..18f62bff4 100644 --- a/lib/diaspora/relayable.rb +++ b/lib/diaspora/relayable.rb @@ -46,14 +46,6 @@ module Diaspora end end - def particpants - self.parent.participants - end - - def participant_users - self.parent.participant_users - end - def receive(user, person=nil) comment_or_like = self.class.where(:guid => self.guid).first || self diff --git a/lib/diaspora/shareable.rb b/lib/diaspora/shareable.rb index 85cea06f2..1ba5746ef 100644 --- a/lib/diaspora/shareable.rb +++ b/lib/diaspora/shareable.rb @@ -107,28 +107,6 @@ module Diaspora end end - # @return [Array] The list of participants to this shareable - def participants - @participants ||= lambda do - share_type = self.class.base_class.to_s - people = [] - if self.respond_to? :comments - people += Person.joins(:comments).where(:comments => {:commentable_id => self.id, :commentable_type => share_type}).all - end - - if self.respond_to? :likes - people += Person.joins(:likes).where(:likes => {:target_id => self.id, :target_type => share_type}).all - end - people - end.call - end - - def participant_users - @participant_users ||= lambda do - user_ids = participants.map{|x| x.owner_id}.compact - User.where(:id => user_ids) - end.call - end protected diff --git a/lib/postzord/dispatcher.rb b/lib/postzord/dispatcher.rb index edf6b16e9..8b01847fe 100644 --- a/lib/postzord/dispatcher.rb +++ b/lib/postzord/dispatcher.rb @@ -139,7 +139,15 @@ class Postzord::Dispatcher # @param services [Array] def notify_users(users) return unless users.present? && @object.respond_to?(:persisted?) - Resque.enqueue(Jobs::NotifyLocalUsers, users.map{|u| u.id}, @object.class.to_s, @object.id, @object.author.id) + + #temp hax + unless object_is_related_to_diaspora_hq? + Resque.enqueue(Jobs::NotifyLocalUsers, users.map{|u| u.id}, @object.class.to_s, @object.id, @object.author.id) + end + end + + def object_is_related_to_diaspora_hq? + (@object.author.diaspora_handle == 'diasporahq@joindiaspora.com' || (@object.respond_to?(:relayable?) && @object.parent.author.diaspora_handle == 'diasporahq@joindiaspora.com')) end # @param services [Array] diff --git a/lib/postzord/receiver/local_batch.rb b/lib/postzord/receiver/local_batch.rb index 24b607968..be91e2c93 100644 --- a/lib/postzord/receiver/local_batch.rb +++ b/lib/postzord/receiver/local_batch.rb @@ -9,7 +9,6 @@ class Postzord::Receiver::LocalBatch < Postzord::Receiver def initialize(object, recipient_user_ids) @object = object @recipient_user_ids = recipient_user_ids - #this is a nightmare @users = User.where(:id => @recipient_user_ids) end diff --git a/lib/stream/multi.rb b/lib/stream/multi.rb index 934d6bbf5..e6e5403d7 100644 --- a/lib/stream/multi.rb +++ b/lib/stream/multi.rb @@ -117,4 +117,5 @@ class Stream::Multi < Stream::Base def ids(query) Post.connection.select_values(query.for_a_stream(max_time, order).select('posts.id').to_sql) end + end diff --git a/script/websocket_server.rb b/script/websocket_server.rb index f38a8c24a..e0adf36cf 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -45,6 +45,7 @@ $cookie_parser = Rack::Builder.new do use ActionDispatch::Session::CookieStore, :key => "_diaspora_session" use Warden::Manager do |warden| warden.default_scope = :user + warden.failure_app = Proc.new {|env| [0, {}, nil]} end run Proc.new {|env| [0, {}, env['warden'].user]} diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 3aa492737..be158ca61 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -36,12 +36,6 @@ describe Comment do @comment.notification_type(alice, alice.person).should == Notifications::AlsoCommented end end - - it 'should not return if you are author of the object being commented on' do - p = Factory(:status_message, :author => bob.person) - c = bob.comment("dfs", :post => p) - c.notification_type(bob, bob.person).should be_false - end end describe 'User#comment' do diff --git a/spec/models/jobs/notify_local_users_spec.rb b/spec/models/jobs/notify_local_users_spec.rb index 6c1271561..30cec5047 100644 --- a/spec/models/jobs/notify_local_users_spec.rb +++ b/spec/models/jobs/notify_local_users_spec.rb @@ -11,7 +11,7 @@ describe Jobs::NotifyLocalUsers do post = Factory :status_message StatusMessage.should_receive(:find_by_id).with(post.id).and_return(post) - post.should_receive(:participant_users).and_return([alice, eve]) + #User.should_receive(:where).and_return([alice, eve]) Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person)).twice Jobs::NotifyLocalUsers.perform([alice.id, eve.id], post.class.to_s, post.id, person.id) diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 87106d706..55f9b3430 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -195,17 +195,6 @@ describe Post do end end - describe '#participants' do - it 'only returns the people that commented and liked the post' do - status = Factory(:status_message, :author => bob.person, :public => true) - alice.comment('too', :post => status) - eve.like(true, :target => status) - - status.participants.map(&:id).should =~ [alice, eve].map{|x| x.person.id} - end - - end - describe '#comments' do it 'returns the comments of a post in created_at order' do post = bob.post :status_message, :text => "hello", :to => 'all'