new years resolution: commit more. make the websocket take user objects, rather then just ids, since postman now gets all of them at once, rather than querying them n times
This commit is contained in:
parent
7ea6b4dd8d
commit
5e58eba240
7 changed files with 19 additions and 14 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue