Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
messenger
Commits
15336d57
Commit
15336d57
authored
Jan 25, 2021
by
Choi Ga Young
Browse files
Merge remote-tracking branch 'origin/yeonwoo' into young
parents
ae4c0309
34d0df05
Changes
9
Hide whitespace changes
Inline
Side-by-side
client/src/Components/Chat.js
View file @
15336d57
...
@@ -14,11 +14,10 @@ const INIT_CHAT = {
...
@@ -14,11 +14,10 @@ const INIT_CHAT = {
function
Chat
(
props
)
{
function
Chat
(
props
)
{
const
[
sender
,
setSender
]
=
useState
([])
const
[
sender
,
setSender
]
=
useState
([])
const
[
roomName
,
setRoomName
]
=
useState
(
''
)
const
[
inner
,
setInner
]
=
useState
([
''
])
const
[
inner
,
setInner
]
=
useState
([
''
])
const
[
chat
,
setChat
]
=
useState
([
INIT_CHAT
])
//object로 key는 보낸사람 value는 메세지
const
[
chat
,
setChat
]
=
useState
([
INIT_CHAT
])
//object로 key는 보낸사람 value는 메세지
const
[
img
,
setImg
]
=
useState
([])
const
[
time
,
setTime
]
=
useState
([
''
])
const
simpleTime
=
new
Date
().
toLocaleTimeString
()
const
simpleTime
=
new
Date
().
toLocaleTimeString
()
const
usualTime
=
simpleTime
.
substring
(
0
,
simpleTime
.
length
-
3
)
const
usualTime
=
simpleTime
.
substring
(
0
,
simpleTime
.
length
-
3
)
const
realTime
=
new
Date
().
toISOString
()
const
realTime
=
new
Date
().
toISOString
()
...
@@ -66,29 +65,9 @@ function Chat(props) {
...
@@ -66,29 +65,9 @@ function Chat(props) {
props
.
setLeaveInfo
([...
props
.
leaveInfo
,
{
roomName
:
props
.
roomCode
,
leaveTime
:
realTime
}])
props
.
setLeaveInfo
([...
props
.
leaveInfo
,
{
roomName
:
props
.
roomCode
,
leaveTime
:
realTime
}])
console
.
log
(
'
나간시간
'
,
realTime
,
usualTime
)
console
.
log
(
'
나간시간
'
,
realTime
,
usualTime
)
setChat
([
''
])
setChat
([
''
])
props
.
handleChatc
()
props
.
handleChatc
()
// console.log("22222222222222222", props.leaveInfo)
props
.
setLeaveInfo
([...
props
.
leaveInfo
,
{
roomName
:
props
.
roomCode
,
leaveTime
:
realTime
}])
// let find1 = props.leaveInfo.findIndex((ele) => ele.roomName === props.roomCode)
// console.log("33333333333333333", find1)
// let find=0
// for(let i=0;i<=props.leaveInfo.length-1;i++){
// if(props.leaveInfo[i].roomName===props.roomCode){
// find = i
// break;
// }
// console.log('찾자',find)
// }
// if (props.leaveInfo[find1]) {
// props.setLeaveInfo(props.leaveInfo[find1] = { roomName: props.roomCode, leaveTime: realTime })
// console.log('트루')
// } else {
// props.setLeaveInfo([...props.leaveInfo, { roomName: props.roomCode, leaveTime: realTime }])
// console.log('폴스')
// }
// console.log('나간다', props.leaveInfo)
}
}
function
settingtime
(
hour
)
{
function
settingtime
(
hour
)
{
...
@@ -108,28 +87,15 @@ function Chat(props) {
...
@@ -108,28 +87,15 @@ function Chat(props) {
//이전 채팅 내용에 대한 것 불러오기
//이전 채팅 내용에 대한 것 불러오기
//프사 닉네임 메세지가 각각의 배열로 들어가서 띄워지는 방식
//프사 닉네임 메세지가 각각의 배열로 들어가서 띄워지는 방식
async
function
getPreviousChat
()
{
async
function
getPreviousChat
()
{
//메세지, 닉네임, 시간 불러오기
const
respond
=
await
axios
.
get
(
'
/room/getChatInfo
'
,
{
params
:
{
'
roomCode
'
:
props
.
roomCode
}
})
const
respond
=
await
axios
.
get
(
'
/room/getChatInfo
'
,
{
params
:
{
'
roomCode
'
:
props
.
roomCode
}
})
console
.
log
(
respond
)
console
.
log
(
respond
)
const
info
=
respond
.
data
const
info
=
respond
.
data
let
intochat
=
[]
let
intochat
=
[]
let
msglist
=
[]
let
userlist
=
[]
let
hourlist
=
[]
let
imglist
=
[]
for
(
let
prop
in
info
)
{
for
(
let
prop
in
info
)
{
let
hour
=
info
[
prop
].
createdAt
.
split
(
'
T
'
)[
1
].
split
(
'
:
'
)
let
hour
=
info
[
prop
].
createdAt
.
split
(
'
T
'
)[
1
].
split
(
'
:
'
)
hour
=
settingtime
(
hour
[
0
])
+
'
:
'
+
hour
[
1
]
hour
=
settingtime
(
hour
[
0
])
+
'
:
'
+
hour
[
1
]
msglist
.
push
(
info
[
prop
].
message
)
intochat
.
push
({
msg
:
info
[
prop
].
message
,
sender
:
info
[
prop
].
username
,
img
:
info
[
prop
].
profileimg
,
time
:
hour
})
userlist
.
push
(
info
[
prop
].
username
)
hourlist
.
push
(
hour
)
}
const
respond2
=
await
axios
.
get
(
'
/room/getProfileImage
'
,
{
params
:
{
'
userlist
'
:
userlist
}
})
imglist
=
respond2
.
data
console
.
log
(
'
확인해보자
'
,
imglist
)
for
(
let
i
=
0
;
i
<
msglist
.
length
;
i
++
)
{
intochat
.
push
({
msg
:
msglist
[
i
],
sender
:
userlist
[
i
],
img
:
imglist
[
i
].
profileimg
,
time
:
hourlist
[
i
]
})
}
}
setChat
(
intochat
)
setChat
(
intochat
)
}
}
...
...
client/src/Components/ClosedList.js
View file @
15336d57
...
@@ -11,21 +11,6 @@ const INIT_LIST = [{
...
@@ -11,21 +11,6 @@ const INIT_LIST = [{
}]
}]
function
ClosedList
(
props
)
{
function
ClosedList
(
props
)
{
const
[
list
,
setList
]
=
useState
(
INIT_LIST
);
useEffect
(()
=>
{
getClosedList
();
},
[
props
.
roomCode
]);
async
function
getClosedList
()
{
const
userid
=
sessionStorage
.
getItem
(
'
userId
'
)
let
res
=
await
axios
.
get
(
'
/room/closedlist
'
,
{
params
:
{
'
_id
'
:
userid
}
})
setList
(
res
.
data
)
}
const
realTime
=
new
Date
().
toISOString
()
function
enterChatRoomCH
(
e
)
{
function
enterChatRoomCH
(
e
)
{
if
(
props
.
roomCode
)
{
if
(
props
.
roomCode
)
{
props
.
closeChatRoom
(
props
.
roomCode
)
props
.
closeChatRoom
(
props
.
roomCode
)
...
@@ -36,14 +21,15 @@ function ClosedList(props) {
...
@@ -36,14 +21,15 @@ function ClosedList(props) {
props
.
setRoomCode
(
roomCode
)
props
.
setRoomCode
(
roomCode
)
props
.
setRoomName
(
roomName
)
props
.
setRoomName
(
roomName
)
console
.
log
(
'
rrrrrrrrrrrrrrr
'
,
props
.
closedlist
)
console
.
log
(
'
1111111111111111111
'
,
props
.
leaveInfo
,
typeof
(
props
.
leaveInfo
))
console
.
log
(
'
1111111111111111111
'
,
props
.
leaveInfo
,
typeof
(
props
.
leaveInfo
))
}
}
const
[
checknew
,
setChecknew
]
=
useState
([])
const
[
checknew
,
setChecknew
]
=
useState
([])
const
[
unreadnumber
,
setUnreadnumber
]
=
useState
([
''
])
const
[
unreadnumber
,
setUnreadnumber
]
=
useState
([
''
])
async
function
dbChat
()
{
async
function
dbChat
()
{
for
(
let
i
=
0
;
i
<=
list
.
length
-
1
;
i
++
)
{
for
(
let
i
=
0
;
i
<=
props
.
closed
list
.
length
-
1
;
i
++
)
{
const
respond
=
await
axios
.
get
(
'
/room/dbChat
'
,
{
params
:
{
'
roomId
'
:
list
[
i
].
roomId
}
})
const
respond
=
await
axios
.
get
(
'
/room/dbChat
'
,
{
params
:
{
'
roomId
'
:
props
.
closed
list
[
i
].
roomId
}
})
setChecknew
(
respond
.
data
)
setChecknew
(
respond
.
data
)
}
}
}
}
...
@@ -63,8 +49,8 @@ function ClosedList(props) {
...
@@ -63,8 +49,8 @@ function ClosedList(props) {
setUnreadnumber
([
''
])
setUnreadnumber
([
''
])
let
arr
=
[]
let
arr
=
[]
for
(
let
i
=
0
;
i
<=
list
.
length
-
1
;
i
++
)
{
for
(
let
i
=
0
;
i
<=
props
.
closed
list
.
length
-
1
;
i
++
)
{
const
respond
=
await
axios
.
get
(
'
/room/unreadMessage
'
,
{
params
:
{
'
leaveInfo
'
:
props
.
leaveInfo
,
'
roomId
'
:
list
[
i
].
roomId
}
})
const
respond
=
await
axios
.
get
(
'
/room/unreadMessage
'
,
{
params
:
{
'
leaveInfo
'
:
props
.
leaveInfo
,
'
roomId
'
:
props
.
closed
list
[
i
].
roomId
}
})
// setUnreadnumber([...unreadnumber, respond.data])
// setUnreadnumber([...unreadnumber, respond.data])
arr
=
[...
arr
,
respond
.
data
]
arr
=
[...
arr
,
respond
.
data
]
}
}
...
@@ -73,18 +59,17 @@ function ClosedList(props) {
...
@@ -73,18 +59,17 @@ function ClosedList(props) {
}
}
return
(
return
(
<
div
>
<
div
>
{
list
.
map
((
item
,
index
)
=>
{
props
.
closed
list
.
map
((
item
,
index
)
=>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
name
=
{
item
.
roomId
}
value
=
{
item
.
roomName
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
name
=
{
item
.
roomId
}
value
=
{
item
.
roomName
}
>
{
item
.
roomName
}
{
item
.
roomName
}
{
unreadnumber
[
index
]
?
<
Badge
className
=
'
ml-2
'
pill
variant
=
'
danger
'
>
{
unreadnumber
[
index
]}
<
/Badge> : ''
}
{
unreadnumber
[
index
]
?
<
Badge
className
=
'
ml-2
'
pill
variant
=
'
danger
'
>
{
unreadnumber
[
index
]}
<
/Badge> : ''
}
<
/ListGroup.Item
>
<
/ListGroup.Item
>
<
/ListGroup
>
<
/ListGroup
>
)
)
}
}
<
/div
>
<
/div
>
)
)
}
}
...
...
client/src/Components/OpenList.js
View file @
15336d57
...
@@ -3,18 +3,6 @@ import { ListGroup } from 'react-bootstrap';
...
@@ -3,18 +3,6 @@ import { ListGroup } from 'react-bootstrap';
import
axios
from
'
axios
'
import
axios
from
'
axios
'
function
OpenList
(
props
)
{
function
OpenList
(
props
)
{
const
[
openlist
,
setOpenlist
]
=
useState
([])
useEffect
(()
=>
{
getOpenList
();
},
[
props
.
roomCode
]);
async
function
getOpenList
()
{
let
res
=
await
axios
.
get
(
'
/room/openlist
'
)
console
.
log
(
'
getOpenlist
'
,
res
.
data
)
setOpenlist
(
res
.
data
)
}
function
enterChatRoomCH
(
e
)
{
function
enterChatRoomCH
(
e
)
{
if
(
props
.
roomCode
){
if
(
props
.
roomCode
){
...
@@ -31,7 +19,7 @@ function OpenList(props) {
...
@@ -31,7 +19,7 @@ function OpenList(props) {
return
(
return
(
<
div
>
<
div
>
{
openlist
.
map
((
item
,
index
)
=>
{
props
.
openlist
.
map
((
item
,
index
)
=>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
name
=
{
item
.
roomId
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
name
=
{
item
.
roomId
}
>
{
item
.
roomName
}
{
item
.
roomName
}
...
...
client/src/Pages/HomePage.js
View file @
15336d57
...
@@ -17,6 +17,13 @@ const INIT_ROOM = {
...
@@ -17,6 +17,13 @@ const INIT_ROOM = {
roomId
:
''
,
roomId
:
''
,
member
:
''
,
member
:
''
,
}
}
const
INIT_LIST
=
[{
interest
:
''
,
isOpen
:
''
,
memeber
:
[],
roomId
:
''
,
roomName
:
''
,
}]
function
Home
()
{
function
Home
()
{
const
userName
=
sessionStorage
.
getItem
(
'
name
'
)
const
userName
=
sessionStorage
.
getItem
(
'
name
'
)
...
@@ -44,7 +51,7 @@ function Home() {
...
@@ -44,7 +51,7 @@ function Home() {
const
[
singleTime
,
setSingleTime
]
=
useState
(
''
)
const
[
singleTime
,
setSingleTime
]
=
useState
(
''
)
const
[
recievedTime
,
setRecievedTime
]
=
useState
(
''
)
const
[
recievedTime
,
setRecievedTime
]
=
useState
(
''
)
const
[
leaveInfo
,
setLeaveInfo
]
=
useState
([{
roomName
:
""
,
leaveTime
:
""
}])
const
[
leaveInfo
,
setLeaveInfo
]
=
useState
([{
roomName
:
""
,
leaveTime
:
""
}])
const
handleCloseModal
=
()
=>
setShowModal
(
false
);
const
handleCloseModal
=
()
=>
setShowModal
(
false
);
const
handleShowModal
=
()
=>
setShowModal
(
true
);
const
handleShowModal
=
()
=>
setShowModal
(
true
);
...
@@ -52,6 +59,8 @@ function Home() {
...
@@ -52,6 +59,8 @@ function Home() {
const
handleShowEnter
=
()
=>
setShowEnter
(
true
);
const
handleShowEnter
=
()
=>
setShowEnter
(
true
);
const
handleChato
=
()
=>
setChat
(
true
);
const
handleChato
=
()
=>
setChat
(
true
);
const
handleChatc
=
()
=>
setChat
(
false
);
const
handleChatc
=
()
=>
setChat
(
false
);
const
[
closedlist
,
setClosedList
]
=
useState
(
INIT_LIST
);
const
[
openlist
,
setOpenlist
]
=
useState
([])
//SOCKET 관련 시작
//SOCKET 관련 시작
async
function
enterChatRoom
(
rCode
)
{
//방 입장하기
async
function
enterChatRoom
(
rCode
)
{
//방 입장하기
...
@@ -72,6 +81,18 @@ function Home() {
...
@@ -72,6 +81,18 @@ function Home() {
setRoomCode
(
""
)
setRoomCode
(
""
)
}
}
async
function
getClosedList
()
{
const
userid
=
sessionStorage
.
getItem
(
'
userId
'
)
let
res
=
await
axios
.
get
(
'
/room/closedlist
'
,
{
params
:
{
'
_id
'
:
userid
}
})
setClosedList
(
res
.
data
)
}
async
function
getOpenList
()
{
let
res
=
await
axios
.
get
(
'
/room/openlist
'
)
console
.
log
(
'
getOpenlist
'
,
res
.
data
)
setOpenlist
(
res
.
data
)
}
//오픈채팅방에서 참가하기
//오픈채팅방에서 참가하기
async
function
openListroom
(
roomId
)
{
async
function
openListroom
(
roomId
)
{
console
.
log
(
roomId
)
console
.
log
(
roomId
)
...
@@ -101,6 +122,11 @@ function Home() {
...
@@ -101,6 +122,11 @@ function Home() {
e
.
preventDefault
()
e
.
preventDefault
()
}
}
useEffect
(()
=>
{
getClosedList
();
getOpenList
();
},
[
roomCode
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
!
(
singleChat
===
""
))
{
if
(
!
(
singleChat
===
""
))
{
socket
.
emit
(
"
chat
"
,
{
socket
.
emit
(
"
chat
"
,
{
...
@@ -130,7 +156,6 @@ function Home() {
...
@@ -130,7 +156,6 @@ function Home() {
}
}
},
[
sysmsg
])
},
[
sysmsg
])
useEffect
(()
=>
{
useEffect
(()
=>
{
socket
.
on
(
"
sendedMSG
"
,
(
sendInfo
)
=>
{
socket
.
on
(
"
sendedMSG
"
,
(
sendInfo
)
=>
{
setRecievedTime
(
sendInfo
.
time
)
setRecievedTime
(
sendInfo
.
time
)
...
@@ -148,10 +173,10 @@ function Home() {
...
@@ -148,10 +173,10 @@ function Home() {
<
Col
className
=
"
list
"
md
=
{
5
}
>
<
Col
className
=
"
list
"
md
=
{
5
}
>
<
Tabs
defaultActiveKey
=
"
closed
"
id
=
"
uncontrolled-tab-example
"
>
<
Tabs
defaultActiveKey
=
"
closed
"
id
=
"
uncontrolled-tab-example
"
>
<
Tab
eventKey
=
"
closed
"
title
=
"
내 채팅
"
onClick
=
{
handleChato
}
>
<
Tab
eventKey
=
"
closed
"
title
=
"
내 채팅
"
onClick
=
{
handleChato
}
>
<
ClosedList
singleChat
=
{
singleChat
}
recievedMsg
=
{
recievedMsg
}
leaveInfo
=
{
leaveInfo
}
setLeaveInfo
=
{
setLeaveInfo
}
enterChatRoom
=
{
enterChatRoom
}
setRoomCode
=
{
setRoomCode
}
setRoomName
=
{
setRoomName
}
roomCode
=
{
roomCode
}
/
>
<
ClosedList
closedlist
=
{
closedlist
}
singleChat
=
{
singleChat
}
recievedMsg
=
{
recievedMsg
}
leaveInfo
=
{
leaveInfo
}
setLeaveInfo
=
{
setLeaveInfo
}
enterChatRoom
=
{
enterChatRoom
}
setRoomCode
=
{
setRoomCode
}
setRoomName
=
{
setRoomName
}
roomCode
=
{
roomCode
}
closeChatRoom
=
{
closeChatRoom
}
/
>
<
/Tab
>
<
/Tab
>
<
Tab
eventKey
=
"
open
"
title
=
"
공개방
"
onClick
=
{
handleChatc
}
>
<
Tab
eventKey
=
"
open
"
title
=
"
공개방
"
onClick
=
{
handleChatc
}
>
<
OpenList
enterChatRoom
=
{
enterChatRoom
}
openListroom
=
{
openListroom
}
setRoomCode
=
{
setRoomCode
}
setRoomName
=
{
setRoomName
}
roomCode
=
{
roomCode
}
closeChatRoom
=
{
closeChatRoom
}
/
>
<
OpenList
openlist
=
{
openlist
}
enterChatRoom
=
{
enterChatRoom
}
openListroom
=
{
openListroom
}
setRoomCode
=
{
setRoomCode
}
setRoomName
=
{
setRoomName
}
roomCode
=
{
roomCode
}
closeChatRoom
=
{
closeChatRoom
}
/
>
<
/Tab
>
<
/Tab
>
<
/Tabs
>
<
/Tabs
>
<
/Col
>
<
/Col
>
...
...
server/controllers/room.controller.js
View file @
15336d57
...
@@ -140,10 +140,12 @@ const unreadMessage = async (req, res) => {
...
@@ -140,10 +140,12 @@ const unreadMessage = async (req, res) => {
let
leaveInfo
=
req
.
query
.
leaveInfo
let
leaveInfo
=
req
.
query
.
leaveInfo
const
roomId
=
req
.
query
.
roomId
const
roomId
=
req
.
query
.
roomId
let
leaveTime
=
''
let
leaveTime
=
''
console
.
log
(
'
서버에서 초기 leaveInfo
'
,
leaveInfo
)
for
(
let
i
=
1
;
i
<
leaveInfo
.
length
;
i
++
)
{
//일단 형식좀 맞추고
for
(
let
i
=
1
;
i
<
leaveInfo
.
length
;
i
++
)
{
//일단 형식좀 맞추고
leaveInfo
[
i
]
=
JSON
.
parse
(
leaveInfo
[
i
])
leaveInfo
[
i
]
=
JSON
.
parse
(
leaveInfo
[
i
])
}
}
//findOne으로 해보자
for
(
let
i
=
1
;
i
<=
leaveInfo
.
length
-
1
;
i
++
)
{
//그 방의 id와 나간기록의 방과 일치하는지 확인하고
for
(
let
i
=
1
;
i
<=
leaveInfo
.
length
-
1
;
i
++
)
{
//그 방의 id와 나간기록의 방과 일치하는지 확인하고
if
(
leaveInfo
[
i
].
roomName
===
roomId
)
{
if
(
leaveInfo
[
i
].
roomName
===
roomId
)
{
leaveTime
=
leaveInfo
[
i
].
leaveTime
//그 방에서 나간 시간을 찾아옴
leaveTime
=
leaveInfo
[
i
].
leaveTime
//그 방에서 나간 시간을 찾아옴
...
@@ -154,6 +156,7 @@ const unreadMessage = async (req, res) => {
...
@@ -154,6 +156,7 @@ const unreadMessage = async (req, res) => {
const
room_id
=
await
Room
.
find
({
roomId
:
roomId
}).
select
(
'
_id
'
)
//id로 _id를 찾아와서
const
room_id
=
await
Room
.
find
({
roomId
:
roomId
}).
select
(
'
_id
'
)
//id로 _id를 찾아와서
let
unreadMsg
=
await
Chat
.
find
({
room
:
room_id
}).
select
(
'
createdAt
'
)
//그 방의 메세지와 전송시간을 가져옴
let
unreadMsg
=
await
Chat
.
find
({
room
:
room_id
}).
select
(
'
createdAt
'
)
//그 방의 메세지와 전송시간을 가져옴
let
count
=
0
let
count
=
0
//mongoose 시간비교 방법이 있음 (gte...)
for
(
let
i
=
0
;
i
<=
unreadMsg
.
length
-
1
;
i
++
)
{
for
(
let
i
=
0
;
i
<=
unreadMsg
.
length
-
1
;
i
++
)
{
const
dbtime
=
Date
.
parse
(
unreadMsg
[
i
].
createdAt
)
const
dbtime
=
Date
.
parse
(
unreadMsg
[
i
].
createdAt
)
const
parsedleaveTime
=
Date
.
parse
(
leaveTime
)
const
parsedleaveTime
=
Date
.
parse
(
leaveTime
)
...
...
server/controllers/roomEnter.controller.js
View file @
15336d57
...
@@ -28,27 +28,13 @@ const getChatInfo = async (req, res) => {
...
@@ -28,27 +28,13 @@ const getChatInfo = async (req, res) => {
const
roomId
=
req
.
query
.
roomCode
const
roomId
=
req
.
query
.
roomCode
try
{
try
{
const
room_id
=
await
Room
.
find
({
roomId
:
roomId
}).
select
(
'
_id
'
)
//roomId로 해당 방의 _id를 찾아옴
const
room_id
=
await
Room
.
find
({
roomId
:
roomId
}).
select
(
'
_id
'
)
//roomId로 해당 방의 _id를 찾아옴
let
infolist
=
await
Chat
.
find
({
room
:
room_id
}).
select
(
'
message username createdAt
'
)
let
infolist
=
await
Chat
.
find
({
room
:
room_id
}).
select
(
'
message username createdAt
profileimg
'
)
res
.
json
(
infolist
)
res
.
json
(
infolist
)
}
catch
(
error
)
{
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
이전 채팅 정보 불러오기를 실패하였습니다!
'
)
res
.
status
(
500
).
send
(
'
이전 채팅 정보 불러오기를 실패하였습니다!
'
)
}
}
}
}
const
getProfileImage
=
async
(
req
,
res
)
=>
{
const
nicknamelist
=
req
.
query
.
userlist
try
{
let
imglist
=
[]
for
(
let
prop
in
nicknamelist
)
{
const
getimg
=
await
User
.
find
({
nickname
:
nicknamelist
[
prop
]
}).
select
(
'
profileimg
'
)
const
eachimg
=
{
profileimg
:
getimg
[
0
].
profileimg
}
imglist
=
[...
imglist
,
eachimg
]
}
res
.
json
(
imglist
)
}
catch
(
error
)
{
res
.
status
(
500
).
send
(
'
프로필 사진 정보 불러오기를 실패하였습니다!
'
)
}
}
export
default
{
roomEnter
,
getChatInfo
,
getProfileImage
}
export
default
{
roomEnter
,
getChatInfo
}
\ No newline at end of file
\ No newline at end of file
server/models/Chat.js
View file @
15336d57
...
@@ -16,6 +16,10 @@ const ChatSchema = new mongoose.Schema({
...
@@ -16,6 +16,10 @@ const ChatSchema = new mongoose.Schema({
type
:
String
,
type
:
String
,
required
:
true
required
:
true
},
},
profileimg
:{
type
:
String
,
default
:
'
3cd14b9bcb2007f324fcb82e0b566cce
'
}
},
{
},
{
timestamps
:
true
timestamps
:
true
})
})
...
...
server/routes/roomEnter.routers.js
View file @
15336d57
...
@@ -9,7 +9,5 @@ router.route('/room/enterRoom')
...
@@ -9,7 +9,5 @@ router.route('/room/enterRoom')
router
.
route
(
'
/room/getChatInfo
'
)
router
.
route
(
'
/room/getChatInfo
'
)
.
get
(
roomEnterCtrl
.
getChatInfo
)
.
get
(
roomEnterCtrl
.
getChatInfo
)
router
.
route
(
'
/room/getProfileImage
'
)
.
get
(
roomEnterCtrl
.
getProfileImage
)
export
default
router
export
default
router
\ No newline at end of file
server/server.js
View file @
15336d57
...
@@ -49,7 +49,8 @@ io.on("connection", (socket) => { // 기본 연결
...
@@ -49,7 +49,8 @@ io.on("connection", (socket) => { // 기본 연결
const
chat
=
await
new
Chat
({
const
chat
=
await
new
Chat
({
room
:
room
.
_id
,
room
:
room
.
_id
,
username
:
data
.
sendInfo
.
sender
,
username
:
data
.
sendInfo
.
sender
,
message
:
data
.
sendInfo
.
msg
message
:
data
.
sendInfo
.
msg
,
profileimg
:
data
.
sendInfo
.
img
}).
save
()
}).
save
()
console
.
log
(
'
resChat확인
'
,
chat
)
console
.
log
(
'
resChat확인
'
,
chat
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment