@cometchat/chat-uikit-react-native 5.5.4 → 5.6.0
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/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
- package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
- package/ios/CCLocalFileGuard.h +19 -0
- package/ios/CCLocalFileGuard.m +34 -0
- package/ios/FileManager.m +70 -6
- package/ios/VideoManager.m +1 -1
- package/package.json +18 -3
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +124 -55
- package/src/CometChatConversations/CometChatConversations.tsx +240 -117
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +4 -0
- package/src/CometChatGroups/CometChatGroups.tsx +61 -52
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +146 -66
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +7 -3
- package/src/CometChatMessageHeader/listners.ts +76 -56
- package/src/CometChatMessageList/CometChatMessageList.tsx +1371 -188
- package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +71 -7
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +74 -2
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +69 -4
- package/src/CometChatSearch/CometChatSearch.tsx +353 -101
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +23 -1
- package/src/CometChatUsers/CometChatUsers.tsx +2 -0
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +19 -0
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -0
- package/src/index.ts +6 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +85 -2
- package/src/shared/CometChatUiKit/UIKitSettings.ts +20 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
- package/src/shared/events/index.ts +4 -0
- package/src/shared/events/offline.ts +28 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -3
- package/src/shared/framework/MessageDataSource.tsx +34 -14
- package/src/shared/index.ts +2 -0
- package/src/shared/offline/OfflineHub.ts +651 -0
- package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
- package/src/shared/offline/OfflineViews.tsx +218 -0
- package/src/shared/offline/conversationPins.ts +137 -0
- package/src/shared/offline/conversations.ts +325 -0
- package/src/shared/offline/frameProbe.ts +24 -0
- package/src/shared/offline/gate.ts +94 -0
- package/src/shared/offline/groupActions.ts +81 -0
- package/src/shared/offline/identity.ts +162 -0
- package/src/shared/offline/index.ts +76 -0
- package/src/shared/offline/media.ts +247 -0
- package/src/shared/offline/notices.ts +90 -0
- package/src/shared/offline/reconcile.ts +296 -0
- package/src/shared/offline/searchOutcome.ts +62 -0
- package/src/shared/offline/send.ts +430 -0
- package/src/shared/offline/stateContract.ts +85 -0
- package/src/shared/offline/threadReplies.ts +125 -0
- package/src/shared/offline/twoPhase.ts +372 -0
- package/src/shared/offline/unsentActions.ts +168 -0
- package/src/shared/offline/useOfflineMediaUri.ts +87 -0
- package/src/shared/offline/useOfflineReconnect.ts +25 -0
- package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
- package/src/shared/offline/useOfflineUploadTray.ts +76 -0
- package/src/shared/offline/usePresenceHidden.ts +33 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +24 -1
- package/src/shared/services/UploadQueueService.ts +106 -1
- package/src/shared/utils/MessageReceiptUtils.ts +8 -0
- package/src/shared/utils/SavedMessagesHelper.ts +18 -1
- package/src/shared/utils/catchUpCursor.ts +36 -0
- package/src/shared/utils/failedMessageRetry.ts +73 -0
- package/src/shared/utils/messageIdentity.ts +38 -0
- package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +34 -5
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +10 -2
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +60 -11
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +27 -2
- package/src/shared/views/CometChatList/CometChatList.tsx +468 -7
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +27 -5
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -0
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +56 -10
- package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +36 -2
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
- package/src/theme/type.ts +17 -0
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
|
@@ -47,6 +47,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
|
|
47
47
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
48
48
|
import com.facebook.react.bridge.ReactMethod;
|
|
49
49
|
import com.facebook.react.bridge.ReadableMap;
|
|
50
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
50
51
|
import com.facebook.react.bridge.WritableMap;
|
|
51
52
|
import com.facebook.react.bridge.WritableArray;
|
|
52
53
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
@@ -306,7 +307,11 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
306
307
|
if (fileName == null) {
|
|
307
308
|
fileName = String.valueOf(System.currentTimeMillis());
|
|
308
309
|
}
|
|
309
|
-
|
|
310
|
+
String safeName = SafeFileName.of(fileName);
|
|
311
|
+
if (safeName == null) {
|
|
312
|
+
throw new IOException("unsafe file name");
|
|
313
|
+
}
|
|
314
|
+
File destFile = new File(dir, safeName);
|
|
310
315
|
Uri copyPath = copyFile(context, uri, destFile);
|
|
311
316
|
map.putString(FIELD_FILE_COPY_URI, copyPath.toString());
|
|
312
317
|
} catch (Exception e) {
|
|
@@ -445,10 +450,19 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
445
450
|
}
|
|
446
451
|
|
|
447
452
|
public static void downloadFileInNewThread(Context context, String fileUrl, String fileName, String mimeType) {
|
|
448
|
-
|
|
453
|
+
String safeName = SafeFileName.of(fileName);
|
|
454
|
+
if (safeName == null) {
|
|
455
|
+
handleDownloadFailure(context);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), safeName);
|
|
449
459
|
Thread downloadThread = new Thread(() -> {
|
|
450
460
|
try {
|
|
451
|
-
if (!file.exists()) {
|
|
461
|
+
if (!file.exists() && SafeFileName.isFileUri(fileUrl)) {
|
|
462
|
+
// A file already on the device: copied only from the offline media cache, no fetch.
|
|
463
|
+
copyLocalFile(context, fileUrl, file);
|
|
464
|
+
handleDownloadSuccess(context, mimeType, file);
|
|
465
|
+
} else if (!file.exists()) {
|
|
452
466
|
URL url = new URL(fileUrl);
|
|
453
467
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
454
468
|
connection.connect();
|
|
@@ -485,6 +499,37 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
485
499
|
downloadThread.start();
|
|
486
500
|
}
|
|
487
501
|
|
|
502
|
+
/**
|
|
503
|
+
* Where the offline Chat SDK keeps media (MediaFileStore): `<dataDir>/no_backup/cometchat/media`
|
|
504
|
+
* (the folder op-sqlite reports as ANDROID_FILES_PATH, one level up, then `no_backup`), or
|
|
505
|
+
* `<files>/cometchat/media` without op-sqlite and before the SDK's one-time move to no_backup.
|
|
506
|
+
* Its database (`no_backup/databases`) and every other private file are outside both.
|
|
507
|
+
*/
|
|
508
|
+
private static File[] offlineMediaRoots(Context context) {
|
|
509
|
+
File files = context.getFilesDir();
|
|
510
|
+
return new File[] {
|
|
511
|
+
new File(files.getParentFile(), "no_backup/cometchat/media"),
|
|
512
|
+
new File(files, "cometchat/media"),
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
private static void copyLocalFile(Context context, String fileUri, File dest) throws IOException {
|
|
517
|
+
// A file:// source is the message's data: copy it only when it resolves inside the offline
|
|
518
|
+
// media cache, never any other file the app can read.
|
|
519
|
+
File source = SafeFileName.confinedLocalFile(fileUri, offlineMediaRoots(context));
|
|
520
|
+
if (source == null) {
|
|
521
|
+
throw new IOException("source is not in the offline media cache");
|
|
522
|
+
}
|
|
523
|
+
try (InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(dest)) {
|
|
524
|
+
byte[] buffer = new byte[4096];
|
|
525
|
+
int read;
|
|
526
|
+
while ((read = in.read(buffer)) != -1) {
|
|
527
|
+
out.write(buffer, 0, read);
|
|
528
|
+
}
|
|
529
|
+
out.flush();
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
488
533
|
private static void handleDownloadSuccess(Context context, String mimeType, final File file) {
|
|
489
534
|
((Activity) context).runOnUiThread(() -> {
|
|
490
535
|
shareFile(mimeType, context, file);
|
|
@@ -1805,12 +1850,31 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
1805
1850
|
@ReactMethod
|
|
1806
1851
|
public void checkAndDownload(String url, String name, Callback callback) {
|
|
1807
1852
|
try {
|
|
1853
|
+
name = SafeFileName.of(name);
|
|
1854
|
+
if (name == null) {
|
|
1855
|
+
callback.invoke("{\"success\": false, \"error\": \"Invalid file name\"}");
|
|
1856
|
+
return;
|
|
1857
|
+
}
|
|
1808
1858
|
if (fileExists(name)) {
|
|
1809
1859
|
// Already downloaded — open it and report done
|
|
1810
1860
|
openFileWithOption(name, ignored -> {});
|
|
1811
1861
|
callback.invoke("{\"success\": true, \"alreadyExists\": true}");
|
|
1812
1862
|
return;
|
|
1813
1863
|
}
|
|
1864
|
+
if (SafeFileName.isFileUri(url)) {
|
|
1865
|
+
// A file already on the device: copied into Downloads only from the offline media cache.
|
|
1866
|
+
File dest = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), name);
|
|
1867
|
+
try {
|
|
1868
|
+
copyLocalFile(getReactApplicationContext(), url, dest);
|
|
1869
|
+
} catch (IOException e) {
|
|
1870
|
+
Log.w(TAG, "checkAndDownload: refused a local file outside the offline media cache");
|
|
1871
|
+
UiThreadUtil.runOnUiThread(() -> Toast.makeText(getReactApplicationContext(), "File download failed.", Toast.LENGTH_SHORT).show());
|
|
1872
|
+
callback.invoke("{\"success\": false, \"error\": \"File is not available\"}");
|
|
1873
|
+
return;
|
|
1874
|
+
}
|
|
1875
|
+
callback.invoke("{\"success\": true, \"alreadyExists\": false}");
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1814
1878
|
Long downloadId = downloadFile(name, url);
|
|
1815
1879
|
if (downloadId == null) {
|
|
1816
1880
|
callback.invoke("{\"success\": false, \"error\": \"Download could not be started\"}");
|
|
@@ -1837,6 +1901,11 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
1837
1901
|
@ReactMethod
|
|
1838
1902
|
public void openFileWithOption(String fileName, Callback callback) {
|
|
1839
1903
|
try {
|
|
1904
|
+
fileName = SafeFileName.of(fileName);
|
|
1905
|
+
if (fileName == null) {
|
|
1906
|
+
callback.invoke("{\"success\": false, \"error\": \"Invalid file name\"}");
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1840
1909
|
// Get the Downloads directory path
|
|
1841
1910
|
File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
|
1842
1911
|
File file = new File(downloadsDir, fileName);
|
|
@@ -1910,12 +1979,18 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
1910
1979
|
}
|
|
1911
1980
|
|
|
1912
1981
|
private boolean fileExists(String fileName) {
|
|
1982
|
+
fileName = SafeFileName.of(fileName);
|
|
1983
|
+
if (fileName == null) return false;
|
|
1913
1984
|
File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName);
|
|
1914
1985
|
return f.exists();
|
|
1915
1986
|
}
|
|
1916
1987
|
|
|
1917
1988
|
private Long downloadFile(String fileName, String url){
|
|
1918
1989
|
try {
|
|
1990
|
+
fileName = SafeFileName.of(fileName);
|
|
1991
|
+
if (fileName == null) {
|
|
1992
|
+
return null;
|
|
1993
|
+
}
|
|
1919
1994
|
if (fileExists(fileName)) {
|
|
1920
1995
|
return null;
|
|
1921
1996
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
package com.reactnativecometchatuikit;
|
|
2
|
+
|
|
3
|
+
import java.io.File;
|
|
4
|
+
import java.net.URI;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Checks for the native copy and download code, kept free of Android classes so they can be unit
|
|
8
|
+
* tested on the JVM. A destination name keeps only its base name, as the Android UI Kit's share copy
|
|
9
|
+
* does (MediaViewerSource.copyForShare uses File(displayName).name). A local source must also lie
|
|
10
|
+
* inside the offline media cache ({@link #confinedLocalFile}), which is stricter than the Android
|
|
11
|
+
* UI Kit's MediaViewerSource.localFile (it only checks that the file exists).
|
|
12
|
+
*/
|
|
13
|
+
final class SafeFileName {
|
|
14
|
+
|
|
15
|
+
private SafeFileName() {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The base name of [name], so a `..` or a path separator can never leave the destination
|
|
19
|
+
* folder, or null when there is no usable name (empty, `.`, `..`, or a NUL character).
|
|
20
|
+
*/
|
|
21
|
+
static String of(String name) {
|
|
22
|
+
if (name == null || name.indexOf('\0') >= 0) return null;
|
|
23
|
+
String base = new File(name).getName();
|
|
24
|
+
if (base.isEmpty() || base.equals(".") || base.equals("..")) return null;
|
|
25
|
+
return base;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The path behind a `file://` [uri], or null for any other scheme or an empty path. */
|
|
29
|
+
static String localPath(String uri) {
|
|
30
|
+
if (uri == null) return null;
|
|
31
|
+
try {
|
|
32
|
+
URI parsed = new URI(uri);
|
|
33
|
+
if (!"file".equalsIgnoreCase(parsed.getScheme())) return null;
|
|
34
|
+
String path = parsed.getPath();
|
|
35
|
+
return path == null || path.isEmpty() ? null : path;
|
|
36
|
+
} catch (Exception e) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** True when [file] is an existing regular file that can be read. */
|
|
42
|
+
static boolean isReadableLocalFile(File file) {
|
|
43
|
+
return file != null && file.isFile() && file.canRead();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** True when [uri] has the `file` scheme, in any letter case. */
|
|
47
|
+
static boolean isFileUri(String uri) {
|
|
48
|
+
return uri != null && uri.length() > 5 && uri.regionMatches(true, 0, "file:", 0, 5);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The file behind a `file://` [uri] when it may be copied out of the app: after `..` and every
|
|
53
|
+
* symlink are resolved, it is a readable regular file strictly inside one of [roots] (the offline
|
|
54
|
+
* media cache). Anything else is null, so a message cannot name a private file of the app (its
|
|
55
|
+
* database, its storage, `/etc/hosts`) and have it copied into public storage or shared.
|
|
56
|
+
*
|
|
57
|
+
* The Android UI Kit's MediaViewerSource.localFile only checks that the file exists, so it is not
|
|
58
|
+
* the model here. The returned file is the resolved one: the caller reads exactly what was checked.
|
|
59
|
+
*/
|
|
60
|
+
static File confinedLocalFile(String uri, File... roots) {
|
|
61
|
+
String path = localPath(uri);
|
|
62
|
+
if (path == null || roots == null) return null;
|
|
63
|
+
try {
|
|
64
|
+
File source = new File(path).getCanonicalFile();
|
|
65
|
+
if (!isReadableLocalFile(source)) return null;
|
|
66
|
+
String resolved = source.getPath();
|
|
67
|
+
for (File root : roots) {
|
|
68
|
+
if (root == null) continue;
|
|
69
|
+
String base = root.getCanonicalPath();
|
|
70
|
+
if (base.isEmpty() || base.equals(File.separator)) continue;
|
|
71
|
+
if (resolved.startsWith(base + File.separator)) return source;
|
|
72
|
+
}
|
|
73
|
+
} catch (Exception e) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
/// True when `url` has the `file` scheme, in any letter case.
|
|
6
|
+
FOUNDATION_EXPORT BOOL CCUIKitIsFileURL(NSURL *_Nullable url);
|
|
7
|
+
|
|
8
|
+
/// Where the offline Chat SDK keeps media: `<Documents>/cometchat/media` (its MediaFileStore root,
|
|
9
|
+
/// under react-native-fs's DocumentDirectoryPath).
|
|
10
|
+
FOUNDATION_EXPORT NSArray<NSString *> *CCUIKitOfflineMediaRoots(void);
|
|
11
|
+
|
|
12
|
+
/// The resolved path of the file behind a `file://` `url` when it may be copied out of the app: after
|
|
13
|
+
/// `..` and every symlink are resolved, it is a regular file strictly inside one of `roots` (the offline
|
|
14
|
+
/// media cache). Anything else is nil, so a message cannot name a private file of the app (its database,
|
|
15
|
+
/// its storage, any other file) and have it saved or shared. The caller copies the returned path, i.e.
|
|
16
|
+
/// exactly what was checked.
|
|
17
|
+
FOUNDATION_EXPORT NSString *_Nullable CCUIKitConfinedLocalFilePath(NSURL *_Nullable url, NSArray<NSString *> *roots);
|
|
18
|
+
|
|
19
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#import "CCLocalFileGuard.h"
|
|
2
|
+
#include <limits.h>
|
|
3
|
+
#include <stdlib.h>
|
|
4
|
+
|
|
5
|
+
BOOL CCUIKitIsFileURL(NSURL *url) {
|
|
6
|
+
return url != nil && url.scheme != nil && [url.scheme caseInsensitiveCompare:@"file"] == NSOrderedSame;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
NSArray<NSString *> *CCUIKitOfflineMediaRoots(void) {
|
|
10
|
+
NSString *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
|
|
11
|
+
return documents.length > 0 ? @[[documents stringByAppendingPathComponent:@"cometchat/media"]] : @[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// realpath(3): `..` and every symlink resolved, or nil when the path does not exist.
|
|
15
|
+
static NSString *CCUIKitResolvedPath(NSString *path) {
|
|
16
|
+
if (path.length == 0) return nil;
|
|
17
|
+
char resolved[PATH_MAX];
|
|
18
|
+
if (realpath(path.fileSystemRepresentation, resolved) == NULL) return nil;
|
|
19
|
+
return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:resolved length:strlen(resolved)];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
NSString *CCUIKitConfinedLocalFilePath(NSURL *url, NSArray<NSString *> *roots) {
|
|
23
|
+
if (!CCUIKitIsFileURL(url)) return nil;
|
|
24
|
+
NSString *source = CCUIKitResolvedPath(url.path);
|
|
25
|
+
if (source == nil) return nil;
|
|
26
|
+
BOOL isDir = YES;
|
|
27
|
+
if (![[NSFileManager defaultManager] fileExistsAtPath:source isDirectory:&isDir] || isDir) return nil;
|
|
28
|
+
for (NSString *root in roots) {
|
|
29
|
+
NSString *base = CCUIKitResolvedPath(root);
|
|
30
|
+
if (base.length <= 1) continue; // a missing root, or "/", allows nothing
|
|
31
|
+
if ([source hasPrefix:[base stringByAppendingString:@"/"]]) return source;
|
|
32
|
+
}
|
|
33
|
+
return nil;
|
|
34
|
+
}
|
package/ios/FileManager.m
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#import <Foundation/Foundation.h>
|
|
2
2
|
#import <React/RCTBridgeModule.h>
|
|
3
3
|
#import "FileManager.h"
|
|
4
|
+
#import "CCLocalFileGuard.h"
|
|
4
5
|
#import <QuickLook/QuickLook.h>
|
|
5
6
|
#import <React/RCTUtils.h>
|
|
6
7
|
#import <React/RCTConvert.h>
|
|
@@ -22,6 +23,22 @@ static NSString *const FIELD_NAME = @"name";
|
|
|
22
23
|
static NSString *const FIELD_TYPE = @"type";
|
|
23
24
|
static NSString *const FIELD_SIZE = @"size";
|
|
24
25
|
|
|
26
|
+
// The base name of a file name, so a ".." or a path separator can never leave the destination folder,
|
|
27
|
+
// or nil when there is no usable name. Same rule as the Android UI Kit (File(displayName).name).
|
|
28
|
+
static NSString *CCSafeFileName(NSString *name) {
|
|
29
|
+
if (name.length == 0 || [name containsString:@"\0"]) return nil;
|
|
30
|
+
NSString *base = name.lastPathComponent;
|
|
31
|
+
if (base.length == 0 || [base isEqualToString:@"/"] || [base isEqualToString:@"."] || [base isEqualToString:@".."]) return nil;
|
|
32
|
+
return base;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The file behind a file:// URL taken from a message, when it lies inside the offline media cache
|
|
36
|
+
// (CCLocalFileGuard.h), else nil. Stricter than the Android UI Kit's MediaViewerSource.localFile, which
|
|
37
|
+
// only checks that the file exists.
|
|
38
|
+
static NSString *CCOfflineMediaFilePath(NSURL *url) {
|
|
39
|
+
return CCUIKitConfinedLocalFilePath(url, CCUIKitOfflineMediaRoots());
|
|
40
|
+
}
|
|
41
|
+
|
|
25
42
|
|
|
26
43
|
@interface CometChatFileManager () <UIDocumentPickerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, AVAudioRecorderDelegate, AVAudioPlayerDelegate, UIDocumentInteractionControllerDelegate, PHPickerViewControllerDelegate>
|
|
27
44
|
|
|
@@ -80,11 +97,32 @@ RCT_EXPORT_MODULE(FileManager)
|
|
|
80
97
|
- (void)downloadToDocuments:(NSString *)urlToDownload name:(NSString *)name callback:(RCTResponseSenderBlock)callback {
|
|
81
98
|
NSURL *url = [NSURL URLWithString:urlToDownload];
|
|
82
99
|
if (url == nil) { callback(@[@"{\"success\": false, \"error\": \"invalid url\"}"]); return; }
|
|
100
|
+
name = CCSafeFileName(name);
|
|
101
|
+
if (name == nil) { callback(@[@"{\"success\": false, \"error\": \"invalid file name\"}"]); return; }
|
|
83
102
|
|
|
84
103
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
85
104
|
NSString *destPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:name];
|
|
86
105
|
NSURL *destinationFileURL = [NSURL fileURLWithPath:destPath];
|
|
87
106
|
|
|
107
|
+
// A file already on the device: copied only from the offline media cache, never fetched.
|
|
108
|
+
if (CCUIKitIsFileURL(url)) {
|
|
109
|
+
NSString *source = CCOfflineMediaFilePath(url);
|
|
110
|
+
if (source == nil) {
|
|
111
|
+
callback(@[@"{\"success\": false, \"error\": \"file is not available\"}"]);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
NSFileManager *fm = [NSFileManager defaultManager];
|
|
115
|
+
[fm removeItemAtURL:destinationFileURL error:nil];
|
|
116
|
+
NSError *copyErr = nil;
|
|
117
|
+
if (![fm copyItemAtURL:[NSURL fileURLWithPath:source] toURL:destinationFileURL error:©Err]) {
|
|
118
|
+
callback(@[@"{\"success\": false, \"error\": \"could not save file\"}"]);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
self->_url = [NSString stringWithFormat:@"file://%@", destPath];
|
|
122
|
+
callback(@[@"{\"success\": true}"]);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
88
126
|
NSURLSessionDownloadTask *task = [[NSURLSession sharedSession] downloadTaskWithURL:url
|
|
89
127
|
completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
90
128
|
if (error != nil || location == nil) {
|
|
@@ -109,7 +147,9 @@ RCT_EXPORT_MODULE(FileManager)
|
|
|
109
147
|
// Files / Save to Photos / AirDrop — the sandbox-legal equivalent of Android's visible DownloadManager
|
|
110
148
|
// save (iOS apps cannot write to a shared public "Downloads" folder). Previously this saved into the
|
|
111
149
|
// app's PRIVATE Documents dir with no UI, so on iOS the download appeared to do nothing.
|
|
112
|
-
RCT_EXPORT_METHOD(checkAndDownload:(NSString *) urlToDownload name:(NSString *)
|
|
150
|
+
RCT_EXPORT_METHOD(checkAndDownload:(NSString *) urlToDownload name:(NSString *) rawName callback:(RCTResponseSenderBlock) callback) {
|
|
151
|
+
NSString *name = CCSafeFileName(rawName);
|
|
152
|
+
if (name == nil) { callback(@[@"{\"success\": false, \"error\": \"invalid file name\"}"]); return; }
|
|
113
153
|
[self downloadToDocuments:urlToDownload name:name callback:^(NSArray *response) {
|
|
114
154
|
NSString *res = response.firstObject ?: @"";
|
|
115
155
|
if ([res containsString:@"\"success\": true"]) {
|
|
@@ -134,13 +174,15 @@ RCT_EXPORT_METHOD(checkAndDownload:(NSString *) urlToDownload name:(NSString *)
|
|
|
134
174
|
QLPreviewController* previewCtrl = [[QLPreviewController alloc] init];
|
|
135
175
|
[previewCtrl setDataSource: self];
|
|
136
176
|
[[previewCtrl navigationController] setTitle:@""];
|
|
137
|
-
[previewCtrl setModalPresentationStyle:
|
|
177
|
+
[previewCtrl setModalPresentationStyle:UIModalPresentationFullScreen];
|
|
138
178
|
UIViewController *presentedViewController = RCTPresentedViewController();
|
|
139
179
|
[presentedViewController presentViewController:previewCtrl animated:YES completion:nil];
|
|
140
180
|
});
|
|
141
181
|
}
|
|
142
182
|
|
|
143
|
-
RCT_EXPORT_METHOD(doesFileExist:(NSString *)
|
|
183
|
+
RCT_EXPORT_METHOD(doesFileExist:(NSString *)rawFileName callback:(RCTResponseSenderBlock)callback) {
|
|
184
|
+
NSString *fileName = CCSafeFileName(rawFileName);
|
|
185
|
+
if (fileName == nil) { callback(@[@"{\"exists\": false}"]); return; }
|
|
144
186
|
// Get the document directory path
|
|
145
187
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
146
188
|
NSString *documentsDirectory = [paths objectAtIndex:0];
|
|
@@ -158,7 +200,9 @@ RCT_EXPORT_METHOD(doesFileExist:(NSString *)fileName callback:(RCTResponseSender
|
|
|
158
200
|
}
|
|
159
201
|
|
|
160
202
|
|
|
161
|
-
RCT_EXPORT_METHOD(openFile:(NSString *) url name:(NSString *)
|
|
203
|
+
RCT_EXPORT_METHOD(openFile:(NSString *) url name:(NSString *) rawFileName myCallback:(RCTResponseSenderBlock)callback) {
|
|
204
|
+
NSString *fileName = CCSafeFileName(rawFileName);
|
|
205
|
+
if (fileName == nil) { callback(@[@"{\"success\": false}"]); return; }
|
|
162
206
|
//new way
|
|
163
207
|
@try {
|
|
164
208
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
@@ -194,7 +238,9 @@ RCT_EXPORT_METHOD(openFile:(NSString *) url name:(NSString *) fileName myCallbac
|
|
|
194
238
|
}
|
|
195
239
|
}
|
|
196
240
|
|
|
197
|
-
RCT_EXPORT_METHOD(openFileWithOption:(NSString *)
|
|
241
|
+
RCT_EXPORT_METHOD(openFileWithOption:(NSString *)rawFileName callback:(RCTResponseSenderBlock)callback) {
|
|
242
|
+
NSString *fileName = CCSafeFileName(rawFileName);
|
|
243
|
+
if (fileName == nil) { callback(@[@"{\"success\": false, \"error\": \"invalid file name\"}"]); return; }
|
|
198
244
|
@try {
|
|
199
245
|
// Get the Downloads directory path
|
|
200
246
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
@@ -480,7 +526,25 @@ RCT_EXPORT_METHOD(shareMessage: (NSDictionary *) shareObj myCallback:(RCTRespons
|
|
|
480
526
|
} else {
|
|
481
527
|
if (fileUrl) {
|
|
482
528
|
NSURL *url = [NSURL URLWithString:fileUrl];
|
|
483
|
-
if (url) {
|
|
529
|
+
if (url && CCUIKitIsFileURL(url)) {
|
|
530
|
+
// A file already on the device: shared only from the offline media cache, under its own
|
|
531
|
+
// name (the cached file has none), never fetched.
|
|
532
|
+
NSString *shareName = CCSafeFileName(mediaName.length > 0 ? mediaName : url.lastPathComponent);
|
|
533
|
+
NSString *source = CCOfflineMediaFilePath(url);
|
|
534
|
+
if (shareName == nil || source == nil) {
|
|
535
|
+
callback(@[@"{\"success\": false}"]);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
NSURL *shareUrl = [[NSURL fileURLWithPath:NSTemporaryDirectory()] URLByAppendingPathComponent:shareName];
|
|
539
|
+
NSFileManager *fm = [NSFileManager defaultManager];
|
|
540
|
+
[fm removeItemAtURL:shareUrl error:nil];
|
|
541
|
+
if ([fm copyItemAtURL:[NSURL fileURLWithPath:source] toURL:shareUrl error:nil]) {
|
|
542
|
+
[self shareMedia:shareUrl];
|
|
543
|
+
callback(@[@"{\"success\": true}"]);
|
|
544
|
+
} else {
|
|
545
|
+
callback(@[@"{\"success\": false}"]);
|
|
546
|
+
}
|
|
547
|
+
} else if (url) {
|
|
484
548
|
[self downloadMediaMessage:url completion:^(NSURL *fileLocation) {
|
|
485
549
|
if (fileLocation) {
|
|
486
550
|
[self shareMedia:fileLocation];
|
package/ios/VideoManager.m
CHANGED
|
@@ -16,7 +16,7 @@ RCT_EXPORT_MODULE(VideoManager);
|
|
|
16
16
|
QLPreviewController* previewCtrl = [[QLPreviewController alloc] init];
|
|
17
17
|
[previewCtrl setDataSource: self];
|
|
18
18
|
[[previewCtrl navigationController] setTitle:@""];
|
|
19
|
-
[previewCtrl setModalPresentationStyle:
|
|
19
|
+
[previewCtrl setModalPresentationStyle:UIModalPresentationFullScreen];
|
|
20
20
|
UIViewController *presentedViewController = RCTPresentedViewController();
|
|
21
21
|
[presentedViewController presentViewController:previewCtrl animated:YES completion:nil];
|
|
22
22
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cometchat/chat-uikit-react-native",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "Ready-to-use Chat UI Components for React Native",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"module": "src/index",
|
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
"test:native:ios": "cd ios-tests && UDID=$(xcrun simctl list devices available | grep -m1 iPhone | grep -oE '[0-9A-F-]{36}'); if [ -z \"$UDID\" ]; then echo \"No iPhone simulator is available. Install one via Xcode > Settings > Components.\" >&2; exit 1; fi; xcodebuild test -scheme RichTextEditorKit-Package -destination \"platform=iOS Simulator,id=$UDID\"",
|
|
29
29
|
"typescript": "tsc --noEmit",
|
|
30
30
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
31
|
+
"lint:offline": "eslint \"src/shared/offline/**/*.{ts,tsx}\"",
|
|
32
|
+
"api:check": "bash ./scripts/api-check.sh",
|
|
33
|
+
"sdk-floor:check": "bash ./scripts/sdk-floor-typecheck.sh",
|
|
34
|
+
"integrator:check": "bash ./scripts/integrator-compile-check.sh",
|
|
35
|
+
"probe:check": "bash ./scripts/probe-strip-check.sh",
|
|
31
36
|
"release": "release-it",
|
|
32
37
|
"format": "prettier --write ./src/**/*.{ts,tsx}"
|
|
33
38
|
},
|
|
@@ -87,15 +92,25 @@
|
|
|
87
92
|
"react-native-localize": "*",
|
|
88
93
|
"react-native-safe-area-context": "*",
|
|
89
94
|
"react-native-svg": "*",
|
|
90
|
-
"react-native-video": "*"
|
|
95
|
+
"react-native-video": "*",
|
|
96
|
+
"react-native-fs": "*"
|
|
97
|
+
},
|
|
98
|
+
"peerDependenciesMeta": {
|
|
99
|
+
"react-native-fs": {
|
|
100
|
+
"optional": true
|
|
101
|
+
}
|
|
91
102
|
},
|
|
92
103
|
"jest": {
|
|
93
104
|
"preset": "@react-native/jest-preset",
|
|
94
105
|
"modulePathIgnorePatterns": [
|
|
95
106
|
"<rootDir>/lib/"
|
|
96
107
|
],
|
|
108
|
+
"setupFiles": [
|
|
109
|
+
"<rootDir>/jest/setup.js"
|
|
110
|
+
],
|
|
97
111
|
"moduleNameMapper": {
|
|
98
|
-
"\\.(wav|mp3|m4a|aac|ogg)$": "<rootDir>/jest/assetMock.js"
|
|
112
|
+
"\\.(wav|mp3|m4a|aac|ogg)$": "<rootDir>/jest/assetMock.js",
|
|
113
|
+
"^@react-native-async-storage/async-storage$": "<rootDir>/jest/asyncStorageMock.js"
|
|
99
114
|
}
|
|
100
115
|
},
|
|
101
116
|
"commitlint": {
|