code refactor

This commit is contained in:
slawk0
2024-12-13 19:54:19 +01:00
parent c5aac7ad2f
commit 76c49c3709
5 changed files with 32 additions and 44 deletions

View File

@@ -131,7 +131,7 @@ const MessageForm = ({ contact }: MessageFormProps) => {
const response = await uploadFiles(files.map((f) => f.file));
console.log(response);
attachmentUrls = response;
} catch (e) {
} catch {
console.error('Failed to upload attachments');
}
}

View File

@@ -80,8 +80,7 @@ function MessagesArea({
conversation_id: currentContact?.conversation_id,
},
(response: { status: string; message: string }) => {
if (response.status == 'ok') {
} else {
if (response.status !== 'ok') {
console.error('Failed to delete message: ', response.message);
}
},

View File

@@ -20,47 +20,10 @@ function initializeSocket(token: string): Socket | null {
return socket;
}
function sendMessage(message: string, recipient: string, tempId: string) {
if (!socket) {
console.error('Socket not initialized');
return;
}
socket.emit(
'chat message',
{
message: message,
recipient: recipient,
},
(response: { status: string; tempId: string }) => {
console.log(response.status, response.tempId);
},
);
console.log('sent message: ', {
message: message,
recipient: recipient,
});
}
function joinRoom(conversation_id: number) {
if (!socket) return;
socket.emit('join room', conversation_id);
console.log('sent on join room: ', conversation_id);
}
async function createRoom(
roomName: string,
): Promise<{ status: string } | undefined> {
return new Promise((resolve, reject) => {
if (!socket) {
reject('Socket not initialized');
return;
}
socket.emit('create room', roomName, (response: { status: string }) => {
resolve(response);
});
});
}
export { initializeSocket, sendMessage, createRoom, joinRoom, socket };
export { initializeSocket, joinRoom, socket };