• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 JavaScript, TS 게시판 채팅방 중복 개설

채팅방 중복 개설

3 글 보임 - 21 에서 23 까지 (총 23 중에서)
  • 글쓴이
  • #67913

    이형민
    참가자
    $('#chat').click(function () {
    db.collection("chatroom").where("who", "array-contains-any", [구매자uid, 판매자uid]).get().then((result) => {
    console.log(result.empty)
    console.log(구매자uid)
    console.log(판매자uid)
    if (result.empty == true) {
    //새로 채팅방 개설
    var 데이터 = {
    who: [내uid, 판매자uid],
    판매자uid,
    구매자uid,
    product: 상품명,
    productID,
    date: new Date()
     }
    db.collection('chatroom').add(데이터).then(function (doc) {
    console.log(doc.id);
    sessionStorage.setItem('chatroom', JSON.stringify(doc.id))
    채팅방id = JSON.parse(sessionStorage.getItem('chatroom'));
    setTimeout(() => window.location.href = 'chatroom.html?id=' + 채팅방id, 2000);
     })
     }
    else {
    //기존 채팅방 불러오기
    result.forEach((a) => {
    //기존 채팅방으로 이동
    if (내uid === a.data().who[0] && 판매자uid === a.data().who[1]) {
    console.log(a.data().who[0]);
    console.log(a.data().who[1]);
    //채팅방 id 출력
    db.collection("chatroom").get(a.id).then(function (doc) {
    console.log(a.id)
     });
    기존채팅방id = a.id;
    console.log(기존채팅방id);
    //기존 채팅방으로 가기
    setTimeout(() => window.location.href = 'chatroom.html?id=' + 기존채팅방id, 2000);
     }
     })
     }
     })
     })
    
    
    말씀하신대로 코드 수정했지만, db 상에 하나라도 저장된 데이터가 있으면 false를 띄웁니다
     
    #67988

    codingapple
    키 마스터
    보니까 array의 문자를 전부포함하는걸 가져오는 쿼리는 줄수 없나봅니다
    
    db.collection('chatroom').where('who', 'array-contains-any', [내uid]).get().then((r)=>{
            var 중복여부 = false;
            r.forEach((a)=>{
              console.log(a.data().who)
              var dup = a.data().who.includes(판매자uid)
              if (dup) { 
                중복여부 = true;
              }
            })
            
            if(중복여부 == false){
              새로운채팅방생성~
            }
    })
    이렇게합시다 근데 요금이 많이나올텐데 채팅방목록을 다른 문서에 따로 기록해두거나하는 방법을 생각해보는 것도 좋을듯요
    #68159

    이형민
    참가자
    감사합니다!!
3 글 보임 - 21 에서 23 까지 (총 23 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