code refactor
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user