diff --git a/app/controllers/sockets_controller.rb b/app/controllers/sockets_controller.rb index 5411d1801a73e5e2ecf7c60992abfb31e487122d..aa87ec32041ab73cd656e2f243fab8da11803df5 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 2c7ccc48ab4cc0654d1cd69d7f4b4c275fcdefc5..f810538f01f824bea7aee5c0c26826db926a38cf 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 a9be633ab72f8de6708f0a8cd16838043e19d583..3b291200e170a71b7e48070f942bb64d4b44ed80 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 39c76fdc58dfe10373f327fd149ca8b4175664a3..6b927ac2246c4cb56934a88adf7197aa37de73c1 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 8f7cc337962bb29837fe7da17f851d0c70e759a3..de35584704e92f3e085c6d158c7c52e9e5f857e3 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 dd6022c331366993127bd52f09305df2ef6b7e32..465410f3ac7c5453115a9d57670368a726d37186 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 060744442fc0c20fbfd8ac2a4013ad7cf6a2d89a..9f052011aec8677eb1349cec685441f77364d7e6 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