Skip to content

Commit

Permalink
Change the broadcast jobs params
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAvlonitis committed Sep 21, 2024
1 parent 3113b24 commit f221b47
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
9 changes: 3 additions & 6 deletions app/jobs/message_broadcast_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/messages_notifications_broadcast_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 2 additions & 6 deletions app/jobs/online_status_broadcast_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f221b47

Please sign in to comment.