Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

채팅방 초대 기능 구현 #118

Merged
merged 12 commits into from
Nov 24, 2021
Merged

Conversation

HanCiHu
Copy link
Member

@HanCiHu HanCiHu commented Nov 23, 2021

개요

  • 채팅방 초대 기능 구현

  • 모바일 반응형 UI 구현

작업사항

  • 음성채팅방 내부 버튼 클릭 오류 해결
  • 채팅 기록 업데이트 부분 reducer로 코드 분리
  • DB에 채팅 추가해주는 로직 API 요청 > 소켓으로 리팩토링
  • 초대 메세지 보내고, 해당 메세지 클릭시 채팅방 이동

  • 모바일 환경에서도 텍스트, 이미지가 꺠지지 않도록 물결님과 함께 개선하였습니다 :)

변경로직

  • DB에 채팅을 추가해주는 API를 삭제하였습니다.
  • 모든 채팅은 소켓을 통해서 이루어지기 때문에 해당 기능은 소켓에서 맡아서 해주고 있습니다.

변경후

  • 채팅방 초대 메세지 보내기 기능
2021-11-23.8.30.43.mov
  • 초대 메세지 보낸 사용자 채팅방 목록 실시간 업데이트
2021-11-23.9.05.34.mov
  • 초대 메세지 보낸 사용자 채팅방 내부 실시간 업데이트
2021-11-23.9.06.50.mov
  • 모바일 UI 개선
2021-11-24.12.04.51.mov

사용방법

  • closed 에서 사용자를 선택하거나, 채팅방 내부에서 + 버튼을 통해 다른 사용자를 초대하는 메세지를 보낼수 있습니다.

기타

  • 현재 유저들을 초대하는 모달창이 미완성인것 같아요!
  • closed나 초대하는 기능에서 다른 사람에게는 실시간으로 잘 가는데 자기자신에게는 실시간으로 보낸 메세지가 확인이 안되네요... 수정하겠습니다 >> 해결 했습니다 :)

@HanCiHu HanCiHu added 🐠 front-end 프론트 관련 이슈 🐟 back-end 백엔드 관련 이슈 ✨ feature 기능 개발 관련 이슈 labels Nov 23, 2021
console.error(error);
}
};

export const setUnCheckedMsg0 = async (chatDocumentId: string, userDocumentId: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

언젠간 프론트에서도 api를 라우터별로 나누면 찾기 좋을 것 같네요 fetch해서 받아오는 interface도 명시해주면 재사용이 쉬울텐데 뭔가 대대적인 변경이 있어야 할 것 같아서 두려운건 어쩔 수 없네요.. ㅜ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리팩토링 이슈에도 제가 올렸던것 같은데 저도 api 파일이 좀 커진것 같아서 나누면 좋겠다는 생각을 했습니다 !!

@@ -49,6 +51,10 @@ const DoneBtn = () => {
state: { participantsInfo: selectedUserList },
});
setSelectedUserList([]);
chatSocket.emit('chat:makeChat', {
chatDocumentId: res.chatRoomId,
participantsInfo: [...selectedUserList, { userDocumentId: user.userDocumentId, userName: user.userName, profileUrl: user.profileUrl }],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

데이터를 받는 쪽에서 isLoggedin 때문에 문제가 생기지 않는다면
participantsInfo: [...selectedUserList, { ...user }] 도 괜찮을 것 같네요!

Copy link
Member Author

@HanCiHu HanCiHu Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗... 이제보니 그렇네요 !! 고치겠습니다
다시 확인해보니 userDocumentId, userName, profileUrl을 그대로 넣어줘서 상태로 사용하는 로직이 있어서 isLoggedin 때문에 안될것 같아요...ㅠㅠ 아쉽네요 뭔가...

Comment on lines +12 to +25
export function chatReducer(state: any, action: any): any {
const { type, payload } = action;

switch (type) {
case 'ADD_CHATTING_LOG': {
const { chatLog } = payload;
const newChattingLog = deepCopy(state.chattingLog);
newChattingLog.push(chatLog);

return { ...state, chattingLog: newChattingLog };
}

case 'UPDATE': {
const { responseChattingLog, user, participantsInfo } = payload;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reducer의 액션 네임을 보고 어떠한 역할인지 바로 알 수 있어서 가독성이 좋아진 것 것 같습니다! 다만 any 타입이 많아서 실제로 데이터가 어떠한 구조인지 따라가기가 쉽지는 않네요ㅜ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 any 사용한 부분 리팩토링의 필요성을 간절하게 느끼고 있습니다 ㅠㅠ
빠른 시일 내에 개선해보도록 할게요 !!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅋㅋㅋㅋ reducer 도입하다가 에러가 너무떠서 급한 마음에 any를 넣었네요....

Comment on lines -98 to +109
setChattingLog(res.chattingLog.map((chat: any) => {
if (chat.userDocumentId === user.userDocumentId) {
return ({
message: chat.message,
userDocumentId: chat.userDocumentId,
profileUrl: user.profileUrl,
userName: user.userName,
date: makeDateToHourMinute(new Date(chat.date)),
});
}
const userData = location.state.participantsInfo.filter((userInfo: any) => userInfo.userDocumentId === chat.userDocumentId);
return ({
message: chat.message,
userDocumentId: chat.userDocumentId,
profileUrl: userData[0].profileUrl,
userName: userData[0].userName,
date: makeDateToHourMinute(new Date(chat.date)),
});
}));
dispatch({ type: 'UPDATE', payload: { responseChattingLog: res.chattingLog, participantsInfo: location.state.participantsInfo, user } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엄청 짧아졌네요.. 맞죠?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분을 빼내기 위해 reducer를 사용했어요 !
성빈님이 구현해주셨습니다 :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드를 보고 reducer를 이해하게 되었습니다. 이런식으로 사용하면 좋군요!

@HanCiHu HanCiHu merged commit 146eb6e into boostcampwm-2021:dev Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐟 back-end 백엔드 관련 이슈 ✨ feature 기능 개발 관련 이슈 🐠 front-end 프론트 관련 이슈
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants