@smart-link/rn-im 1.0.24 → 1.0.26

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.
Files changed (40) hide show
  1. package/assets/file-dir.jpg +0 -0
  2. package/dist/components/ChatAvatar/ChatAvatarLocal.js +0 -1
  3. package/dist/default-assets.d.ts +1 -0
  4. package/dist/default-assets.js +1 -0
  5. package/dist/interface.d.ts +9 -0
  6. package/dist/pages/conversation/setting/OptionAvatars.d.ts +1 -1
  7. package/dist/pages/conversation/setting/OptionGroup.d.ts +1 -1
  8. package/dist/pages/conversation/setting/Setting.js +2 -3
  9. package/dist/pages/message/FileSelector.d.ts +6 -0
  10. package/dist/pages/message/FileSelector.js +235 -0
  11. package/dist/pages/message/MessageList.js +19 -15
  12. package/dist/pages/message/MessageRecord.js +33 -22
  13. package/dist/pages/message/components/MessageItem.d.ts +2 -1
  14. package/dist/pages/message/components/MessageItem.js +6 -5
  15. package/dist/pages/message/components/MessageOption.d.ts +7 -3
  16. package/dist/pages/message/components/MessageOption.js +13 -16
  17. package/dist/pages/message/components/MessagePayload.d.ts +2 -1
  18. package/dist/pages/message/components/Payload/PayloadFile.d.ts +1 -1
  19. package/dist/pages/message/components/Payload/PayloadFile.js +11 -11
  20. package/dist/pages/message/components/Payload/PayloadMultiple.js +9 -5
  21. package/dist/pages/message/components/Payload/PayloadPicture.d.ts +1 -1
  22. package/dist/pages/message/components/Payload/PayloadPicture.js +3 -4
  23. package/dist/pages/message/components/Payload/PayloadVideo.js +2 -1
  24. package/dist/pages/message/components/Payload/PayloadVoice.js +1 -1
  25. package/dist/pages/message/components/Payload/PayloadWrapper.d.ts +2 -1
  26. package/dist/pages/message/components/Payload/PayloadWrapper.js +8 -3
  27. package/dist/pages/message/components/Payload/type.d.ts +2 -1
  28. package/dist/pages/message/components/ReceiptBack.js +2 -2
  29. package/dist/pages/message/components/TextMixQuote.js +7 -12
  30. package/dist/pages/message/components/TextMixQuoteMessage.js +3 -3
  31. package/dist/pages/message/components/messageBar/OptionPanel.js +6 -31
  32. package/dist/pages/message/message.routes.js +10 -0
  33. package/dist/pages/types.d.ts +4 -2
  34. package/dist/slice/video/video.action.js +9 -1
  35. package/dist/utils/file.d.ts +10 -2
  36. package/dist/utils/file.js +140 -27
  37. package/dist/utils/upload.js +1 -1
  38. package/package.json +2 -2
  39. package/dist/slice/contact/contact.action.d.ts +0 -1
  40. package/dist/slice/contact/contact.action.js +0 -1
@@ -13,7 +13,6 @@ import { getCookieString } from './cookie';
13
13
  import { getDownloadUrl } from '../api/file';
14
14
  import { uuidv4 } from 'react-native-compressor';
15
15
  import { PermissionsAndroid, Platform } from 'react-native';
16
- import { throttle } from "lodash-es";
17
16
  const documentPath = RNFS.DocumentDirectoryPath;
