diff --git a/app/controllers/sockets_controller.rb b/app/controllers/sockets_controller.rb index 5411d1801..aa87ec320 100644 --- a/app/controllers/sockets_controller.rb +++ b/app/controllers/sockets_controller.rb @@ -11,8 +11,8 @@ class SocketsController < ApplicationController Rails.logger.info("Socket received connection to: #{msg}") end - def outgoing(uid,object,opts={}) + def outgoing(user, object, opts={}) @_request = ActionDispatch::Request.new({}) - Diaspora::WebSocket.queue_to_user(uid, action_hash(uid, object, opts)) + Diaspora::WebSocket.queue_to_user(user.id, action_hash(user, object, opts)) end end diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 2c7ccc48a..f810538f0 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -10,9 +10,9 @@ module SocketsHelper object.respond_to?(:post_id) ? object.post_id : object.id end - def action_hash(uid, object, opts={}) + def action_hash(user, object, opts={}) + uid = user.id begin - user = User.find_by_id uid unless user.nil? old_locale = I18n.locale I18n.locale = user.language.to_s diff --git a/app/models/retraction.rb b/app/models/retraction.rb index a9be633ab..3b291200e 100644 --- a/app/models/retraction.rb +++ b/app/models/retraction.rb @@ -13,9 +13,14 @@ class Retraction attr_accessor :person, :object, :subscribers def subscribers(user) - @subscribers ||= self.object.subscribers(user) + unless self.type == 'Person' + @subscribers ||= self.object.subscribers(user) + else + raise 'HAX: you must set the subscribers manaully before unfriending' if @subscribers.nil? + @subscribers + end end - + def self.for(object) retraction = self.new if object.is_a? User @@ -30,7 +35,7 @@ class Retraction retraction end - def perform receiving_user_id + def perform(receiving_user) Rails.logger.debug "Performing retraction for #{post_id}" if self.type.constantize.find_by_id(post_id) unless Post.first(:diaspora_handle => person.diaspora_handle, :id => post_id) @@ -41,7 +46,7 @@ class Retraction begin Rails.logger.debug("Retracting #{self.type} id: #{self.post_id}") target = self.type.constantize.first(:id => self.post_id) - target.unsocket_from_uid receiving_user_id if target.respond_to? :unsocket_from_uid + target.unsocket_from_uid(receiving_user, self) if target.respond_to? :unsocket_from_uid target.delete rescue NameError Rails.logger.info("event=retraction status=abort reason='unknown type'") diff --git a/lib/postzord/dispatch.rb b/lib/postzord/dispatch.rb index 39c76fdc5..6b927ac22 100644 --- a/lib/postzord/dispatch.rb +++ b/lib/postzord/dispatch.rb @@ -62,7 +62,7 @@ class Postzord::Dispatch def socket_to_users(users) if @object.respond_to?(:socket_to_uid) users.each do |user| - @object.socket_to_uid(user.id) + @object.socket_to_uid(user) end end end diff --git a/spec/controllers/sockets_controller_spec.rb b/spec/controllers/sockets_controller_spec.rb index 8f7cc3379..de3558470 100644 --- a/spec/controllers/sockets_controller_spec.rb +++ b/spec/controllers/sockets_controller_spec.rb @@ -25,14 +25,14 @@ describe SocketsController do end it 'actionhashes posts' do - json = @controller.action_hash(@user.id, @message) + json = @controller.action_hash(@user, @message) json.include?(@message.message).should be_true json.include?('status_message').should be_true end it 'actionhashes retractions' do retraction = Retraction.for @message - json = @controller.action_hash(@user.id, retraction) + json = @controller.action_hash(@user, retraction) json.include?('retraction').should be_true json.include?("html\":null").should be_true end diff --git a/spec/lib/diaspora/web_socket_spec.rb b/spec/lib/diaspora/web_socket_spec.rb index dd6022c33..465410f3a 100644 --- a/spec/lib/diaspora/web_socket_spec.rb +++ b/spec/lib/diaspora/web_socket_spec.rb @@ -33,6 +33,6 @@ describe Diaspora::Socketable do it 'sockets to a user' do Diaspora::WebSocket.should_receive(:queue_to_user) - @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) + @post.socket_to_uid(@user, :aspect_ids => @aspect.id) end end diff --git a/spec/models/jobs/socket_webfinger_spec.rb b/spec/models/jobs/socket_webfinger_spec.rb index 060744442..9f052011a 100644 --- a/spec/models/jobs/socket_webfinger_spec.rb +++ b/spec/models/jobs/socket_webfinger_spec.rb @@ -22,7 +22,7 @@ describe Jobs::SocketWebfinger do person = Factory.create(:person) finger.stub(:fetch).and_return(person) - person.should_receive(:socket_to_uid).with(@user.id, {}) + person.should_receive(:socket_to_uid).with(@user, {}) Jobs::SocketWebfinger.perform(@user.id, @account) end it 'Passes opts through on success' do @@ -32,7 +32,7 @@ describe Jobs::SocketWebfinger do finger.stub(:fetch).and_return(person) opts = {:symbol => true} - person.should_receive(:socket_to_uid).with(@user.id, opts) + person.should_receive(:socket_to_uid).with(@user, opts) Jobs::SocketWebfinger.perform(@user.id, @account, opts) end it 'sockets failure message on failure' do