@droppii-org/chat-sdk 0.0.22 → 0.0.23
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/components/message/footer/ActionBar.d.ts.map +1 -1
- package/dist/components/message/footer/ActionBar.js +7 -5
- package/dist/components/message/footer/FilePreview.d.ts.map +1 -1
- package/dist/components/message/footer/FilePreview.js +3 -3
- package/dist/components/message/item/ImageMessage.js +1 -1
- package/dist/components/message/item/VideoMessage.js +1 -1
- package/dist/hooks/message/useSendMessage.d.ts.map +1 -1
- package/dist/hooks/message/useSendMessage.js +57 -43
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionBar.d.ts","sourceRoot":"","sources":["../../../../src/components/message/footer/ActionBar.tsx"],"names":[],"mappings":"AAgEA,QAAA,MAAM,SAAS,+
|
|
1
|
+
{"version":3,"file":"ActionBar.d.ts","sourceRoot":"","sources":["../../../../src/components/message/footer/ActionBar.tsx"],"names":[],"mappings":"AAgEA,QAAA,MAAM,SAAS,+CAiOd,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -109,22 +109,24 @@ const ActionBar = () => {
|
|
|
109
109
|
return Upload.LIST_IGNORE;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
return
|
|
112
|
+
return false;
|
|
113
113
|
};
|
|
114
114
|
const beforeUploadFile = (file) => {
|
|
115
115
|
const isAllowed = documentTypes.includes(file.type);
|
|
116
116
|
if (!isAllowed) {
|
|
117
117
|
message.error(`${file.name} không đúng định dạng (chỉ hỗ trợ PDF, DOC, DOCX)`);
|
|
118
|
+
return Upload.LIST_IGNORE;
|
|
118
119
|
}
|
|
119
|
-
return
|
|
120
|
+
return false;
|
|
120
121
|
};
|
|
121
122
|
const handleChange = (info) => {
|
|
123
|
+
var _a;
|
|
122
124
|
let newList = [...info.fileList];
|
|
123
|
-
// Nếu file mới là tài liệu -> chỉ giữ 1 cái (file cuối)
|
|
124
125
|
const lastFile = info.file;
|
|
125
126
|
if (documentTypes.includes(lastFile.type || "")) {
|
|
126
|
-
newList = newList.filter((f) => documentTypes.includes(f.type || "")
|
|
127
|
-
|
|
127
|
+
newList = newList.filter((f) => !documentTypes.includes(f.type || ""));
|
|
128
|
+
const originFile = ((_a = lastFile.originFileObj) !== null && _a !== void 0 ? _a : lastFile);
|
|
129
|
+
newList.push(Object.assign(Object.assign({}, lastFile), { originFileObj: originFile }));
|
|
128
130
|
}
|
|
129
131
|
setListUploadFiles(newList);
|
|
130
132
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilePreview.d.ts","sourceRoot":"","sources":["../../../../src/components/message/footer/FilePreview.tsx"],"names":[],"mappings":"AAYA,eAAO,MAAM,YAAY,yCAoCxB,CAAC;AAEF,UAAU,cAAc;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,UAAS,cAAmB,WAkBzE,CAAC;AAEF,QAAA,MAAM,WAAW,+
|
|
1
|
+
{"version":3,"file":"FilePreview.d.ts","sourceRoot":"","sources":["../../../../src/components/message/footer/FilePreview.tsx"],"names":[],"mappings":"AAYA,eAAO,MAAM,YAAY,yCAoCxB,CAAC;AAEF,UAAU,cAAc;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,UAAS,cAAmB,WAkBzE,CAAC;AAEF,QAAA,MAAM,WAAW,+CAkFhB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -31,9 +31,9 @@ const FilePreview = () => {
|
|
|
31
31
|
setListUploadFiles(listUploadFiles.filter((f) => f.uid !== file.uid));
|
|
32
32
|
};
|
|
33
33
|
const renderFilePreview = useCallback((file) => {
|
|
34
|
-
var _a;
|
|
35
|
-
const isDocument = documentTypes.includes(file.type || "");
|
|
36
|
-
const isVideo = (
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const isDocument = documentTypes.includes(((_a = file === null || file === void 0 ? void 0 : file.originFileObj) === null || _a === void 0 ? void 0 : _a.type) || "");
|
|
36
|
+
const isVideo = (_b = file.type) === null || _b === void 0 ? void 0 : _b.startsWith("video/");
|
|
37
37
|
let src = file.url;
|
|
38
38
|
if (!src && file.originFileObj) {
|
|
39
39
|
src = URL.createObjectURL(file.originFileObj);
|
|
@@ -18,6 +18,6 @@ const ImageMessageItem = (props) => {
|
|
|
18
18
|
minHeight: `${adaptedHight}px`,
|
|
19
19
|
minWidth: `${adaptedWidth}px`,
|
|
20
20
|
};
|
|
21
|
-
return (_jsx(Spin, { spinning: isSending, children: _jsx("div", { className: "relative max-w-[200px]", style: minStyle, children: _jsx(Image, { rootClassName: "message-image cursor-pointer", className: "
|
|
21
|
+
return (_jsx(Spin, { spinning: isSending, children: _jsx("div", { className: "relative max-w-[200px]", style: minStyle, children: _jsx(Image, { rootClassName: "message-image cursor-pointer", className: "rounded-md", src: sourceUrl, preview: true, placeholder: _jsx("div", { style: minStyle, className: "flex items-center justify-center", children: _jsx(Spin, {}) }) }) }) }));
|
|
22
22
|
};
|
|
23
23
|
export default ImageMessageItem;
|
|
@@ -15,6 +15,6 @@ const VideoMessageItem = (props) => {
|
|
|
15
15
|
minHeight: `${adaptedHight}px`,
|
|
16
16
|
minWidth: `${adaptedWidth}px`,
|
|
17
17
|
};
|
|
18
|
-
return (_jsx(Spin, { spinning: isSending, children: _jsx("div", { className: "relative max-w-[200px]", style: minStyle, children: _jsx("video", { className: "
|
|
18
|
+
return (_jsx(Spin, { spinning: isSending, children: _jsx("div", { className: "relative max-w-[200px]", style: minStyle, children: _jsx("video", { className: "rounded-md", src: sourceUrl, controls: true }) }) }));
|
|
19
19
|
};
|
|
20
20
|
export default VideoMessageItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSendMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useSendMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAQ1B,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC,eAAO,MAAM,iBAAiB,GAAU,MAAM,MAAM,gCAanD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,MAAM,oBAAoB,gCAaxE,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAU,iBAAiB,eAAe,gCAazE,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,MAAM,oBAAoB,gCAaxE,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAU,MAAM,mBAAmB,gCAatE,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,cAAc,WAAW;gDAiCjD;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB;wDAwBE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,UAAU,EAAE,CAAC;KACrB;
|
|
1
|
+
{"version":3,"file":"useSendMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/message/useSendMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,WAAW,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAQ1B,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC,eAAO,MAAM,iBAAiB,GAAU,MAAM,MAAM,gCAanD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,MAAM,oBAAoB,gCAaxE,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAU,iBAAiB,eAAe,gCAazE,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,MAAM,oBAAoB,gCAaxE,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAU,MAAM,mBAAmB,gCAatE,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,cAAc,WAAW;gDAiCjD;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB;wDAwBE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,UAAU,EAAE,CAAC;KACrB;CAwIJ,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,2CAIvC;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,KAmBM,iBACN,CAAC"}
|
|
@@ -109,17 +109,31 @@ export const useSendMessage = (lastMessage) => {
|
|
|
109
109
|
try {
|
|
110
110
|
if (isImage) {
|
|
111
111
|
const picInfo = await createPicBaseInfoFromFile(file);
|
|
112
|
+
const baseInfo = {
|
|
113
|
+
uuid: uuidv4(),
|
|
114
|
+
type: file.type,
|
|
115
|
+
size: file.size,
|
|
116
|
+
width: picInfo.width,
|
|
117
|
+
height: picInfo.height,
|
|
118
|
+
url: URL.createObjectURL(file),
|
|
119
|
+
};
|
|
112
120
|
const parsedImage = {
|
|
113
|
-
sourcePicture:
|
|
114
|
-
bigPicture:
|
|
115
|
-
snapshotPicture:
|
|
121
|
+
sourcePicture: baseInfo,
|
|
122
|
+
bigPicture: baseInfo,
|
|
123
|
+
snapshotPicture: baseInfo,
|
|
116
124
|
sourcePath: "",
|
|
117
125
|
file: file,
|
|
118
126
|
};
|
|
119
127
|
const imageMessage = await createImageMessageByFile(parsedImage);
|
|
120
128
|
if (!imageMessage)
|
|
121
129
|
continue;
|
|
122
|
-
|
|
130
|
+
const extendMessageInfo = generateExtendMessageInfo({
|
|
131
|
+
currentUserID: (user === null || user === void 0 ? void 0 : user.userID) || "",
|
|
132
|
+
lastMessage: messageList.length > 0
|
|
133
|
+
? messageList[messageList.length - 1]
|
|
134
|
+
: lastMessage,
|
|
135
|
+
});
|
|
136
|
+
messageList.push(Object.assign(Object.assign({}, imageMessage), { ex: JSON.stringify(extendMessageInfo) || "{}" }));
|
|
123
137
|
}
|
|
124
138
|
else if (isVideo) {
|
|
125
139
|
const videoBaseInfo = await createVideoBaseInfoFromFile(file);
|
|
@@ -142,7 +156,13 @@ export const useSendMessage = (lastMessage) => {
|
|
|
142
156
|
});
|
|
143
157
|
if (!videoMessage)
|
|
144
158
|
continue;
|
|
145
|
-
|
|
159
|
+
const extendMessageInfo = generateExtendMessageInfo({
|
|
160
|
+
currentUserID: (user === null || user === void 0 ? void 0 : user.userID) || "",
|
|
161
|
+
lastMessage: messageList.length > 0
|
|
162
|
+
? messageList[messageList.length - 1]
|
|
163
|
+
: lastMessage,
|
|
164
|
+
});
|
|
165
|
+
messageList.push(Object.assign(Object.assign({}, videoMessage), { ex: JSON.stringify(extendMessageInfo) || "{}" }));
|
|
146
166
|
}
|
|
147
167
|
else if (isDocument) {
|
|
148
168
|
const fileMessage = await createFileMessageByFile({
|
|
@@ -156,28 +176,36 @@ export const useSendMessage = (lastMessage) => {
|
|
|
156
176
|
});
|
|
157
177
|
if (!fileMessage)
|
|
158
178
|
continue;
|
|
159
|
-
|
|
179
|
+
const extendMessageInfo = generateExtendMessageInfo({
|
|
180
|
+
currentUserID: (user === null || user === void 0 ? void 0 : user.userID) || "",
|
|
181
|
+
lastMessage: messageList.length > 0
|
|
182
|
+
? messageList[messageList.length - 1]
|
|
183
|
+
: lastMessage,
|
|
184
|
+
});
|
|
185
|
+
messageList.push(Object.assign(Object.assign({}, fileMessage), { ex: JSON.stringify(extendMessageInfo) || "{}" }));
|
|
160
186
|
}
|
|
161
187
|
}
|
|
162
188
|
catch (err) {
|
|
163
189
|
console.error("Lỗi xử lý tin nhắn:", err);
|
|
164
190
|
}
|
|
165
191
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
192
|
+
if (!!plainText && plainText.trim() !== "") {
|
|
193
|
+
const extendMessageInfo = generateExtendMessageInfo({
|
|
194
|
+
richText,
|
|
195
|
+
currentUserID: (user === null || user === void 0 ? void 0 : user.userID) || "",
|
|
196
|
+
lastMessage: messageList.length > 0
|
|
197
|
+
? messageList[messageList.length - 1]
|
|
198
|
+
: lastMessage,
|
|
199
|
+
});
|
|
200
|
+
const textMessage = await createTextMessage(plainText);
|
|
201
|
+
if (!textMessage)
|
|
202
|
+
return;
|
|
203
|
+
const messageItem = Object.assign(Object.assign({}, textMessage), { ex: JSON.stringify(extendMessageInfo) || "{}" });
|
|
204
|
+
messageList.push(messageItem);
|
|
205
|
+
}
|
|
206
|
+
for (const message of messageList) {
|
|
207
|
+
await sendMessage(message);
|
|
208
|
+
}
|
|
181
209
|
}, [recvID, groupID, lastMessage, sendMessage]);
|
|
182
210
|
return {
|
|
183
211
|
sendTextMessage,
|
|
@@ -201,28 +229,14 @@ export const generateExtendMessageInfo = ({ richText, currentUserID, lastMessage
|
|
|
201
229
|
},
|
|
202
230
|
};
|
|
203
231
|
};
|
|
204
|
-
const createPicBaseInfoFromFile = (file
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
img
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
type: file.type,
|
|
213
|
-
size: file.size,
|
|
214
|
-
width: img.width,
|
|
215
|
-
height: img.height,
|
|
216
|
-
url: url, // để trống nếu không cần dùng
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
img.onerror = (err) => {
|
|
220
|
-
URL.revokeObjectURL(objectUrl);
|
|
221
|
-
reject(err);
|
|
222
|
-
};
|
|
223
|
-
img.src = objectUrl;
|
|
224
|
-
});
|
|
225
|
-
};
|
|
232
|
+
const createPicBaseInfoFromFile = (file) => new Promise((resolve, reject) => {
|
|
233
|
+
const _URL = window.URL || window.webkitURL;
|
|
234
|
+
const img = new Image();
|
|
235
|
+
img.onload = function () {
|
|
236
|
+
resolve(img);
|
|
237
|
+
};
|
|
238
|
+
img.src = _URL.createObjectURL(file);
|
|
239
|
+
});
|
|
226
240
|
function createVideoBaseInfoFromFile(file) {
|
|
227
241
|
return new Promise((resolve, reject) => {
|
|
228
242
|
try {
|