From 9886caebf5d8cc341b3cf65a3a225ed7d799ef93 Mon Sep 17 00:00:00 2001 From: Hajung Song Date: Tue, 10 Oct 2023 11:26:55 +0900 Subject: [PATCH 1/5] =?UTF-8?q?RoomMetadata=20=EC=8A=A4=ED=82=A4=EB=A7=88?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/chat/src/types/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/chat/src/types/index.ts b/packages/chat/src/types/index.ts index 36c896b05f..de7dfd358c 100644 --- a/packages/chat/src/types/index.ts +++ b/packages/chat/src/types/index.ts @@ -43,7 +43,7 @@ export interface RoomListResultWithPagingInterface export interface RoomMetadata { name: string memberCounts: number - faqId?: string + articleId?: string } export interface RoomInterface { From a8f2e2ce7062da3f4ca3816a26aaee4a8f618658 Mon Sep 17 00:00:00 2001 From: Hajung Song Date: Tue, 10 Oct 2023 14:34:04 +0900 Subject: [PATCH 2/5] =?UTF-8?q?RoomInterface=EC=9D=98=20metadata=20?= =?UTF-8?q?=EC=98=B5=EC=85=94=EB=84=90=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/chat/src/types/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/chat/src/types/index.ts b/packages/chat/src/types/index.ts index de7dfd358c..f4fcff0784 100644 --- a/packages/chat/src/types/index.ts +++ b/packages/chat/src/types/index.ts @@ -56,7 +56,7 @@ export interface RoomInterface { members: UserInterface[] isDirect: boolean createdAt: string - metadata: RoomMetadata + metadata?: RoomMetadata } export type DisplayTargetAll = 'all' From 74eb2da8b101ac859f7bdfd98451addfcaa26bcf Mon Sep 17 00:00:00 2001 From: guswl98 Date: Tue, 10 Oct 2023 10:13:12 +0900 Subject: [PATCH 3/5] =?UTF-8?q?retry=20function=20parameter=20message=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/chat/src/chat-bubble/chat-bubble.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/chat/src/chat-bubble/chat-bubble.tsx b/packages/chat/src/chat-bubble/chat-bubble.tsx index 8971a30277..d3ac51a7d7 100644 --- a/packages/chat/src/chat-bubble/chat-bubble.tsx +++ b/packages/chat/src/chat-bubble/chat-bubble.tsx @@ -22,8 +22,8 @@ interface ChatBubbleProps { displayTarget: UserType postMessageAction?: PostMessageActionType disableUnreadCount?: boolean - onRetryButtonClick?: () => void - onRetryCancelButtonClick?: () => void + onRetryButtonClick?: (message: MessageInterface) => void + onRetryCancelButtonClick?: (message: MessageInterface) => void blindedText?: string bubbleColor?: ChatBubbleColor } @@ -79,7 +79,7 @@ const ChatBubble = ({ !!postMessageAction const onRetry = () => { - onRetryButtonClick?.() + onRetryButtonClick?.(message) return postMessageAction?.( message.payload as TextPayload | ImagePayload, true, @@ -87,7 +87,7 @@ const ChatBubble = ({ } const onCancel = () => { - onRetryCancelButtonClick?.() + onRetryCancelButtonClick?.(message) } return ( From ef1b747c004477bb32a105c60870a4888e8707b9 Mon Sep 17 00:00:00 2001 From: guswl98 Date: Tue, 10 Oct 2023 10:14:37 +0900 Subject: [PATCH 4/5] =?UTF-8?q?reducer=EC=97=90=20failedMessages=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/chat/src/chat/chat.tsx | 87 ++++++++++++++++++++++--------- packages/chat/src/chat/reducer.ts | 32 ++++++------ 2 files changed, 78 insertions(+), 41 deletions(-) diff --git a/packages/chat/src/chat/chat.tsx b/packages/chat/src/chat/chat.tsx index ef354c2de7..b4a3216ebe 100644 --- a/packages/chat/src/chat/chat.tsx +++ b/packages/chat/src/chat/chat.tsx @@ -92,6 +92,7 @@ export const Chat = ({ const [ { messages, + failedMessages, hasPrevMessage, otherUnreadInfo, lastMessageId, @@ -202,7 +203,6 @@ export const Chat = ({ dispatch({ action: ChatActions.POST, messages: newMessages, - payload, }) const lastMessage = newMessages[newMessages.length - 1] @@ -211,7 +211,7 @@ export const Chat = ({ dispatch({ action: ChatActions.FAILED_TO_POST, message: { - id: NaN, + id: new Date().getTime(), roomId: room.id, senderId: userInfo.me.id, payload, @@ -262,34 +262,73 @@ export const Chat = ({ } } + function removeFromFailedMessages(message: MessageInterface) { + dispatch({ + action: ChatActions.REMOVE_FROM_FAILED, + message, + }) + } + + function onRetry(message: MessageInterface) { + removeFromFailedMessages(message) + onRetryButtonClick?.() + } + + function onRetryCancel(message: MessageInterface) { + removeFromFailedMessages(message) + onRetryButtonClick?.() + } + return ( <> -
    - {messages.map((message: MessageInterface, index) => ( -
  • - {userInfo ? ( - - ) : null} -
  • - ))} -
+ {userInfo ? ( + <> +
    + {messages.map((message: MessageInterface) => ( +
  • + +
  • + ))} +
+
    + {failedMessages.map((message: MessageInterface) => ( +
  • + +
  • + ))} +
+ + ) : null}
diff --git a/packages/chat/src/chat/reducer.ts b/packages/chat/src/chat/reducer.ts index 14122d0b73..d0354fb10f 100644 --- a/packages/chat/src/chat/reducer.ts +++ b/packages/chat/src/chat/reducer.ts @@ -1,9 +1,4 @@ -import { - MessageInterface, - OtherUnreadInterface, - TextPayload, - ImagePayload, -} from '../types' +import { MessageInterface, OtherUnreadInterface } from '../types' export enum ChatActions { INIT, // 최초에 메시지 @@ -12,10 +7,12 @@ export enum ChatActions { POST, // 메시지 전송 FAILED_TO_POST, // 메시지 전송 실패 UPDATE, // 읽음 표시 업데이트 + REMOVE_FROM_FAILED, // 전송 실패 메세지 재전송 또는 삭제 } export interface ChatState { messages: MessageInterface[] + failedMessages: MessageInterface[] hasPrevMessage: boolean otherUnreadInfo: OtherUnreadInterface[] firstMessageId: number | null @@ -39,7 +36,6 @@ export type ChatAction = | { action: ChatActions.POST messages: MessageInterface[] - payload: TextPayload | ImagePayload } | { action: ChatActions.FAILED_TO_POST @@ -49,6 +45,7 @@ export type ChatAction = action: ChatActions.UPDATE otherUnreadInfo: OtherUnreadInterface[] } + | { action: ChatActions.REMOVE_FROM_FAILED; message: MessageInterface } export const ChatReducer = ( state: ChatState, @@ -81,15 +78,7 @@ export const ChatReducer = ( case ChatActions.POST: return { ...state, - messages: mergeMessages( - state.messages.some((message) => !message.id) - ? state.messages.filter( - (message) => - !message.id && !Object.is(message.payload, action.payload), - ) - : state.messages, - action.messages, - ), + messages: mergeMessages(state.messages, action.messages), lastMessageId: Number(action.messages[action.messages.length - 1].id), } @@ -103,7 +92,7 @@ export const ChatReducer = ( case ChatActions.FAILED_TO_POST: return { ...state, - messages: [...state.messages, action.message], + failedMessages: [...state.failedMessages, action.message], } case ChatActions.UPDATE: @@ -112,6 +101,14 @@ export const ChatReducer = ( otherUnreadInfo: action.otherUnreadInfo, } + case ChatActions.REMOVE_FROM_FAILED: + return { + ...state, + failedMessages: state.failedMessages.filter( + (message) => message.id !== action.message.id, + ), + } + default: throw new Error('unexpected action') } @@ -119,6 +116,7 @@ export const ChatReducer = ( export const initialChatState: ChatState = { messages: [], + failedMessages: [], hasPrevMessage: true, otherUnreadInfo: [], firstMessageId: null, From a2bba8ff40886493667d9bd2a64c6ad4c5531a49 Mon Sep 17 00:00:00 2001 From: guswl98 Date: Wed, 11 Oct 2023 10:59:42 +0900 Subject: [PATCH 5/5] =?UTF-8?q?ChatContainer=EC=9D=98=20Container=20prop?= =?UTF-8?q?=20=EC=84=A4=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/chat/src/chat/chat-container.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/chat/src/chat/chat-container.tsx b/packages/chat/src/chat/chat-container.tsx index 44b39e806e..d435a3526c 100644 --- a/packages/chat/src/chat/chat-container.tsx +++ b/packages/chat/src/chat/chat-container.tsx @@ -17,7 +17,7 @@ const ScrollProvider = dynamic(() => import('./scroll-context'), { export interface ChatContainerProps extends ChatContextValue { /** - * Chat list와 보내기 Input 창을 감싸는 컨테이너로, 커스텀 스타일 등 적용 가능 + * Chat list를 감싸는 컨테이너로, 커스텀 스타일 등 적용 가능 */ container: ElementType /**