diff --git a/client/src/components/chat/MessageForm.tsx b/client/src/components/chat/MessageForm.tsx index e0c7560..bab22ff 100644 --- a/client/src/components/chat/MessageForm.tsx +++ b/client/src/components/chat/MessageForm.tsx @@ -14,7 +14,6 @@ type Input = { type MessageFormProps = { contact: ContactsProps; - setMessages: React.Dispatch>; messages: ChatMessages[]; }; @@ -136,33 +135,35 @@ const MessageForm = ({ contact }: MessageFormProps) => { } } - // Emit message to server - socket.emit( - 'chat message', - { + for (let i = 0; i < 100; i++) { + // Emit message to server + socket.emit( + 'chat message', + { + message: data.message.trim(), + recipient: contact.conversation_id, + attachment_urls: attachmentUrls, + recipient_id: contact.user_id, + }, + (response: { status: string; message: string }) => { + if (response.status === 'ok') { + setIsSending(false); + reset({ message: '' }); + handleClearFiles(); + } else { + setIsSending(false); + setErrorMessage(response.message); + } + console.log('Response: ', response); + }, + ); + console.log('sent: ', { message: data.message.trim(), recipient: contact.conversation_id, attachment_urls: attachmentUrls, recipient_id: contact.user_id, - }, - (response: { status: string; message: string }) => { - if (response.status === 'ok') { - setIsSending(false); - reset({ message: '' }); - handleClearFiles(); - } else { - setIsSending(false); - setErrorMessage(response.message); - } - console.log('Response: ', response); - }, - ); - console.log('sent: ', { - message: data.message.trim(), - recipient: contact.conversation_id, - attachment_urls: attachmentUrls, - recipient_id: contact.user_id, - }); + }); + } }; const handleKeyPress: KeyboardEventHandler = (e) => { diff --git a/client/src/pages/Chat.tsx b/client/src/pages/Chat.tsx index 8c35d3f..e0c5846 100644 --- a/client/src/pages/Chat.tsx +++ b/client/src/pages/Chat.tsx @@ -138,7 +138,12 @@ function Chat() { messages.messages.forEach((msg) => { setMessages((prevMessages) => { if (!prevMessages.some((m) => m.message_id === msg.message_id)) { - return [msg, ...prevMessages]; + const messageWithDate = { + ...msg, + sent_at: new Date(msg.sent_at), + }; + + return [messageWithDate, ...prevMessages]; } return prevMessages; }); @@ -247,11 +252,7 @@ function Chat() {
{currentContact && currentContact.username?.length >= 4 ? ( - + ) : null}