본문 바로가기

아카이브/Mine Villages

Mine Villages DM 개념 잡기

728x90

 

 

DM 서비스 개요

DM창 요청 > 이전 Message 불러오기 > 웹 소켓  > 메시지 MongoDB 저장 

                                                                            > 웹소켓으로 메시지 주고 받기

이전 메시지 저장 및 조회

유저의 연결 (ex: AB, BC, AD)마다 다른 roomID를 부여

userID는 알파벳 순으로 정렬

이전 메시지는 userID 2명을 기준으로 find하여 roomID 조회  > 해당 room의 최신 20개 데이터 조회 (더보기 기능으로 페이지네이션)

roomID마다 별도의 도큐먼트 생성 (도큐먼트 용량 제한 16MB)
roomID = UserID1 + UserID2

 

안 읽은 메시지 숫자 

read 라는 필드 만들어 Boolean 체크 

 

도큐먼트 예시

{
    "_id": ObjectId("60a5c3a9b44b787eddb31735"),
    "name": "user123_user456",
    "messages": [
        {"sender": "user123", "message": "Hello!", "timestamp": ISODate("2022-04-06T12:00:00Z"), "read": true},
        {"sender": "user456", "message": "Hi there!", "timestamp": ISODate("2022-04-06T12:05:00Z"), "read":true}
    ]
}