Open geekelo opened 1 month ago
Here's a detailed breakdown of your P2pTrades::ChatsController
within the Api::V1
namespace:
The P2pTrades::ChatsController
handles chat-related actions for a peer-to-peer (P2P) trade system. It provides functionality to manage chats associated with trades, including creating chats, uploading attachments, and updating message statuses.
index
:
@trade.chats.includes(:attachment_attachment)
to fetch chats with their attachments.P2pChatSerializer
.create
:
@trade.chats.new(chat_params)
.broadcast_message
to broadcast the new chat message via ActionCable.P2pApi::Chat::CreateJob
to process the chat asynchronously.400 Bad Request
with errors.upload_attachment
:
create
, but also handles file attachment:params[:file].present?
.P2pApi::Chat::UploadAttachmentJob
to process the attachment asynchronously.400 Bad Request
with errors if saving fails.update_read_messages
:
params[:chat_ids]
.is_read
to true
and sets read_at
to the current time.P2pApi::Chat::UpdateJob
to process the update asynchronously.200 OK
on success.broadcast_message
:
"p2p_chat_channel_#{@trade.id}"
.chat_params
:
:message
and :trade_id
, and merges profile_id
from the current user.find_trade
:
params[:trade_id]
.P2pTrade.find(params[:trade_id])
.This controller leverages both immediate and background processing to handle chat operations efficiently and ensures that updates are broadcasted in real-time.