From f221b47faf9ca8a9c33fd8468e63e273389d6dc5 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 21 Sep 2024 10:02:26 +0300 Subject: [PATCH] Change the broadcast jobs params --- app/controllers/api/v1/messages_controller.rb | 4 ++-- app/jobs/message_broadcast_job.rb | 9 +++------ app/jobs/messages_notifications_broadcast_job.rb | 2 +- app/jobs/online_status_broadcast_job.rb | 8 ++------ 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/v1/messages_controller.rb b/app/controllers/api/v1/messages_controller.rb index 91ab7c2c..f4abd945 100644 --- a/app/controllers/api/v1/messages_controller.rb +++ b/app/controllers/api/v1/messages_controller.rb @@ -17,7 +17,7 @@ def create add_notifications render json: { data: 'μήνυμα εστάλει' }, status: :ok - rescue StandardError => e + rescue StandardError render json: { error: 'Κάτι πήγε στραβά, δοκιμάστε αργότερα'}, status: :unprocessable_entity end @@ -28,7 +28,7 @@ def reply add_notifications render json: { data: 'μήνυμα εστάλει' }, status: :ok - rescue StandardError => e + rescue StandardError render json: { error: 'Κάτι πήγε στραβά, δοκιμάστε αργότερα'}, status: :unprocessable_entity end diff --git a/app/jobs/message_broadcast_job.rb b/app/jobs/message_broadcast_job.rb index 641a932f..87f1b029 100644 --- a/app/jobs/message_broadcast_job.rb +++ b/app/jobs/message_broadcast_job.rb @@ -6,16 +6,13 @@ def perform(conversation, current_user) end def broadcast(conversation, current_user) - sender = - Api::V1::UserSerializer.new(current_user, scope: current_user).as_json - serialized_message = - Api::V1::MessageSerializer.new(conversation.messages.last).as_json - + sender = Api::V1::UserSerializer.new(current_user, scope: current_user).as_json + serialized_message = Api::V1::MessageSerializer.new(conversation.messages.last).as_json serialized_message[:sender] = sender ActionCable.server.broadcast( "conversation_#{conversation.id}", - message: serialized_message + { message: serialized_message } ) end diff --git a/app/jobs/messages_notifications_broadcast_job.rb b/app/jobs/messages_notifications_broadcast_job.rb index 005abc63..16fd5507 100644 --- a/app/jobs/messages_notifications_broadcast_job.rb +++ b/app/jobs/messages_notifications_broadcast_job.rb @@ -12,7 +12,7 @@ def perform(conversation, current_user) def add_conversation_notification(conversation, recipient) ::ActionCable.server.broadcast( "messages_notifications_#{recipient.username}", - conversation_id: conversation.id + { conversation_id: conversation.id } ) end diff --git a/app/jobs/online_status_broadcast_job.rb b/app/jobs/online_status_broadcast_job.rb index d5ff13d0..2519d0fc 100644 --- a/app/jobs/online_status_broadcast_job.rb +++ b/app/jobs/online_status_broadcast_job.rb @@ -2,15 +2,11 @@ class OnlineStatusBroadcastJob < ApplicationJob queue_as :default def perform(current_user, status) - serialised_user = - Api::V1::UserSerializer.new(current_user, scope: current_user).as_json + serialised_user = Api::V1::UserSerializer.new(current_user, scope: current_user).as_json ::ActionCable.server.broadcast( "online_status_channel", - { - user: serialised_user, - online: status - } + { user: serialised_user, online: status } ) current_user.update!(is_signed_in: status) end