업데이트

This commit is contained in:
익희 김 2025-01-18 00:42:49 +09:00
parent 85feb2e1e6
commit 011535a450
4 changed files with 27 additions and 35 deletions

22
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,22 @@
{
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#ff6433",
"activityBar.background": "#ff6433",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#00ff3d",
"activityBarBadge.foreground": "#15202b",
"commandCenter.border": "#e7e7e799",
"sash.hoverBorder": "#ff6433",
"statusBar.background": "#ff3d00",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#ff6433",
"statusBarItem.remoteBackground": "#ff3d00",
"statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#ff3d00",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#ff3d0099",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#ff3d00"
}

View File

@ -86,42 +86,10 @@ app.use('/v1', compaign);
app.use('/v1/chat', chatRoutes);
// io.on('connection', (socket) => {
// console.log(`클라이언트 연결됨: ${socket.id}`);
// // 클라이언트로부터 메시지 수신
// socket.on('message', async (data) => {
// console.log('받은 메시지:', data);
// // MongoDB에 메시지 저장
// const newMessage = new ChatMessage({
// username: data.username,
// message: data.message,
// });
// try {
// await newMessage.save();
// // 연결된 모든 클라이언트에게 메시지 브로드캐스트
// io.emit('message', newMessage);
// } catch (error) {
// console.error('메시지 저장 중 오류:', error);
// }
// });
// // 클라이언트 연결 종료 처리
// socket.on('disconnect', () => {
// console.log(`클라이언트 연결 해제: ${socket.id}`);
// });
// });
io.on('connection', (socket) => {
console.log(`클라이언트 연결됨: ${socket.id}`);
// 사용자 방 참여
socket.on('join', (email) => {
console.log(`${email} joined room: ${email}`);
socket.join(email); // 사용자를 이메일 기반으로 방에 참여시킴
socket.on('join', (room) => {
socket.join(room); // 사용자를 이메일 기반으로 방에 참여시킴
});
// 클라이언트로부터 메시지 수신
@ -132,6 +100,7 @@ io.on('connection', (socket) => {
// MongoDB에 메시지 저장
const newMessage = new ChatMessage({
username,
to:targetEmail,
message,
timestamp: new Date(),
});

View File

@ -2,6 +2,7 @@ const mongoose = require('mongoose');
const ChatMessageSchema = new mongoose.Schema({
username: { type: String, required: true },
to: { type: String, required: true },
message: { type: String, required: true },
timestamp: { type: Date, default: Date.now },
});

View File

@ -6,6 +6,7 @@ const router = express.Router();
router.get('/messages', async (req, res) => {
try {
const { email } = req.query;
if (!email) {
return res.status(400).json({ success: false, message: 'Email parameter is required.' });
@ -14,7 +15,6 @@ router.get('/messages', async (req, res) => {
// 이메일 배열로 필터링
const emailArray = email.split(',');
const messages = await ChatMessage.find({ username: { $in: emailArray } }).sort({ timestamp: 1 });
res.json(messages);
} catch (error) {
res.status(500).json({ success: false, message: error.message });