diff --git a/app/controllers/ajax/inbox_controller.rb b/app/controllers/ajax/inbox_controller.rb index 21ff83dc..52b4ca8a 100644 --- a/app/controllers/ajax/inbox_controller.rb +++ b/app/controllers/ajax/inbox_controller.rb @@ -46,14 +46,8 @@ class Ajax::InboxController < ApplicationController return end - # sharing - begin - share_to = JSON.parse params[:share] - current_user.services.each do |service| - service.post(answer) if share_to.include? service.provider - end - rescue - end + services = JSON.parse params[:share] + ShareWorker.perform_async(current_user.id, answer.id, services) @status = :okay @message = "Successfully answered question." diff --git a/app/workers/share_worker.rb b/app/workers/share_worker.rb index 079baaee..e607919b 100644 --- a/app/workers/share_worker.rb +++ b/app/workers/share_worker.rb @@ -3,7 +3,16 @@ class ShareWorker sidekiq_options queue: :share - def perform(answer_id) - # fuck this… for now + # @param user_id [Integer] the user id + # @param answer_id [Integer] the user id + # @param services [Array] array containing strings + def perform(user_id, answer_id, services) + User.find(user_id).services.each do |service| + begin + service.post(Answer.find(answer_id)) if services.include? service.provider + rescue => e + Rails.logger.error "failed to post answer #{answer_id} to #{service.provider} for user #{user_id}: #{e.message}" + end + end end end \ No newline at end of file