18
17
  const resourceDirBase = {
19
18
  avatars: '/avatars',
@@ -47,7 +46,7 @@ export function toAbsolutePath(filePath) {
47
46
  if (filePath.startsWith('file://')) {
48
47
  return filePath;
49
48
  }
50
- return 'file://' + filePath;
49
+ return 'file://' + documentPath + filePath;
51
50
  }
52
51
  export function toRelativePath(filePath) {
53
52
  if (filePath.startsWith(documentPath)) {
@@ -86,25 +85,27 @@ export const getSuffix = (filename) => {
86
85
  const index = filename.lastIndexOf('.');
87
86
  return filename.substring(index);
88
87
  };
89
- export const download = ({ fileId, fileSize, resourceType, filename, onProgress, onStart }) => __awaiter(void 0, void 0, void 0, function* () {
88
+ export const download = ({ fileId, resourceType, filename, onProgress, onStart }) => __awaiter(void 0, void 0, void 0, function* () {
90
89
  const cookie = yield getCookieString();
91
90
  const fileUrl = getDownloadUrl(fileId);
92
91
  console.log('download url: ', fileUrl);
93
- const throttledFn = throttle((o) => {
94
- onProgress === null || onProgress === void 0 ? void 0 : onProgress(o);
95
- }, 500);
96
- // if (Platform.OS === 'android') {
97
- const destPath = RNFS.DocumentDirectoryPath + resourceDir[resourceType] + '/' + fileId + getSuffix(filename);
92
+ const relativePath = resourceDir[resourceType] + "/" + filename;
93
+ const destPath = documentPath + relativePath;
98
94
  const { jobId, promise } = RNFS.downloadFile({
99
95
  fromUrl: fileUrl,
100
96
  toFile: destPath,
101
97
  headers: {
102
98
  'Cookie': cookie,
103
99
  },
104
- background: true,
100
+ progressInterval: 300,
101
+ progressDivider: 5,
102
+ begin: (e) => {
103
+ // 这个方法不能注释,否则 ios 不响应进度
104
+ // console.log('download begin: ', e);
105
+ },
105
106
  progress: (e) => {
106
107
  // console.log('download progress: ', e);
107
- throttledFn({ loaded: e.bytesWritten, total: e.contentLength });
108
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({ loaded: e.bytesWritten, total: e.contentLength, jobId });
108
109
  }
109
110
  });
110
111
  onStart === null || onStart === void 0 ? void 0 : onStart(() => {
@@ -112,28 +113,12 @@ export const download = ({ fileId, fileSize, resourceType, filename, onProgress,
112
113
  });
113
114
  try {
114
115
  yield promise;
115
- console.log('下载完成');
116
- return destPath;
116
+ return relativePath;
117
117
  }
118
118
  catch (error) {
119
119
  console.error('下载失败:', error);
120
120
  throw error;
121
121
  }
122
- // } else {
123
- // const resp = await fetch(fileUrl, {
124
- // method: 'HEAD',
125
- // })
126
- // if (resp.status !== 200) {
127
- // console.error('下载失败:', resp.status);
128
- // throw new Error('下载失败');
129
- // }
130
- // const contentLength = resp.headers.get('Content-Length') || fileSize;
131
- // const result = await CompressDownload(fileUrl, (progress) => {
132
- // // console.log('download progress: ', progress);
133
- // throttledFn({loaded: progress * Number(contentLength), total: Number(contentLength)});
134
- // })
135
- // return await moveFile(result, filename, resourceType)
136
- // }
137
122
  });
138
123
  export function saveToAlbum(imManager, localPath, showTips = true) {
139
124
  var _a, _b;
@@ -245,3 +230,131 @@ const extensions = {
245
230
  export function getExtensionFromMime(mime) {
246
231
  return extensions[mime] || '';
247
232
  }
233
+ export function selectFile(imManager, filePath, filename) {
234
+ return __awaiter(this, void 0, void 0, function* () {
235
+ const success = yield requestSaveFilePermissionIfAndroid(imManager);
236
+ console.log("获取写入内存的权限", success);
237
+ if (!success) {
238
+ return;
239
+ }
240
+ let relativePath;
241
+ if (filePath.indexOf(documentPath) >= 0) {
242
+ return filePath.replace(documentPath, '');
243
+ }
244
+ relativePath = resourceDir.file + "/" + filename;
245
+ const destPath = documentPath + relativePath;
246
+ console.log('destPath: ', filePath, destPath);
247
+ if (yield RNFS.exists(destPath)) {
248
+ return destPath;
249
+ }
250
+ yield RNFS.copyFile(filePath, destPath);
251
+ return relativePath;
252
+ });
253
+ }
254
+ function filterUserPath(imManager, path, items = []) {
255
+ if (path !== userPath) {
256
+ return items;
257
+ }
258
+ return items.filter(item => {
259
+ switch (item.path) {
260
+ case userPath + resourceDirBase.file:
261
+ item.name = imManager.t('file');
262
+ return true;
263
+ case userPath + resourceDirBase.video:
264
+ item.name = imManager.t('video');
265
+ return true;
266
+ case userPath + resourceDirBase.picture:
267
+ item.name = imManager.t('picture');
268
+ return true;
269
+ default:
270
+ return false;
271
+ }
272
+ });
273
+ }
274
+ function filterThumbPicture(imManager, path, items) {
275
+ if (path !== userPath + resourceDirBase.video) {
276
+ return items;
277
+ }
278
+ return items.filter(item => {
279
+ if (getFileType(item.path) === 'jpg') {
280
+ return false;
281
+ }
282
+ let thumbPath = item.path.replace('video_', 'thumb_');
283
+ thumbPath = thumbPath.substring(0, thumbPath.lastIndexOf('.'));
284
+ thumbPath = thumbPath + '.jpg';
285
+ item.thumbPath = thumbPath;
286
+ return true;
287
+ });
288
+ }
289
+ export function readFileDir(imManager, path, keyword = '') {
290
+ return __awaiter(this, void 0, void 0, function* () {
291
+ let items = yield RNFS.readDir(path);
292
+ items = filterUserPath(imManager, path, items);
293
+ items = filterThumbPicture(imManager, path, items);
294
+ const list = [];
295
+ for (let i = 0; i < items.length; i++) {
296
+ const item = items[i];
297
+ const mapItem = {
298
+ name: item.name,
299
+ time: item.mtime.getTime(),
300
+ isDir: item.isDirectory(),
301
+ path: item.path,
302
+ size: item.size,
303
+ thumbPath: item.thumbPath,
304
+ };
305
+ mapItem.childrenCount = yield getChildrenCount(imManager, item.isDirectory(), item.path);
306
+ list.push(mapItem);
307
+ }
308
+ if (keyword === '') {
309
+ return list;
310
+ }
311
+ else {
312
+ return list.filter(item => item.name.indexOf(keyword) >= 0);
313
+ }
314
+ });
315
+ }
316
+ export function getChildrenCount(imManager, isDir, path) {
317
+ return __awaiter(this, void 0, void 0, function* () {
318
+ if (!isDir) {
319
+ return 0;
320
+ }
321
+ let children = yield RNFS.readDir(path);
322
+ children = filterUserPath(imManager, path, children);
323
+ children = filterThumbPicture(imManager, path, children);
324
+ return children.length;
325
+ });
326
+ }
327
+ export function getFileRootItem(imManager) {
328
+ return __awaiter(this, void 0, void 0, function* () {
329
+ const rootList = [];
330
+ if (Platform.OS === 'android') {
331
+ const item = yield createRootItem(imManager, imManager.t('storage'), '/storage/emulated/0');
332
+ rootList.push(item);
333
+ }
334
+ const item = yield createRootItem(imManager, imManager.t('user'), userPath);
335
+ rootList.push(item);
336
+ return rootList;
337
+ });
338
+ }
339
+ export function createRootItem(imManager, name, path) {
340
+ return __awaiter(this, void 0, void 0, function* () {
341
+ let item = {
342
+ name,
343
+ isDir: true,
344
+ path,
345
+ };
346
+ item.childrenCount = yield getChildrenCount(imManager, true, path);
347
+ return item;
348
+ });
349
+ }
350
+ export function getFileType(path) {
351
+ if (path.lastIndexOf('.') === -1) {
352
+ return '';
353
+ }
354
+ return path.slice(path.lastIndexOf('.') + 1);
355
+ }
356
+ export function isImage(path) {
357
+ const imageTypes = ['jpg', 'jpeg', 'gif', 'bmp', 'png', 'webp'];
358
+ const fileType = getFileType(path);
359
+ return imageTypes.includes(fileType);
360
+ }
@@ -21,7 +21,7 @@ const uploadFile = (filePath, type, onProgress) => __awaiter(void 0, void 0, voi
21
21
  onProgress === null || onProgress === void 0 ? void 0 : onProgress(o);
22
22
  }, 500);
23
23
  if (Platform.OS === 'android') {
24
- const resp = yield backgroundUpload(uploadUrl, filePath, {
24
+ const resp = yield backgroundUpload(uploadUrl, toAbsolutePath(filePath), {
25
25
  httpMethod: 'POST',
26
26
  uploadType: UploadType.MULTIPART,
27
27
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-link/rn-im",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "dependencies": {
@@ -63,7 +63,7 @@
63
63
  "redux": "^4.2.1",
64
64
  "redux-thunk": "^2.4.2",
65
65
  "@smart-link/rn-ui": "^1.0.6",
66
- "@smart-link/im-base": "^1.0.24"
66
+ "@smart-link/im-base": "^1.0.26"
67
67
  },
68
68
  "files": [
69
69
  "dist/**",
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};