@daeryun/dr_components 0.9.57 → 0.9.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/components/Daeryuntalk/ChatConversation.jsx +65 -10
- package/dist/components/Daeryuntalk/ChatConversation.tsx +65 -11
- package/dist/components/Daeryuntalk/ChatItem/ChatWrapper.jsx +2 -2
- package/dist/components/Daeryuntalk/ChatItem/ChatWrapper.tsx +2 -2
- package/dist/components/Daeryuntalk/ChatMessage.jsx +1 -1
- package/dist/components/Daeryuntalk/ChatMessage.tsx +1 -1
- package/dist/components/Daeryuntalk/ChatWidget.jsx +2 -2
- package/dist/components/Daeryuntalk/ChatWidget.tsx +2 -2
- package/dist/components/Daeryuntalk/HomeView.jsx +1 -1
- package/dist/components/Daeryuntalk/HomeView.tsx +1 -1
- package/dist/components/Daeryuntalk/Viewer/MobileViewer.jsx +2 -2
- package/dist/components/Daeryuntalk/Viewer/MobileViewer.tsx +2 -2
- package/dist/components/Daeryuntalk/Viewer/TbPcViewer.jsx +4 -2
- package/dist/components/Daeryuntalk/Viewer/TbPcViewer.tsx +2 -1
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.d.ts +1 -1
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.js +2 -4
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.ts +2 -3
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.d.ts +1 -1
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.js +21 -20
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.ts +28 -19
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.js +2 -2
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.ts +2 -2
- package/dist/components/Daeryuntalk/_lib/index.d.ts +1 -1
- package/dist/components/Daeryuntalk/_lib/index.js +2 -2
- package/dist/components/Daeryuntalk/_lib/index.ts +2 -1
- package/dist/components/Daeryuntalk/_types/message.d.ts +1 -0
- package/dist/components/Daeryuntalk/_types/message.ts +3 -0
- package/dist/components/Daeryuntalk/index.jsx +0 -1
- package/dist/components/Daeryuntalk/index.tsx +0 -1
- package/dist/styles/globals.css +13 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -30,6 +30,8 @@ const ChatConversation: React.FC<ChatConversationProps> = ({
|
|
|
30
30
|
isHash
|
|
31
31
|
}) => {
|
|
32
32
|
const {
|
|
33
|
+
getNextMessageList,
|
|
34
|
+
isNextPage,
|
|
33
35
|
inquiryStatus,
|
|
34
36
|
messages,
|
|
35
37
|
isLoading,
|
|
@@ -40,6 +42,13 @@ const ChatConversation: React.FC<ChatConversationProps> = ({
|
|
|
40
42
|
chatInquiryNumber,
|
|
41
43
|
isTyping
|
|
42
44
|
} = useDaeryuntalk();
|
|
45
|
+
|
|
46
|
+
const [isFetchingPrev, setIsFetchingPrev] = useState(false);
|
|
47
|
+
|
|
48
|
+
const sortedMessages = useMemo(() => {
|
|
49
|
+
return messages?.length ? messages.slice().sort((a, b) => a.timestamp - b.timestamp) : [];
|
|
50
|
+
}, [messages]);
|
|
51
|
+
|
|
43
52
|
const [isHovered, setIsHovered] = useState<boolean>(false);
|
|
44
53
|
|
|
45
54
|
const headerRef = useRef<HTMLDivElement | null>(null);
|
|
@@ -51,6 +60,7 @@ const ChatConversation: React.FC<ChatConversationProps> = ({
|
|
|
51
60
|
|
|
52
61
|
// 최초 렌더 여부 플래그
|
|
53
62
|
const isInitialMount = useRef(true);
|
|
63
|
+
// 이후
|
|
54
64
|
const messagesContainerRef = useRef<HTMLDivElement | null>(null);
|
|
55
65
|
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
56
66
|
|
|
@@ -100,18 +110,21 @@ const ChatConversation: React.FC<ChatConversationProps> = ({
|
|
|
100
110
|
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
101
111
|
};
|
|
102
112
|
|
|
103
|
-
// 새 메시지가 도착할 때 자동으로 스크롤 최하단으로 이동
|
|
113
|
+
// 새 메시지가 도착할 때 자동으로 스크롤 최하단으로 이동 sortedMessages의 마지막 행에 type이 live일 경우만 scrollEnd 실행
|
|
104
114
|
useEffect(() => {
|
|
115
|
+
const lastMessage = sortedMessages && sortedMessages.length > 0 && sortedMessages[sortedMessages.length - 1];
|
|
116
|
+
if (!lastMessage || lastMessage?.type !== 'live') return;
|
|
117
|
+
|
|
105
118
|
const timeout = setTimeout(() => {
|
|
106
119
|
scrollEnd();
|
|
107
120
|
}, 200);
|
|
108
121
|
return () => clearTimeout(timeout); // cleanup
|
|
109
|
-
}, [
|
|
122
|
+
}, [sortedMessages, messageObject]);
|
|
110
123
|
|
|
124
|
+
// 최초 진입 시 스크롤 최하단으로 이동
|
|
111
125
|
useEffect(() => {
|
|
112
126
|
if (!isInitialMount.current) return;
|
|
113
|
-
|
|
114
|
-
if (messages.length === 0) return;
|
|
127
|
+
if (sortedMessages.length === 0) return;
|
|
115
128
|
|
|
116
129
|
const container = messagesContainerRef.current;
|
|
117
130
|
if (!container) return;
|
|
@@ -124,7 +137,7 @@ const ChatConversation: React.FC<ChatConversationProps> = ({
|
|
|
124
137
|
hasScrolled = true;
|
|
125
138
|
|
|
126
139
|
requestAnimationFrame(() => {
|
|
127
|
-
|
|
140
|
+
scrollEnd(); // 무조건 실행
|
|
128
141
|
isInitialMount.current = false;
|
|
129
142
|
});
|
|
130
143
|
};
|
|
@@ -146,7 +159,7 @@ const ChatConversation: React.FC<ChatConversationProps> = ({
|
|
|
146
159
|
};
|
|
147
160
|
|
|
148
161
|
if (img.complete) {
|
|
149
|
-
//
|
|
162
|
+
// 강제 로드 보장
|
|
150
163
|
const newImg = new Image();
|
|
151
164
|
newImg.src = img.src;
|
|
152
165
|
newImg.onload = done;
|
|
@@ -156,7 +169,48 @@ const ChatConversation: React.FC<ChatConversationProps> = ({
|
|
|
156
169
|
img.addEventListener('error', done, { once: true });
|
|
157
170
|
}
|
|
158
171
|
});
|
|
159
|
-
|
|
172
|
+
|
|
173
|
+
// fallback 타이머로 scrollToBottom 보장 (예: 이미지 로딩 실패 시)
|
|
174
|
+
const fallback = setTimeout(() => {
|
|
175
|
+
scrollToBottom();
|
|
176
|
+
}, 500); // 1초 후 강제 실행
|
|
177
|
+
|
|
178
|
+
return () => clearTimeout(fallback);
|
|
179
|
+
}, [sortedMessages, messageObject]);
|
|
180
|
+
|
|
181
|
+
// 무한 스크롤
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
const container = messagesContainerRef.current;
|
|
184
|
+
if (!container || !isNextPage || !chatInquiryNumber || sortedMessages.length === 0) return;
|
|
185
|
+
|
|
186
|
+
const handleScroll = async () => {
|
|
187
|
+
const { scrollTop, scrollHeight, clientHeight } = container;
|
|
188
|
+
|
|
189
|
+
// 스크롤이 없더라도 무시하지 않음! → handleScroll은 무한스크롤 용도에만 사용
|
|
190
|
+
const scrolledPercent = (scrollTop / scrollHeight) * 100;
|
|
191
|
+
|
|
192
|
+
if (scrolledPercent < 5 && !isFetchingPrev) {
|
|
193
|
+
setIsFetchingPrev(true);
|
|
194
|
+
const prevScrollHeight = container.scrollHeight;
|
|
195
|
+
const oldestMessage = sortedMessages[0];
|
|
196
|
+
if (!oldestMessage?.createdAt) return;
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
await getNextMessageList(chatInquiryNumber, oldestMessage.timestamp);
|
|
200
|
+
requestAnimationFrame(() => {
|
|
201
|
+
const newScrollHeight = container.scrollHeight;
|
|
202
|
+
container.scrollTop = newScrollHeight - prevScrollHeight;
|
|
203
|
+
});
|
|
204
|
+
} finally {
|
|
205
|
+
setIsFetchingPrev(false);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
handleScroll();
|
|
210
|
+
|
|
211
|
+
container.addEventListener('scroll', handleScroll);
|
|
212
|
+
return () => container.removeEventListener('scroll', handleScroll);
|
|
213
|
+
}, [sortedMessages, chatInquiryNumber, isNextPage, isFetchingPrev, getNextMessageList]);
|
|
160
214
|
|
|
161
215
|
const isNewDay = (date1: Date, date2: Date): boolean => {
|
|
162
216
|
return (
|
|
@@ -168,9 +222,9 @@ const ChatConversation: React.FC<ChatConversationProps> = ({
|
|
|
168
222
|
|
|
169
223
|
const renderedMessages = useMemo(() => {
|
|
170
224
|
const elements: React.ReactNode[] = [];
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
225
|
+
if (sortedMessages.length < 1) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
174
228
|
|
|
175
229
|
sortedMessages.forEach((message, index) => {
|
|
176
230
|
const findObject =
|
|
@@ -202,7 +256,7 @@ const ChatConversation: React.FC<ChatConversationProps> = ({
|
|
|
202
256
|
|
|
203
257
|
return elements;
|
|
204
258
|
}, [
|
|
205
|
-
|
|
259
|
+
sortedMessages,
|
|
206
260
|
messageObject, // 둘 다 바뀌면 리렌더됨
|
|
207
261
|
isMobile,
|
|
208
262
|
inquiryStatus,
|
|
@@ -4,8 +4,8 @@ const ChatWrapper = ({ isOperator, children, className = '' }) => {
|
|
|
4
4
|
const customerClassName = 'border-drTalkBtnActive2 text-drTalkHover bg-drTalkGrayscale5';
|
|
5
5
|
return (<div className={`
|
|
6
6
|
${isOperator ? operatorClassName : customerClassName} ${className}
|
|
7
|
-
dr_talk_body_medium2 w-full whitespace-pre-line
|
|
8
|
-
rounded-[10px] border px-[12px] py-[8px]
|
|
7
|
+
dr_talk_body_medium2 w-full whitespace-pre-line
|
|
8
|
+
break-words rounded-[10px] border px-[12px] py-[8px]
|
|
9
9
|
`}>
|
|
10
10
|
{children}
|
|
11
11
|
</div>);
|
|
@@ -13,8 +13,8 @@ const ChatWrapper = ({ isOperator, children, className = '' }: props) => {
|
|
|
13
13
|
<div
|
|
14
14
|
className={`
|
|
15
15
|
${isOperator ? operatorClassName : customerClassName} ${className}
|
|
16
|
-
dr_talk_body_medium2 w-full whitespace-pre-line
|
|
17
|
-
rounded-[10px] border px-[12px] py-[8px]
|
|
16
|
+
dr_talk_body_medium2 w-full whitespace-pre-line
|
|
17
|
+
break-words rounded-[10px] border px-[12px] py-[8px]
|
|
18
18
|
`}
|
|
19
19
|
>
|
|
20
20
|
{children}
|
|
@@ -82,7 +82,7 @@ const ChatMessage = ({ message, object, handelObjectBack, chatInquiryNumber, wor
|
|
|
82
82
|
return (<div className={`flex flex-col gap-[10px]`}>
|
|
83
83
|
{/* 텍스트 + 파일인경우 */}
|
|
84
84
|
{isRichForm && (<TimeWrapper time={time}>
|
|
85
|
-
<ChatWrapper isOperator={isOperator}>
|
|
85
|
+
<ChatWrapper isOperator={isOperator} className={` !w-fit `}>
|
|
86
86
|
<RichText message={message}/>
|
|
87
87
|
</ChatWrapper>
|
|
88
88
|
</TimeWrapper>)}
|
|
@@ -115,7 +115,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|
|
115
115
|
{/* 텍스트 + 파일인경우 */}
|
|
116
116
|
{isRichForm && (
|
|
117
117
|
<TimeWrapper time={time}>
|
|
118
|
-
<ChatWrapper isOperator={isOperator}>
|
|
118
|
+
<ChatWrapper isOperator={isOperator} className={` !w-fit `}>
|
|
119
119
|
<RichText message={message} />
|
|
120
120
|
</ChatWrapper>
|
|
121
121
|
</TimeWrapper>
|
|
@@ -25,7 +25,7 @@ const ChatWidget = ({ isOpen, isMobile, onClose, hashValue, setHashValue, animat
|
|
|
25
25
|
? ``
|
|
26
26
|
: isOpen
|
|
27
27
|
? 'opacity-100 pointer-events-auto xs:translate-y-0 xs:duration-500'
|
|
28
|
-
: 'opacity-0 pointer-events-none xs:translate-y-4 xs:duration-500 '}
|
|
28
|
+
: 'opacity-0 pointer-events-none xs:translate-y-4 xs:duration-500 xs:rounded-[30px] '}
|
|
29
29
|
${isHash
|
|
30
30
|
? `
|
|
31
31
|
xs:fixed xs:flex xs:justify-center xs:items-center xs:inset-0 xs:bg-white
|
|
@@ -35,7 +35,7 @@ const ChatWidget = ({ isOpen, isMobile, onClose, hashValue, setHashValue, animat
|
|
|
35
35
|
h-[100dvh] ease-in-out
|
|
36
36
|
xs:bottom-[165px] xs:right-[25px] xs:max-w-[390px]
|
|
37
37
|
xs:max-h-[690px] xs:rounded-[30px]
|
|
38
|
-
lg:bottom-[100px]
|
|
38
|
+
lg:bottom-[100px] xs:rounded-[30px]
|
|
39
39
|
`}
|
|
40
40
|
`;
|
|
41
41
|
//
|
|
@@ -47,7 +47,7 @@ const ChatWidget: React.FC<ChatWidgetProps> = ({
|
|
|
47
47
|
? ``
|
|
48
48
|
: isOpen
|
|
49
49
|
? 'opacity-100 pointer-events-auto xs:translate-y-0 xs:duration-500'
|
|
50
|
-
: 'opacity-0 pointer-events-none xs:translate-y-4 xs:duration-500 '
|
|
50
|
+
: 'opacity-0 pointer-events-none xs:translate-y-4 xs:duration-500 xs:rounded-[30px] '
|
|
51
51
|
}
|
|
52
52
|
${
|
|
53
53
|
isHash
|
|
@@ -59,7 +59,7 @@ const ChatWidget: React.FC<ChatWidgetProps> = ({
|
|
|
59
59
|
h-[100dvh] ease-in-out
|
|
60
60
|
xs:bottom-[165px] xs:right-[25px] xs:max-w-[390px]
|
|
61
61
|
xs:max-h-[690px] xs:rounded-[30px]
|
|
62
|
-
lg:bottom-[100px]
|
|
62
|
+
lg:bottom-[100px] xs:rounded-[30px]
|
|
63
63
|
`
|
|
64
64
|
}
|
|
65
65
|
`;
|
|
@@ -110,7 +110,7 @@ const HomeView = ({ inquiryMainData, isLoading, handleStartChat, isMobile, onClo
|
|
|
110
110
|
|
|
111
111
|
<div className={`absolute left-0 top-0 z-0 w-full overflow-hidden ${isMobile ? 'aspect-[16/9] max-h-[360px]' : 'h-full max-h-[360px]'}`}>
|
|
112
112
|
{/*<div className={`relative`}>*/}
|
|
113
|
-
<Image src={backgroundImage} alt="대화 배경" fill className={`will-change-transform ${isMobile ? 'object-cover object-center' : 'object-
|
|
113
|
+
<Image src={backgroundImage} alt="대화 배경" fill className={`will-change-transform ${isMobile ? 'object-cover object-center' : ' object-cover object-top xs:object-contain '}`} priority/>
|
|
114
114
|
<div className="pointer-events-none absolute bottom-0 left-0 h-24 w-full bg-gradient-to-t from-white to-transparent"/>
|
|
115
115
|
{/*</div>*/}
|
|
116
116
|
</div>
|
|
@@ -149,7 +149,7 @@ const HomeView = ({ inquiryMainData, isLoading, handleStartChat, isMobile, onClo
|
|
|
149
149
|
alt="대화 배경"
|
|
150
150
|
fill
|
|
151
151
|
className={`will-change-transform ${
|
|
152
|
-
isMobile ? 'object-cover object-center' : 'object-
|
|
152
|
+
isMobile ? 'object-cover object-center' : ' object-cover object-top xs:object-contain '
|
|
153
153
|
}`}
|
|
154
154
|
priority
|
|
155
155
|
/>
|
|
@@ -74,7 +74,7 @@ const MobileViewer = ({ imageViewerMessage, handleDownload, currentIndex, setCur
|
|
|
74
74
|
{/* </div>*/}
|
|
75
75
|
{/*</div>*/}
|
|
76
76
|
{/* Thumbnail Preview */}
|
|
77
|
-
<div className="relative flex items-center justify-center px-[20px] pb-[65px] pt-[40px]">
|
|
77
|
+
<div className="relative m-auto flex max-w-[350px] items-center justify-center px-[20px] pb-[65px] pt-[40px]">
|
|
78
78
|
{previewImages.length > 1 ? (<Swiper spaceBetween={10} slidesPerView={Math.min(previewImages.length, 5)} watchSlidesProgress allowTouchMove>
|
|
79
79
|
{previewImages.map((img, idx) => (<SwiperSlide key={idx} className={`!w-fit`}>
|
|
80
80
|
<div onClick={() => {
|
|
@@ -84,7 +84,7 @@ const MobileViewer = ({ imageViewerMessage, handleDownload, currentIndex, setCur
|
|
|
84
84
|
setZoomLevel(3);
|
|
85
85
|
(_a = thumbSwiperRef.current) === null || _a === void 0 ? void 0 : _a.slideTo(idx); // 👈 스와이퍼 이동
|
|
86
86
|
}} className={`
|
|
87
|
-
|
|
87
|
+
relative
|
|
88
88
|
h-[50px] w-[50px] cursor-pointer overflow-hidden rounded-[10px] border-[1px]
|
|
89
89
|
${idx === currentIndex ? 'border-white' : 'opacity-50 hover:border-white hover:opacity-100'}
|
|
90
90
|
`}>
|
|
@@ -120,7 +120,7 @@ const MobileViewer = ({
|
|
|
120
120
|
{/* </div>*/}
|
|
121
121
|
{/*</div>*/}
|
|
122
122
|
{/* Thumbnail Preview */}
|
|
123
|
-
<div className="relative flex items-center justify-center px-[20px] pb-[65px] pt-[40px]">
|
|
123
|
+
<div className="relative m-auto flex max-w-[350px] items-center justify-center px-[20px] pb-[65px] pt-[40px]">
|
|
124
124
|
{previewImages.length > 1 ? (
|
|
125
125
|
<Swiper
|
|
126
126
|
spaceBetween={10}
|
|
@@ -138,7 +138,7 @@ const MobileViewer = ({
|
|
|
138
138
|
thumbSwiperRef.current?.slideTo(idx); // 👈 스와이퍼 이동
|
|
139
139
|
}}
|
|
140
140
|
className={`
|
|
141
|
-
|
|
141
|
+
relative
|
|
142
142
|
h-[50px] w-[50px] cursor-pointer overflow-hidden rounded-[10px] border-[1px]
|
|
143
143
|
${idx === currentIndex ? 'border-white' : 'opacity-50 hover:border-white hover:opacity-100'}
|
|
144
144
|
`}
|
|
@@ -94,8 +94,10 @@ const TbPcViewer = ({ imageViewerMessage, handleDownload, currentIndex, setCurre
|
|
|
94
94
|
</div>
|
|
95
95
|
|
|
96
96
|
{/* Thumbnail Preview - 고정된 위치 */}
|
|
97
|
-
{previewImages.length > 1 && (<div className="flex w-full
|
|
98
|
-
<Swiper spaceBetween={10}
|
|
97
|
+
{previewImages.length > 1 && (<div className="flex w-full max-w-[90vw] flex-row justify-center gap-[10px] overflow-x-auto px-[20px] md2:max-w-[570px] ">
|
|
98
|
+
<Swiper spaceBetween={10}
|
|
99
|
+
// slidesPerView={Math.min(previewImages.length, 5)}
|
|
100
|
+
slidesPerView={Math.min(previewImages.length, 5)} watchSlidesProgress allowTouchMove>
|
|
99
101
|
{previewImages.map((img, idx) => (<SwiperSlide key={idx} className={`!w-fit`}>
|
|
100
102
|
<div onClick={() => {
|
|
101
103
|
setCurrentIndex(idx);
|
|
@@ -169,9 +169,10 @@ const TbPcViewer = ({
|
|
|
169
169
|
|
|
170
170
|
{/* Thumbnail Preview - 고정된 위치 */}
|
|
171
171
|
{previewImages.length > 1 && (
|
|
172
|
-
<div className="flex w-full
|
|
172
|
+
<div className="flex w-full max-w-[90vw] flex-row justify-center gap-[10px] overflow-x-auto px-[20px] md2:max-w-[570px] ">
|
|
173
173
|
<Swiper
|
|
174
174
|
spaceBetween={10}
|
|
175
|
+
// slidesPerView={Math.min(previewImages.length, 5)}
|
|
175
176
|
slidesPerView={Math.min(previewImages.length, 5)}
|
|
176
177
|
watchSlidesProgress
|
|
177
178
|
allowTouchMove
|
|
@@ -59,7 +59,7 @@ export declare function getChatInquiryDetailNew(chat_inquiry_number: string, ver
|
|
|
59
59
|
* @param version API 버전 (기본값: 1.0.0)
|
|
60
60
|
* @returns 채팅 메세지 리스트
|
|
61
61
|
*/
|
|
62
|
-
export declare function getChatInquiryMessageList(chatInquiryNumber: string,
|
|
62
|
+
export declare function getChatInquiryMessageList(chatInquiryNumber: string, standardTimestamp?: number, size?: number, version?: string): Promise<IDaeryunTalkResponseWrapper<ChatInquiryMessageListDataResponse>>;
|
|
63
63
|
/**
|
|
64
64
|
* Daeryuntalk 초기화 완료 흐름
|
|
65
65
|
* 이 함수는 인증부터 웹소켓 연결까지 완전한 흐름을 처리
|
|
@@ -401,12 +401,10 @@ export function getChatInquiryDetailNew(chat_inquiry_number, version) {
|
|
|
401
401
|
* @param version API 버전 (기본값: 1.0.0)
|
|
402
402
|
* @returns 채팅 메세지 리스트
|
|
403
403
|
*/
|
|
404
|
-
export function getChatInquiryMessageList(chatInquiryNumber,
|
|
404
|
+
export function getChatInquiryMessageList(chatInquiryNumber, standardTimestamp, size, version) {
|
|
405
405
|
return __awaiter(this, void 0, void 0, function* () {
|
|
406
406
|
const body = {
|
|
407
|
-
d: Object.assign(Object.assign({ chat_inquiry_number: chatInquiryNumber }, (
|
|
408
|
-
// standard_date_time: standard_date_time ?? new Date().toISOString(),
|
|
409
|
-
size: size !== null && size !== void 0 ? size : 400 })
|
|
407
|
+
d: Object.assign(Object.assign({ chat_inquiry_number: chatInquiryNumber }, (standardTimestamp && { standard_timestamp: standardTimestamp })), { size: size !== null && size !== void 0 ? size : 400 })
|
|
410
408
|
};
|
|
411
409
|
consoleFn('[채팅 메세지 리스트] 문의 번호:', chatInquiryNumber, version ? `버전: ${version}` : `기본 버전: ${DEFAULT_API_VERSION}`);
|
|
412
410
|
try {
|
|
@@ -498,15 +498,14 @@ export async function getChatInquiryDetailNew(
|
|
|
498
498
|
*/
|
|
499
499
|
export async function getChatInquiryMessageList(
|
|
500
500
|
chatInquiryNumber: string,
|
|
501
|
-
|
|
501
|
+
standardTimestamp?: number,
|
|
502
502
|
size?: number,
|
|
503
503
|
version?: string
|
|
504
504
|
): Promise<IDaeryunTalkResponseWrapper<ChatInquiryMessageListDataResponse>> {
|
|
505
505
|
const body = {
|
|
506
506
|
d: {
|
|
507
507
|
chat_inquiry_number: chatInquiryNumber,
|
|
508
|
-
...(
|
|
509
|
-
// standard_date_time: standard_date_time ?? new Date().toISOString(),
|
|
508
|
+
...(standardTimestamp && { standard_timestamp: standardTimestamp }),
|
|
510
509
|
size: size ?? 400
|
|
511
510
|
}
|
|
512
511
|
};
|
|
@@ -39,7 +39,7 @@ export declare const useChatHandler: ({ setIsLoading, inquiryMainData, setChatIn
|
|
|
39
39
|
name: string;
|
|
40
40
|
cellPhoneNumber: string;
|
|
41
41
|
}) => Promise<import("../../_api/daeryuntalk/type/response").IDaeryunTalkResponseWrapper<any> | undefined>;
|
|
42
|
-
getNextMessageList: (chatInquiryNumber: string,
|
|
42
|
+
getNextMessageList: (chatInquiryNumber: string, standardTimestamp: number) => Promise<void>;
|
|
43
43
|
startSelectedChat: (chatInquiryNumber: string) => Promise<string | import("../../_api/daeryuntalk/type/response").IDaeryunTalkResponseWrapper<import("../../_api/daeryuntalk/type/response").ChatInquiryDetailDataResponse> | import("../../_api/daeryuntalk/type/response").IDaeryunTalkResponseWrapper<import("../../_api/daeryuntalk/type/response").ChatInquiryMessageListDataResponse>>;
|
|
44
44
|
};
|
|
45
45
|
export {};
|
|
@@ -77,8 +77,10 @@ export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNu
|
|
|
77
77
|
// 메세지 리스트 후처리
|
|
78
78
|
if (chatList.data.message_list.length > 0) {
|
|
79
79
|
const uiMessages = chatList.data.message_list
|
|
80
|
-
.sort((a, b) => a.timestamp - b.timestamp)
|
|
81
|
-
.map(
|
|
80
|
+
.sort((a, b) => a.timestamp - b.timestamp)
|
|
81
|
+
.map(item => {
|
|
82
|
+
return convertApiMessageToUiMessage(item, 'basic');
|
|
83
|
+
});
|
|
82
84
|
setMessages(uiMessages);
|
|
83
85
|
consoleFn('[DaeryuntalkContext] 메시지 설정 완료:', uiMessages.length);
|
|
84
86
|
}
|
|
@@ -151,9 +153,10 @@ export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNu
|
|
|
151
153
|
// 메세지 리스트 후처리
|
|
152
154
|
if (chatList.data.message_list.length > 0) {
|
|
153
155
|
const uiMessages = chatList.data.message_list
|
|
154
|
-
.sort((a, b) => a.timestamp - b.timestamp)
|
|
155
|
-
.map(
|
|
156
|
-
|
|
156
|
+
.sort((a, b) => a.timestamp - b.timestamp)
|
|
157
|
+
.map(item => {
|
|
158
|
+
return convertApiMessageToUiMessage(item, 'basic');
|
|
159
|
+
});
|
|
157
160
|
// const uiMessages = chatList.data.message_list.map(convertApiMessageToUiMessage);
|
|
158
161
|
setMessages(uiMessages);
|
|
159
162
|
consoleFn('[DaeryuntalkContext] 메시지 설정 완료:', uiMessages.length);
|
|
@@ -250,8 +253,10 @@ export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNu
|
|
|
250
253
|
// 메세지 리스트 후처리
|
|
251
254
|
if (((_a = chatList.data) === null || _a === void 0 ? void 0 : _a.message_list) && chatList.data.message_list.length > 0) {
|
|
252
255
|
const uiMessages = chatList.data.message_list
|
|
253
|
-
.sort((a, b) =>
|
|
254
|
-
.map(
|
|
256
|
+
.sort((a, b) => a.timestamp - b.timestamp)
|
|
257
|
+
.map(item => {
|
|
258
|
+
return convertApiMessageToUiMessage(item, 'basic');
|
|
259
|
+
});
|
|
255
260
|
setMessages(uiMessages);
|
|
256
261
|
consoleFn('[DaeryuntalkContext] 메시지 설정 완료:', uiMessages.length);
|
|
257
262
|
}
|
|
@@ -378,24 +383,21 @@ export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNu
|
|
|
378
383
|
setIsLoading === null || setIsLoading === void 0 ? void 0 : setIsLoading(false);
|
|
379
384
|
}
|
|
380
385
|
}), []);
|
|
381
|
-
|
|
386
|
+
// 무한스크롤 실행
|
|
387
|
+
const getNextMessageList = useCallback((chatInquiryNumber, standardTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
382
388
|
try {
|
|
383
|
-
const response = yield getChatInquiryMessageList(chatInquiryNumber,
|
|
389
|
+
const response = yield getChatInquiryMessageList(chatInquiryNumber, standardTimestamp);
|
|
384
390
|
if (response.result_info.result_cd === 'OK' || response.result_info.result_type_cd === 'OK') {
|
|
385
|
-
// 앞에 생성될 여기서는 앞에서부터 채워야함
|
|
386
391
|
const newMessageList = response.data.message_list
|
|
387
392
|
.sort((a, b) => a.timestamp - b.timestamp)
|
|
388
|
-
.map(item =>
|
|
389
|
-
return convertApiMessageToUiMessage(item);
|
|
390
|
-
});
|
|
393
|
+
.map(item => convertApiMessageToUiMessage(item, 'prev'));
|
|
391
394
|
setIsNextPage(response.data.next_page_yn);
|
|
392
395
|
setMessages(prev => {
|
|
393
|
-
if (newMessageList
|
|
394
|
-
return
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
396
|
+
if (!newMessageList || newMessageList.length === 0)
|
|
397
|
+
return prev;
|
|
398
|
+
const existingMessageNumbers = new Set(prev.map(msg => msg.messageNumber));
|
|
399
|
+
const filteredNewMessages = newMessageList.filter(msg => !existingMessageNumbers.has(msg.messageNumber));
|
|
400
|
+
return [...filteredNewMessages, ...prev];
|
|
399
401
|
});
|
|
400
402
|
}
|
|
401
403
|
else {
|
|
@@ -405,7 +407,6 @@ export const useChatHandler = ({ setIsLoading, inquiryMainData, setChatInquiryNu
|
|
|
405
407
|
}
|
|
406
408
|
catch (error) {
|
|
407
409
|
console.error(`[실패]:`, error);
|
|
408
|
-
// toast.error(error?.message || '오류가 발생했습니다.');
|
|
409
410
|
}
|
|
410
411
|
}), []);
|
|
411
412
|
const attendRoomByHistory = useCallback((chatInquiryNumber) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -131,8 +131,10 @@ export const useChatHandler = ({
|
|
|
131
131
|
// 메세지 리스트 후처리
|
|
132
132
|
if (chatList.data.message_list.length > 0) {
|
|
133
133
|
const uiMessages = chatList.data.message_list
|
|
134
|
-
.sort((a, b) => a.timestamp - b.timestamp)
|
|
135
|
-
.map(
|
|
134
|
+
.sort((a, b) => a.timestamp - b.timestamp)
|
|
135
|
+
.map(item => {
|
|
136
|
+
return convertApiMessageToUiMessage(item, 'basic');
|
|
137
|
+
});
|
|
136
138
|
setMessages(uiMessages);
|
|
137
139
|
consoleFn('[DaeryuntalkContext] 메시지 설정 완료:', uiMessages.length);
|
|
138
140
|
}
|
|
@@ -221,9 +223,10 @@ export const useChatHandler = ({
|
|
|
221
223
|
// 메세지 리스트 후처리
|
|
222
224
|
if (chatList.data.message_list.length > 0) {
|
|
223
225
|
const uiMessages = chatList.data.message_list
|
|
224
|
-
.sort((a, b) => a.timestamp - b.timestamp)
|
|
225
|
-
.map(
|
|
226
|
-
|
|
226
|
+
.sort((a, b) => a.timestamp - b.timestamp)
|
|
227
|
+
.map(item => {
|
|
228
|
+
return convertApiMessageToUiMessage(item, 'basic');
|
|
229
|
+
});
|
|
227
230
|
|
|
228
231
|
// const uiMessages = chatList.data.message_list.map(convertApiMessageToUiMessage);
|
|
229
232
|
setMessages(uiMessages);
|
|
@@ -343,8 +346,10 @@ export const useChatHandler = ({
|
|
|
343
346
|
// 메세지 리스트 후처리
|
|
344
347
|
if (chatList.data?.message_list && chatList.data.message_list.length > 0) {
|
|
345
348
|
const uiMessages = chatList.data.message_list
|
|
346
|
-
.sort((a, b) =>
|
|
347
|
-
.map(
|
|
349
|
+
.sort((a, b) => a.timestamp - b.timestamp)
|
|
350
|
+
.map(item => {
|
|
351
|
+
return convertApiMessageToUiMessage(item, 'basic');
|
|
352
|
+
});
|
|
348
353
|
setMessages(uiMessages);
|
|
349
354
|
consoleFn('[DaeryuntalkContext] 메시지 설정 완료:', uiMessages.length);
|
|
350
355
|
}
|
|
@@ -490,23 +495,28 @@ export const useChatHandler = ({
|
|
|
490
495
|
[]
|
|
491
496
|
);
|
|
492
497
|
|
|
493
|
-
|
|
498
|
+
// 무한스크롤 실행
|
|
499
|
+
const getNextMessageList = useCallback(async (chatInquiryNumber: string, standardTimestamp: number) => {
|
|
494
500
|
try {
|
|
495
|
-
const response = await getChatInquiryMessageList(chatInquiryNumber,
|
|
501
|
+
const response = await getChatInquiryMessageList(chatInquiryNumber, standardTimestamp);
|
|
502
|
+
|
|
496
503
|
if (response.result_info.result_cd === 'OK' || response.result_info.result_type_cd === 'OK') {
|
|
497
|
-
// 앞에 생성될 여기서는 앞에서부터 채워야함
|
|
498
504
|
const newMessageList = response.data.message_list
|
|
499
505
|
.sort((a, b) => a.timestamp - b.timestamp)
|
|
500
|
-
.map(item =>
|
|
501
|
-
|
|
502
|
-
});
|
|
506
|
+
.map(item => convertApiMessageToUiMessage(item, 'prev'));
|
|
507
|
+
|
|
503
508
|
setIsNextPage(response.data.next_page_yn);
|
|
509
|
+
|
|
504
510
|
setMessages(prev => {
|
|
505
|
-
if (newMessageList
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
511
|
+
if (!newMessageList || newMessageList.length === 0) return prev;
|
|
512
|
+
|
|
513
|
+
const existingMessageNumbers = new Set(prev.map(msg => msg.messageNumber));
|
|
514
|
+
|
|
515
|
+
const filteredNewMessages = newMessageList.filter(
|
|
516
|
+
msg => !existingMessageNumbers.has(msg.messageNumber)
|
|
517
|
+
);
|
|
518
|
+
|
|
519
|
+
return [...filteredNewMessages, ...prev];
|
|
510
520
|
});
|
|
511
521
|
} else {
|
|
512
522
|
toast.error(getErrorMessageMap(response));
|
|
@@ -514,7 +524,6 @@ export const useChatHandler = ({
|
|
|
514
524
|
}
|
|
515
525
|
} catch (error: any) {
|
|
516
526
|
console.error(`[실패]:`, error);
|
|
517
|
-
// toast.error(error?.message || '오류가 발생했습니다.');
|
|
518
527
|
}
|
|
519
528
|
}, []);
|
|
520
529
|
|
|
@@ -168,7 +168,7 @@ export const useSocketEventHandler = ({ setIsConnected, setIsLoading, setMessage
|
|
|
168
168
|
consoleFn('socket data', data);
|
|
169
169
|
// 메시지 생성
|
|
170
170
|
if (data.type === MessageSocketType.MESSAGE_CREATED && ((_a = data.payload) === null || _a === void 0 ? void 0 : _a.message)) {
|
|
171
|
-
const newMessage = convertApiMessageToUiMessage(data.payload.message);
|
|
171
|
+
const newMessage = convertApiMessageToUiMessage(data.payload.message, 'live');
|
|
172
172
|
setMessages(prev => {
|
|
173
173
|
const isDuplicate = prev.some(msg => msg.messageNumber === newMessage.messageNumber);
|
|
174
174
|
return isDuplicate ? prev : [...prev, newMessage];
|
|
@@ -176,7 +176,7 @@ export const useSocketEventHandler = ({ setIsConnected, setIsLoading, setMessage
|
|
|
176
176
|
closeTyping();
|
|
177
177
|
}
|
|
178
178
|
if (data.type === MessageSocketType.MESSAGE_UPDATED) {
|
|
179
|
-
const newMessage = convertApiMessageToUiMessage(data.payload.message);
|
|
179
|
+
const newMessage = convertApiMessageToUiMessage(data.payload.message, 'basic');
|
|
180
180
|
setMessages(prev => {
|
|
181
181
|
const index = prev.findIndex(msg => msg.messageNumber === newMessage.messageNumber);
|
|
182
182
|
if (index !== -1) {
|
|
@@ -241,7 +241,7 @@ export const useSocketEventHandler = ({
|
|
|
241
241
|
consoleFn('socket data', data);
|
|
242
242
|
// 메시지 생성
|
|
243
243
|
if (data.type === MessageSocketType.MESSAGE_CREATED && data.payload?.message) {
|
|
244
|
-
const newMessage = convertApiMessageToUiMessage(data.payload.message);
|
|
244
|
+
const newMessage = convertApiMessageToUiMessage(data.payload.message, 'live');
|
|
245
245
|
setMessages(prev => {
|
|
246
246
|
const isDuplicate = prev.some(
|
|
247
247
|
msg => msg.messageNumber === newMessage.messageNumber
|
|
@@ -252,7 +252,7 @@ export const useSocketEventHandler = ({
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
if (data.type === MessageSocketType.MESSAGE_UPDATED) {
|
|
255
|
-
const newMessage = convertApiMessageToUiMessage(data.payload.message);
|
|
255
|
+
const newMessage = convertApiMessageToUiMessage(data.payload.message, 'basic');
|
|
256
256
|
setMessages(prev => {
|
|
257
257
|
const index = prev.findIndex(msg => msg.messageNumber === newMessage.messageNumber);
|
|
258
258
|
|
|
@@ -2,6 +2,6 @@ import { ChatInquiryDetailDataResponse, ChatMessage as ApiChatMessage } from '..
|
|
|
2
2
|
import { Message } from '../_types/message';
|
|
3
3
|
import { MessageObject } from '../_types/message_object';
|
|
4
4
|
import { IInquiryWorkFlowUpdate } from '../_types/socket/workflow';
|
|
5
|
-
export declare const convertApiMessageToUiMessage: (apiMessage: ApiChatMessage) => Message;
|
|
5
|
+
export declare const convertApiMessageToUiMessage: (apiMessage: ApiChatMessage, type: "live" | "basic" | "prev") => Message;
|
|
6
6
|
export declare const convertApiMessageObjectToUiMessageObject: (apiObject: ChatInquiryDetailDataResponse) => MessageObject;
|
|
7
7
|
export declare const convertSocketObjectToUiMessage: (obj: IInquiryWorkFlowUpdate) => MessageObject;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const convertApiMessageToUiMessage = (apiMessage) => {
|
|
1
|
+
export const convertApiMessageToUiMessage = (apiMessage, type) => {
|
|
2
2
|
var _a, _b, _c;
|
|
3
|
-
const result = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ messageNumber: apiMessage.message_number, plainText: apiMessage.plain_text,
|
|
3
|
+
const result = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ type: type, messageNumber: apiMessage.message_number, plainText: apiMessage.plain_text,
|
|
4
4
|
// API에서 오는 모든 필드들
|
|
5
5
|
senderType: apiMessage.sender_type, messageType: apiMessage.message_type, messageStatus: apiMessage.message_status, userKey: apiMessage.user_key, inquiryNumber: apiMessage.inquiry_number, templateType: apiMessage.template_type, createdAt: new Date(apiMessage.created_at), updatedAt: apiMessage.updated_at ? new Date(apiMessage.updated_at) : undefined, language: apiMessage.language, timestamp: apiMessage.timestamp }, (apiMessage.rich_text && {
|
|
6
6
|
richText: {
|
|
@@ -7,8 +7,9 @@ import { FormInput, FormInputType, Message } from '../_types/message';
|
|
|
7
7
|
import { MessageObject } from '../_types/message_object';
|
|
8
8
|
import { IInquiryWorkFlowUpdate } from '../_types/socket/workflow';
|
|
9
9
|
|
|
10
|
-
export const convertApiMessageToUiMessage = (apiMessage: ApiChatMessage): Message => {
|
|
10
|
+
export const convertApiMessageToUiMessage = (apiMessage: ApiChatMessage, type: 'live' | 'basic' | 'prev'): Message => {
|
|
11
11
|
const result: Message = {
|
|
12
|
+
type: type,
|
|
12
13
|
messageNumber: apiMessage.message_number,
|
|
13
14
|
plainText: apiMessage.plain_text,
|
|
14
15
|
|
|
@@ -78,6 +78,7 @@ export interface Message {
|
|
|
78
78
|
userType?: string;
|
|
79
79
|
isBot?: boolean;
|
|
80
80
|
isAPIMessage?: boolean;
|
|
81
|
+
type: 'live' | 'basic' | 'prev';
|
|
81
82
|
}
|
|
82
83
|
export declare const hasBlocks: (message: Message) => boolean;
|
|
83
84
|
export declare const hasRichForm: (message: Message) => boolean;
|
|
@@ -119,6 +119,9 @@ export interface Message {
|
|
|
119
119
|
|
|
120
120
|
// 임시 메시지 구분용
|
|
121
121
|
isAPIMessage?: boolean; // 임시 메시지 여부 (웹소켓 응답 전)
|
|
122
|
+
|
|
123
|
+
// 실시간 메시지인지 확인요
|
|
124
|
+
type: 'live' | 'basic' | 'prev'; // live : 소켓 , basic : 최초 API , prev : 무한스크롤
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
// 메시지에 특정 컨텐츠가 있는지 확인하는 헬퍼 함수들
|