Skip to content

Commit

Permalink
fix #586 error
Browse files Browse the repository at this point in the history
  • Loading branch information
JinHyukM3 committed Jan 12, 2024
1 parent 2868583 commit dfe558c
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/chatSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function useChatUtils(socket: Socket | undefined) {
return;
}

resolve(sentMessage);
resolve(message);
}
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/decryptMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CryptoJS from 'crypto-js';

const secretKey = process.env.SECRET_KEY;
const secretKey = process.env.NEXT_PUBLIC_SECRET_KEY;

export default (message: string) => {
if (!secretKey) {
Expand Down
1 change: 0 additions & 1 deletion src/pages/anonymous.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ const Anonymous = () => {
socket?.io.off('reconnect_attempt', onReconnectAttempt);
socket?.io.off('reconnect_error', onReconnectError);

socket?.disconnect();

newMessageEvents.forEach(event => {
socket?.off(event, onNewMessage);
Expand Down
10 changes: 5 additions & 5 deletions src/server/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ const messageCounts: {
[id: string]: number;
} = {};

export const SendMessageHandler = (socket: Socket) => {
export const SendMessageHandler = (io: Server, socket: Socket) => {
socket.on(
constants.NEW_EVENT_SEND_MESSAGE,
async (
{ senderId, message, time, chatId, containsBadword, replyTo },
{ senderId, message, time, room, containsBadword, replyTo },
returnMessageToSender
) => {
// Below line is just a failed message simulator for testing purposes.
Expand Down Expand Up @@ -271,7 +271,7 @@ export const SendMessageHandler = (socket: Socket) => {
/**
* Cache the sent message in memory a nd persist to db
*/
const sentMessage = await addMessage(chatId, {
const sentMessage = await addMessage(room, {
message,
time,
senderId,
Expand All @@ -282,14 +282,14 @@ export const SendMessageHandler = (socket: Socket) => {

const messageDetails = {
...sentMessage,
room: chatId,
room,
status: 'sent',
};

returnMessageToSender(messageDetails);

socket.broadcast
.to(chatId)
.to(room)
.emit(constants.NEW_EVENT_RECEIVE_MESSAGE, messageDetails);

// Update the message count for the user
Expand Down
2 changes: 1 addition & 1 deletion src/server/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
MessageType,
} from '@/types/types';

const secretKey = process.env.SECRET_KEY;
const secretKey = process.env.NEXT_PUBLIC_SECRET_KEY;

const waitingUsers: activeUserIdType = {};

Expand Down
2 changes: 1 addition & 1 deletion src/server/models/MessageModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const messageSchema = new Schema<MessageSchemaDocument>(
default: false,
},
replyTo: {
type: Schema.Types.ObjectId,
type: String,
ref: 'Message',
},
},
Expand Down

0 comments on commit dfe558c

Please sign in to comment.