Skip to content
Extraits de code Groupes Projets
Valider 5e58eba2 rédigé par maxwell's avatar maxwell
Parcourir les fichiers

new years resolution: commit more. make the websocket take user objects,...

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
parent 7ea6b4dd
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -11,8 +11,8 @@ class SocketsController < ApplicationController ...@@ -11,8 +11,8 @@ class SocketsController < ApplicationController
Rails.logger.info("Socket received connection to: #{msg}") Rails.logger.info("Socket received connection to: #{msg}")
end end
def outgoing(uid,object,opts={}) def outgoing(user, object, opts={})
@_request = ActionDispatch::Request.new({}) @_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
end end
...@@ -10,9 +10,9 @@ module SocketsHelper ...@@ -10,9 +10,9 @@ module SocketsHelper
object.respond_to?(:post_id) ? object.post_id : object.id object.respond_to?(:post_id) ? object.post_id : object.id
end end
def action_hash(uid, object, opts={}) def action_hash(user, object, opts={})
uid = user.id
begin begin
user = User.find_by_id uid
unless user.nil? unless user.nil?
old_locale = I18n.locale old_locale = I18n.locale
I18n.locale = user.language.to_s I18n.locale = user.language.to_s
......
...@@ -13,9 +13,14 @@ class Retraction ...@@ -13,9 +13,14 @@ class Retraction
attr_accessor :person, :object, :subscribers attr_accessor :person, :object, :subscribers
def subscribers(user) 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 end
def self.for(object) def self.for(object)
retraction = self.new retraction = self.new
if object.is_a? User if object.is_a? User
...@@ -30,7 +35,7 @@ class Retraction ...@@ -30,7 +35,7 @@ class Retraction
retraction retraction
end end
def perform receiving_user_id def perform(receiving_user)
Rails.logger.debug "Performing retraction for #{post_id}" Rails.logger.debug "Performing retraction for #{post_id}"
if self.type.constantize.find_by_id(post_id) if self.type.constantize.find_by_id(post_id)
unless Post.first(:diaspora_handle => person.diaspora_handle, :id => post_id) unless Post.first(:diaspora_handle => person.diaspora_handle, :id => post_id)
...@@ -41,7 +46,7 @@ class Retraction ...@@ -41,7 +46,7 @@ class Retraction
begin begin
Rails.logger.debug("Retracting #{self.type} id: #{self.post_id}") Rails.logger.debug("Retracting #{self.type} id: #{self.post_id}")
target = self.type.constantize.first(: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 target.delete
rescue NameError rescue NameError
Rails.logger.info("event=retraction status=abort reason='unknown type'") Rails.logger.info("event=retraction status=abort reason='unknown type'")
......
...@@ -62,7 +62,7 @@ class Postzord::Dispatch ...@@ -62,7 +62,7 @@ class Postzord::Dispatch
def socket_to_users(users) def socket_to_users(users)
if @object.respond_to?(:socket_to_uid) if @object.respond_to?(:socket_to_uid)
users.each do |user| users.each do |user|
@object.socket_to_uid(user.id) @object.socket_to_uid(user)
end end
end end
end end
......
...@@ -25,14 +25,14 @@ describe SocketsController do ...@@ -25,14 +25,14 @@ describe SocketsController do
end end
it 'actionhashes posts' do 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?(@message.message).should be_true
json.include?('status_message').should be_true json.include?('status_message').should be_true
end end
it 'actionhashes retractions' do it 'actionhashes retractions' do
retraction = Retraction.for @message 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?('retraction').should be_true
json.include?("html\":null").should be_true json.include?("html\":null").should be_true
end end
......
...@@ -33,6 +33,6 @@ describe Diaspora::Socketable do ...@@ -33,6 +33,6 @@ describe Diaspora::Socketable do
it 'sockets to a user' do it 'sockets to a user' do
Diaspora::WebSocket.should_receive(:queue_to_user) 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
end end
...@@ -22,7 +22,7 @@ describe Jobs::SocketWebfinger do ...@@ -22,7 +22,7 @@ describe Jobs::SocketWebfinger do
person = Factory.create(:person) person = Factory.create(:person)
finger.stub(:fetch).and_return(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) Jobs::SocketWebfinger.perform(@user.id, @account)
end end
it 'Passes opts through on success' do it 'Passes opts through on success' do
...@@ -32,7 +32,7 @@ describe Jobs::SocketWebfinger do ...@@ -32,7 +32,7 @@ describe Jobs::SocketWebfinger do
finger.stub(:fetch).and_return(person) finger.stub(:fetch).and_return(person)
opts = {:symbol => true} 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) Jobs::SocketWebfinger.perform(@user.id, @account, opts)
end end
it 'sockets failure message on failure' do it 'sockets failure message on failure' do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter