Skip to content

Commit

Permalink
fix(#137): 매칭 성공 후 매너평가 메시지 다른 사람에게 보이는 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
heekyungdo committed Oct 16, 2024
1 parent 1674f72 commit 59937ad
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 66 deletions.
120 changes: 62 additions & 58 deletions src/components/chat/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const MessageList = (props: MessageListProps) => {

/* 매너 시스템 소켓 이벤트 리스닝 */
useEffect(() => {
if (chatEnterData.uuid !== currentChatUuid) return;

if (mannerSystemMessage) {
const chatroomUuid = mannerSystemMessage?.chatroomUuid;
const newChatTimestamp = mannerSystemMessage.timestamp;
Expand Down Expand Up @@ -102,6 +104,8 @@ const MessageList = (props: MessageListProps) => {

/* 새로운 메시지 전에 시스템 메시지 보여주기 */
useEffect(() => {
if (chatEnterData.uuid !== currentChatUuid) return;

if (newMessage) {
setMessageList((prevMessages) => {
let updatedMessages = [...prevMessages];
Expand Down Expand Up @@ -336,21 +340,21 @@ const MessageList = (props: MessageListProps) => {
</ErrorBox>
)}
<ChatBorder>
<ChatMain ref={chatRef}>
{messageList.map((message, index) => {
const showProfileImage = handleDisplayProfileImage(messageList, index);
const showTime = handleDisplayTime(messageList, index);

return (
<MsgContainer key={index}>
{handleDisplayDate(messageList, index) && <Timestamp>{setChatDateFormatter(message.createdAt)}</Timestamp>}
{message.systemType === 0 ? (
<SystemMessage
message={message.message}
onClick={() => handlePostOpen(message.boardId as number)}
/>
) : message.systemType === 1 ? (
<>
{chatEnterData.uuid === currentChatUuid &&
<ChatMain ref={chatRef}>
{messageList.map((message, index) => {
const showProfileImage = handleDisplayProfileImage(messageList, index);
const showTime = handleDisplayTime(messageList, index);

return (
<MsgContainer key={index}>
{handleDisplayDate(messageList, index) && <Timestamp>{setChatDateFormatter(message.createdAt)}</Timestamp>}
{message.systemType === 0 ? (
<SystemMessage
message={message.message}
onClick={() => handlePostOpen(message.boardId as number)}
/>
) : message.systemType === 1 ? (
<FeedbackDiv>
<FeedbackContainer>
<Feedback>
Expand All @@ -367,49 +371,49 @@ const MessageList = (props: MessageListProps) => {
</Feedback>
</FeedbackContainer>
</FeedbackDiv>
</>
) : message.senderId === chatEnterData?.memberId ? (
<YourMessageContainer>
{showProfileImage && message.senderProfileImg && (
<ImageWrapper $bgColor={getProfileBgColor(message.senderProfileImg)}
onClick={() => handleMoveProfile(chatEnterData.memberId)}
>
<ProfileImage
data={chatEnterData.blind ? `/assets/images/profile/profile_default.svg` : `/assets/images/profile/profile${message.senderProfileImg}.svg`}
width={38}
height={38}
/>
</ImageWrapper>
)}
<YourDiv $hasProfileImage={showProfileImage}>
<YourMessage>{message.message}</YourMessage>
{showTime ? <YourDate>{setChatTimeFormatter(message.createdAt)}</YourDate> : null}
</YourDiv>
</YourMessageContainer>
) : message.senderId !== chatEnterData?.memberId && message.senderId !== 0 && (
<MyMessageContainer>
<MyDiv>
{showTime ? <MyDate>{setChatTimeFormatter(message.createdAt)}</MyDate> : null}
<MyMessage>{message.message}</MyMessage>
</MyDiv>
</MyMessageContainer>
)}
</MsgContainer>
)
})}
{isLoading && (
<LoadingContainer>
<LoadingSpinner />
</LoadingContainer>
)}
{isFeedbackModalOpen &&
<ConfirmModal
type="manner"
width="315px"
primaryButtonText="확인"
onPrimaryClick={() => dispatch(setCloseMannerStatusModal())} />
}
</ChatMain>
) : message.senderId === chatEnterData?.memberId ? (
<YourMessageContainer>
{showProfileImage && message.senderProfileImg && (
<ImageWrapper $bgColor={getProfileBgColor(message.senderProfileImg)}
onClick={() => handleMoveProfile(chatEnterData.memberId)}
>
<ProfileImage
data={chatEnterData.blind ? `/assets/images/profile/profile_default.svg` : `/assets/images/profile/profile${message.senderProfileImg}.svg`}
width={38}
height={38}
/>
</ImageWrapper>
)}
<YourDiv $hasProfileImage={showProfileImage}>
<YourMessage>{message.message}</YourMessage>
{showTime ? <YourDate>{setChatTimeFormatter(message.createdAt)}</YourDate> : null}
</YourDiv>
</YourMessageContainer>
) : message.senderId !== chatEnterData?.memberId && message.senderId !== 0 && (
<MyMessageContainer>
<MyDiv>
{showTime ? <MyDate>{setChatTimeFormatter(message.createdAt)}</MyDate> : null}
<MyMessage>{message.message}</MyMessage>
</MyDiv>
</MyMessageContainer>
)}
</MsgContainer>
)
})}
{isLoading && (
<LoadingContainer>
<LoadingSpinner />
</LoadingContainer>
)}
{isFeedbackModalOpen &&
<ConfirmModal
type="manner"
width="315px"
primaryButtonText="확인"
onPrimaryClick={() => dispatch(setCloseMannerStatusModal())} />
}
</ChatMain>
}
</ChatBorder >
</>
);
Expand Down
10 changes: 2 additions & 8 deletions src/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ let socketId: string | null = null;
export const connectSocket = (): void => {


if (!!socket?.connected) {
if (socket?.connected) {
return;
}

// 클라이언트 사이드에서만 실행
if (typeof window !== "undefined") {
const token = getAccessToken();

// if (!token) {
// alert("로그인 세션이 만료되었습니다. 로그인 페이지로 이동합니다.")
// window.location.href = "https://www.gamegoo.co.kr/login";
// return;
// }


const options = token ? { auth: { token } } : {};

socket = io(SOCKET_URL, options);
Expand Down

0 comments on commit 59937ad

Please sign in to comment.