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
04d0fdb6
Commit
04d0fdb6
authored
Jan 25, 2021
by
JeongYeonwoo
Browse files
안읽은메세리 구분 주석처리
parent
34d0df05
Changes
3
Hide whitespace changes
Inline
Side-by-side
client/src/Components/ClosedList.js
View file @
04d0fdb6
...
@@ -2,13 +2,7 @@ import React, { useState, useEffect } from 'react'
...
@@ -2,13 +2,7 @@ import React, { useState, useEffect } from 'react'
import
{
Badge
,
Button
,
ListGroup
}
from
'
react-bootstrap
'
;
import
{
Badge
,
Button
,
ListGroup
}
from
'
react-bootstrap
'
;
import
axios
from
'
axios
'
import
axios
from
'
axios
'
const
INIT_LIST
=
[{
interest
:
''
,
isOpen
:
''
,
memeber
:
[],
roomId
:
''
,
roomName
:
''
,
}]
function
ClosedList
(
props
)
{
function
ClosedList
(
props
)
{
const
realTime
=
new
Date
().
toISOString
()
const
realTime
=
new
Date
().
toISOString
()
...
@@ -19,45 +13,47 @@ function ClosedList(props) {
...
@@ -19,45 +13,47 @@ function ClosedList(props) {
props
.
enterChatRoom
(
roomCode
)
props
.
enterChatRoom
(
roomCode
)
props
.
setRoomCode
(
roomCode
)
props
.
setRoomCode
(
roomCode
)
console
.
log
(
'
rrrrrrrrrrrrrrr
'
,
props
.
closedlist
)
// console.log('rrrrrrrrrrrrrrr',props.closedlist)
console
.
log
(
'
1111111111111111111
'
,
props
.
leaveInfo
,
typeof
(
props
.
leaveInfo
))
// console.log('1111111111111111111',props.leaveInfo, typeof(props.leaveInfo))
// unreadMessage()
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//안읽은 메세지 count하는 부분
// const [checknew, setChecknew] = useState([])
// const [unreadnumber, setUnreadnumber] = useState([''])
// async function dbChat() {
// for (let i = 0; i <= props.closedlist.length - 1; i++) {
// const respond = await axios.get('/room/dbChat', { params: { 'roomId': props.closedlist[i].roomId } })
// setChecknew(respond.data)
// }
// }
// useEffect(() => {
// dbChat()
// }, [props.singleChat, props.recievedMsg])
// useEffect(() => {
// // console.log('chat 클라이언트 변경!')
// unreadMessage()
// }, [checknew])
const
[
checknew
,
setChecknew
]
=
useState
([])
// async function unreadMessage() {
const
[
unreadnumber
,
setUnreadnumber
]
=
useState
([
''
])
// //여기서 나간시간과 db의 메세지와 시간비교해서 개수를 count해주면 됨
async
function
dbChat
()
{
// //물론 그 방 별로 찾아서 list를 맵써서 하던?
for
(
let
i
=
0
;
i
<=
props
.
closedlist
.
length
-
1
;
i
++
)
{
// // console.log('ddddddddd', list[0].roomId)
const
respond
=
await
axios
.
get
(
'
/room/dbChat
'
,
{
params
:
{
'
roomId
'
:
props
.
closedlist
[
i
].
roomId
}
})
setChecknew
(
respond
.
data
)
}
}
useEffect
(()
=>
{
dbChat
()
},
[
props
.
singleChat
,
props
.
recievedMsg
])
useEffect
(()
=>
{
// console.log('chat 클라이언트 변경!')
unreadMessage
()
},
[
checknew
])
async
function
unreadMessage
()
{
// setUnreadnumber([''])
//여기서 나간시간과 db의 메세지와 시간비교해서 개수를 count해주면 됨
// let arr = []
//물론 그 방 별로 찾아서 list를 맵써서 하던?
// for (let i = 0; i <= props.closedlist.length - 1; i++) {
// console.log('ddddddddd', list[0].roomId)
// const respond = await axios.get('/room/unreadMessage', { params: { 'leaveInfo': props.leaveInfo, 'roomId': props.closedlist[i].roomId } })
// // setUnreadnumber([...unreadnumber, respond.data])
// arr = [...arr, respond.data]
// }
// setUnreadnumber(arr)
// // console.log('클라이언트 클로즈드 카운드', unreadnumber, list.length)
setUnreadnumber
([
''
])
// }
let
arr
=
[]
for
(
let
i
=
0
;
i
<=
props
.
closedlist
.
length
-
1
;
i
++
)
{
const
respond
=
await
axios
.
get
(
'
/room/unreadMessage
'
,
{
params
:
{
'
leaveInfo
'
:
props
.
leaveInfo
,
'
roomId
'
:
props
.
closedlist
[
i
].
roomId
}
})
// setUnreadnumber([...unreadnumber, respond.data])
arr
=
[...
arr
,
respond
.
data
]
}
setUnreadnumber
(
arr
)
// console.log('클라이언트 클로즈드 카운드', unreadnumber, list.length)
}
return
(
return
(
...
@@ -66,7 +62,7 @@ console.log('1111111111111111111',props.leaveInfo, typeof(props.leaveInfo))
...
@@ -66,7 +62,7 @@ console.log('1111111111111111111',props.leaveInfo, typeof(props.leaveInfo))
<
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>
: ''
}
{
<
Badge
className
=
'
ml-2
'
pill
variant
=
'
danger
'
>
7
<
/Badge>
}
<
/ListGroup.Item
>
<
/ListGroup.Item
>
<
/ListGroup
>
<
/ListGroup
>
)}
)}
...
...
server/controllers/room.controller.js
View file @
04d0fdb6
...
@@ -108,7 +108,7 @@ const unreadMessage = async (req, res) => {
...
@@ -108,7 +108,7 @@ 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
)
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
])
}
}
...
@@ -123,17 +123,20 @@ const unreadMessage = async (req, res) => {
...
@@ -123,17 +123,20 @@ 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
//mongoose 시간비교 방법이 있음 (gte...)
//Chat 전체가 아니라 그 방의 메세지에서 확인해야함!!
for
(
let
i
=
0
;
i
<=
unreadMsg
.
length
-
1
;
i
++
)
{
const
count
=
unreadMsg
.
find
({
createdAt
:
{
$gte
:
leaveTime
}
})
const
dbtime
=
Date
.
parse
(
unreadMsg
[
i
].
createdAt
)
console
.
log
(
'
서버에서 가자
'
,
count
.
length
)
const
parsedleaveTime
=
Date
.
parse
(
leaveTime
)
//mongoose 시간비교 방법이 있음 (gte.,lte..)
if
(
parsedleaveTime
<
dbtime
)
{
//시간 비교를하고 이후에 온 메세지의 개수를 count함
// for (let i = 0; i <= unreadMsg.length - 1; i++) {
console
.
log
(
'
이번째부터 나중에온 메세지
'
,
i
)
// const dbtime = Date.parse(unreadMsg[i].createdAt)
count
+=
1
// const parsedleaveTime = Date.parse(leaveTime)
}
// if (parsedleaveTime < dbtime) { //시간 비교를하고 이후에 온 메세지의 개수를 count함
}
// console.log('이번째부터 나중에온 메세지', i)
res
.
json
(
count
)
// count += 1
// }
// }
res
.
json
(
count
.
length
)
}
}
const
dbChat
=
async
(
req
,
res
)
=>
{
const
dbChat
=
async
(
req
,
res
)
=>
{
...
...
server/models/User.js
View file @
04d0fdb6
...
@@ -34,9 +34,6 @@ const UserSchema = new mongoose.Schema({
...
@@ -34,9 +34,6 @@ const UserSchema = new mongoose.Schema({
type
:
String
,
type
:
String
,
default
:
'
3cd14b9bcb2007f324fcb82e0b566cce
'
,
default
:
'
3cd14b9bcb2007f324fcb82e0b566cce
'
,
},
},
entrylog
:
{
type
:
Array
,
}
},
{
},
{
//옵셥을 정의함.
//옵셥을 정의함.
timestamps
:
true
timestamps
:
true
...
...
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