@cometchat/chat-uikit-react-native 4.3.2 → 4.3.4
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/AndroidManifest.xml +3 -4
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +0 -1
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +125 -7
- package/android/src/main/java/com/reactnativecometchatuikit/ImageManager.java +1 -1
- package/ios/CommonUtil.h +4 -0
- package/ios/CommonUtil.m +27 -0
- package/package.json +1 -1
- package/src/AI/AIAssistBot/AIAssistBotDecorator.tsx +0 -3
- package/src/CometChatConversations/CometChatConversations.tsx +151 -66
- package/src/CometChatConversations/ConversationsConfiguration.ts +25 -4
- package/src/CometChatConversations/style.ts +5 -1
- package/src/CometChatConversationsWithMessages/CometChatConversationsWithMessages.tsx +29 -29
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +598 -63
- package/src/CometChatMessageComposer/MessageComposerConfiguration.tsx +12 -1
- package/src/CometChatMessageComposer/resources/Info.png +0 -0
- package/src/CometChatMessageComposer/resources/index.ts +3 -1
- package/src/CometChatMessageHeader/listners.ts +0 -2
- package/src/CometChatMessageList/CometChatMessageList.tsx +139 -30
- package/src/CometChatMessageList/MessageListConfiguration.ts +19 -6
- package/src/CometChatMessages/CometChatMessages.tsx +16 -16
- package/src/CometChatThreadedMessages/CometChatThreadedMessages.tsx +41 -3
- package/src/calls/CallingExtentionDecorator.tsx +5 -5
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +3 -3
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +2 -0
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +2 -0
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +3 -3
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +3 -3
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +51 -15
- package/src/extensions/LinkPreview/LinkPreviewExtentionDecorator.tsx +4 -4
- package/src/extensions/MessageTranslation/MessageTranslationBubble.tsx +31 -9
- package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +83 -6
- package/src/extensions/Polls/Polls.tsx +106 -70
- package/src/extensions/Polls/PollsDecorator.tsx +3 -2
- package/src/extensions/Stickers/CometChatStickerKeyboard/style.ts +3 -3
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +14 -6
- package/src/extensions/TextModeration/TextModerationExtensionDecorator.tsx +3 -3
- package/src/index.ts +29 -8
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +146 -24
- package/src/shared/CometChatUiKit/index.ts +1 -1
- package/src/shared/base/vars.ts +13 -0
- package/src/shared/constants/UIKitConstants.ts +6 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +7 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +11 -1
- package/src/shared/events/CometChatUIEvents.ts +3 -1
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +380 -0
- package/src/shared/formatters/CometChatMentionsFormatter/MentionTextStyle.ts +14 -0
- package/src/shared/formatters/CometChatMentionsFormatter/index.ts +7 -0
- package/src/shared/formatters/CometChatTextFormatter.ts +253 -0
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +146 -0
- package/src/shared/formatters/index.ts +11 -0
- package/src/shared/framework/DataSource.ts +21 -16
- package/src/shared/framework/DataSourceDecorator.tsx +29 -13
- package/src/shared/framework/MessageDataSource.tsx +215 -49
- package/src/shared/helper/useKeyboard.tsx +20 -2
- package/src/shared/index.ts +31 -11
- package/src/shared/libs/ImageZoom/ReactNativeZoomableView.tsx +1040 -0
- package/src/shared/libs/ImageZoom/ReactNativeZoomableViewWithGestures.tsx +223 -0
- package/src/shared/libs/ImageZoom/helper.ts +144 -0
- package/src/shared/libs/ImageZoom/index.tsx +13 -0
- package/src/shared/libs/ImageZoom/types/index.ts +186 -0
- package/src/shared/libs/VideoPlayer/Video.js +0 -24
- package/src/shared/libs/VideoPlayerControls/assets/img/back.png +0 -0
- package/src/shared/libs/VideoPlayerControls/components/Back/Back.tsx +1 -1
- package/src/shared/resources/CometChatLocalize/CometChatLocalize.ts +2 -0
- package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/de/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/en/translation.json +10 -1
- package/src/shared/resources/CometChatLocalize/resources/es/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +10 -1
- package/src/shared/resources/CometChatLocalize/resources/hu/translation.json +315 -0
- package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +12 -1
- package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +11 -1
- package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +11 -1
- package/src/shared/resources/CometChatTheme/Palette.ts +16 -0
- package/src/shared/utils/InteractiveMessageUtils.ts +39 -1
- package/src/shared/utils/NetworkUtils.tsx +5 -0
- package/src/shared/utils/PermissionUtil.ts +142 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +1 -0
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +8 -6
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +5 -1
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +12 -11
- package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +70 -22
- package/src/shared/views/CometChatImageBubble/assets/index.ts +5 -0
- package/src/shared/views/CometChatImageBubble/assets/spineer.png +0 -0
- package/src/shared/views/CometChatImageViewerModal/ImageViewerModal.tsx +106 -0
- package/src/shared/views/CometChatImageViewerModal/index.tsx +1 -0
- package/src/shared/views/CometChatImageViewerModal/resources/Back.png +0 -0
- package/src/shared/views/CometChatImageViewerModal/resources/index.ts +5 -0
- package/src/shared/views/CometChatList/CometChatList.tsx +10 -1
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -2
- package/src/shared/views/{CometChatReactionsList/CometChatReactionsList.tsx → CometChatReactionList/CometChatReactionList.tsx} +17 -17
- package/src/shared/views/CometChatReactionList/ReactionListConfiguration.tsx +14 -0
- package/src/shared/views/CometChatReactionList/index.ts +12 -0
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +3 -3
- package/src/shared/views/CometChatSchedulerBubble/CometChatSchedulerBubble.tsx +12 -0
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +64 -0
- package/src/shared/views/CometChatSuggestionList/SuggestionItem.ts +48 -0
- package/src/shared/views/CometChatSuggestionList/SuggestionListConfiguration.ts +23 -0
- package/src/shared/views/CometChatSuggestionList/index.ts +11 -0
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +33 -46
- package/src/shared/views/CometChatTextBubble/TextBubbleStyle.ts +0 -14
- package/src/shared/views/CometChatTextBubble/index.ts +2 -3
- package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +6 -4
- package/src/shared/views/index.ts +14 -8
- package/android/src/main/java/com/reactnativecometchatuikit/VideoManager.java +0 -40
- package/src/shared/libs/VideoPlayerControls/assets/img/back@2x.png +0 -0
- package/src/shared/libs/VideoPlayerControls/assets/img/back@3x.png +0 -0
- package/src/shared/utils/PermissionUtilIOS.ts +0 -104
- package/src/shared/views/CometChatReactionsList/ReactionsListConfiguration.tsx +0 -14
- package/src/shared/views/CometChatReactionsList/index.ts +0 -12
- /package/src/shared/views/{CometChatReactionsList/ReactionsListStyle.tsx → CometChatReactionList/ReactionListStyle.tsx} +0 -0
- /package/src/shared/views/{CometChatReactionsList → CometChatReactionList}/resources/Spineer.png +0 -0
- /package/src/shared/views/{CometChatReactionsList → CometChatReactionList}/resources/index.ts +0 -0
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
<uses-permission android:name="android.permission.INTERNET" />
|
|
5
5
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
6
6
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
7
|
-
<application android:requestLegacyExternalStorage="true"
|
|
7
|
+
<application android:requestLegacyExternalStorage="true"
|
|
8
|
+
android:largeHeap="true" >
|
|
8
9
|
<activity
|
|
9
10
|
android:name="com.reactnativecometchatuikit.CometChatVideoPlayer"
|
|
10
11
|
android:theme="@style/Theme.AppCompat" />
|
|
@@ -16,12 +17,10 @@
|
|
|
16
17
|
android:theme="@style/Theme.AppCompat" />
|
|
17
18
|
<provider
|
|
18
19
|
android:name="androidx.core.content.FileProvider"
|
|
19
|
-
android:authorities="${applicationId}.
|
|
20
|
+
android:authorities="${applicationId}.fileprovider"
|
|
20
21
|
android:exported="false"
|
|
21
|
-
tools:replace="android:authorities"
|
|
22
22
|
android:grantUriPermissions="true">
|
|
23
23
|
<meta-data
|
|
24
|
-
tools:replace="android:resource"
|
|
25
24
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
|
26
25
|
android:resource="@xml/filepaths" />
|
|
27
26
|
</provider>
|
|
@@ -21,7 +21,6 @@ public class CometchatUiKitPackage implements ReactPackage {
|
|
|
21
21
|
modules.add(new CometChatSoundModule(reactContext));
|
|
22
22
|
modules.add(new SoundPlayer(reactContext));
|
|
23
23
|
modules.add(new FileManager(reactContext));
|
|
24
|
-
modules.add(new VideoManager(reactContext));
|
|
25
24
|
modules.add(new ImageManager(reactContext));
|
|
26
25
|
modules.add(new WebViewManager(reactContext));
|
|
27
26
|
modules.add(new TimeZoneCodeManager(reactContext));
|
|
@@ -2,6 +2,7 @@ package com.reactnativecometchatuikit;
|
|
|
2
2
|
|
|
3
3
|
import static android.os.Environment.DIRECTORY_DOCUMENTS;
|
|
4
4
|
|
|
5
|
+
import android.Manifest;
|
|
5
6
|
import android.app.Activity;
|
|
6
7
|
import android.app.DownloadManager;
|
|
7
8
|
import android.content.ActivityNotFoundException;
|
|
@@ -14,6 +15,9 @@ import android.content.IntentFilter;
|
|
|
14
15
|
import android.content.pm.PackageManager;
|
|
15
16
|
import android.database.Cursor;
|
|
16
17
|
import android.graphics.Bitmap;
|
|
18
|
+
import android.graphics.BitmapFactory;
|
|
19
|
+
import android.graphics.Matrix;
|
|
20
|
+
import android.media.ExifInterface;
|
|
17
21
|
import android.media.MediaPlayer;
|
|
18
22
|
import android.media.MediaRecorder;
|
|
19
23
|
import android.net.Uri;
|
|
@@ -27,6 +31,7 @@ import android.provider.DocumentsContract;
|
|
|
27
31
|
import android.provider.MediaStore;
|
|
28
32
|
import android.provider.OpenableColumns;
|
|
29
33
|
import android.util.Log;
|
|
34
|
+
import android.webkit.MimeTypeMap;
|
|
30
35
|
import android.widget.Toast;
|
|
31
36
|
|
|
32
37
|
import androidx.annotation.NonNull;
|
|
@@ -47,6 +52,7 @@ import com.facebook.react.bridge.ReadableMap;
|
|
|
47
52
|
import com.facebook.react.bridge.ReadableArray;
|
|
48
53
|
import com.facebook.react.bridge.WritableArray;
|
|
49
54
|
import com.facebook.react.bridge.WritableMap;
|
|
55
|
+
import com.facebook.react.bridge.WritableNativeMap;
|
|
50
56
|
|
|
51
57
|
import java.io.File;
|
|
52
58
|
import java.io.FileOutputStream;
|
|
@@ -73,6 +79,8 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
73
79
|
private ReactApplicationContext mReactContext;
|
|
74
80
|
private static final int READ_REQUEST_CODE = 100;
|
|
75
81
|
private static final int CAPTURE_STILL_IMAGE = 101;
|
|
82
|
+
private static final int REQUEST_LAUNCH_CAMERA = 1;
|
|
83
|
+
private static int IMAGE_QUALITY = 20;
|
|
76
84
|
|
|
77
85
|
private Callback callback;
|
|
78
86
|
|
|
@@ -82,6 +90,7 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
82
90
|
private static final String FIELD_NAME = "name";
|
|
83
91
|
private static final String FIELD_TYPE = "type";
|
|
84
92
|
private static final String FIELD_SIZE = "size";
|
|
93
|
+
private File cameraFile;
|
|
85
94
|
|
|
86
95
|
FileManager(ReactApplicationContext context) {
|
|
87
96
|
super(context);
|
|
@@ -109,6 +118,70 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
109
118
|
if (requestCode == CAPTURE_STILL_IMAGE) {
|
|
110
119
|
saveImageFromCameraAndReturn(resultCode, data, callback);
|
|
111
120
|
}
|
|
121
|
+
if (requestCode == REQUEST_LAUNCH_CAMERA) {
|
|
122
|
+
if (resultCode == Activity.RESULT_OK) {
|
|
123
|
+
if (cameraFile != null && cameraFile.exists()) {
|
|
124
|
+
// Compress the image
|
|
125
|
+
try {
|
|
126
|
+
Bitmap bitmap = BitmapFactory.decodeFile(cameraFile.getAbsolutePath());
|
|
127
|
+
ExifInterface exif = new ExifInterface(cameraFile.getAbsolutePath());
|
|
128
|
+
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
|
|
129
|
+
Log.i(TAG, "onActivityResult: orientation" + orientation);
|
|
130
|
+
int rotationAngle = 0;
|
|
131
|
+
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
|
|
132
|
+
rotationAngle = 90;
|
|
133
|
+
}
|
|
134
|
+
else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
|
|
135
|
+
rotationAngle = 180;
|
|
136
|
+
}
|
|
137
|
+
else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
|
|
138
|
+
rotationAngle = 270;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Create a new matrix for rotation
|
|
142
|
+
Matrix matrix = new Matrix();
|
|
143
|
+
if (rotationAngle != 0) {
|
|
144
|
+
matrix.setRotate(rotationAngle);
|
|
145
|
+
// Rotate the bitmap
|
|
146
|
+
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
|
147
|
+
}
|
|
148
|
+
FileOutputStream out = new FileOutputStream(cameraFile);
|
|
149
|
+
|
|
150
|
+
// The quality parameter can be adjusted to decrease image quality (100 means no compression)
|
|
151
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, IMAGE_QUALITY, out); // Compress to 50% quality
|
|
152
|
+
out.flush();
|
|
153
|
+
out.close();
|
|
154
|
+
bitmap.recycle();
|
|
155
|
+
} catch (Exception e) {
|
|
156
|
+
WritableMap errorMap = new WritableNativeMap();
|
|
157
|
+
errorMap.putString("error", "Image compression error: " + e.getMessage());
|
|
158
|
+
callback.invoke(errorMap);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Prepare the image details to return to React Native
|
|
163
|
+
WritableMap imageMap = new WritableNativeMap();
|
|
164
|
+
Uri fileUri = Uri.fromFile(cameraFile);
|
|
165
|
+
imageMap.putString("uri", fileUri.toString());
|
|
166
|
+
imageMap.putString("path", cameraFile.getAbsolutePath());
|
|
167
|
+
imageMap.putDouble("size", cameraFile.length());
|
|
168
|
+
imageMap.putString("name", cameraFile.getName());
|
|
169
|
+
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(fileUri.toString());
|
|
170
|
+
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension.toLowerCase());
|
|
171
|
+
imageMap.putString("type", mimeType != null ? mimeType : "image/jpeg");
|
|
172
|
+
|
|
173
|
+
callback.invoke(imageMap);
|
|
174
|
+
} else {
|
|
175
|
+
WritableMap errorMap = new WritableNativeMap();
|
|
176
|
+
errorMap.putString("error", "Image file does not exist.");
|
|
177
|
+
callback.invoke(errorMap);
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
WritableMap errorMap = new WritableNativeMap();
|
|
181
|
+
errorMap.putString("error", "Camera activity did not return RESULT_OK.");
|
|
182
|
+
callback.invoke(errorMap);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
112
185
|
}
|
|
113
186
|
|
|
114
187
|
private void saveImageFromCameraAndReturn(int resultCode, Intent data, Callback callback) {
|
|
@@ -496,17 +569,62 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
496
569
|
}
|
|
497
570
|
}
|
|
498
571
|
|
|
499
|
-
|
|
500
|
-
|
|
572
|
+
@ReactMethod
|
|
573
|
+
public void openCamera(String fileType, Integer imageQuality, final Callback callback) {
|
|
574
|
+
IMAGE_QUALITY = imageQuality;
|
|
575
|
+
final Activity currentActivity = getCurrentActivity();
|
|
576
|
+
if (currentActivity == null) {
|
|
577
|
+
WritableMap errorMap = new WritableNativeMap();
|
|
578
|
+
errorMap.putString("error", "Activity doesn't exist");
|
|
579
|
+
callback.invoke(errorMap);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// Check and request permissions if needed, then proceed with camera launch
|
|
584
|
+
if (ContextCompat.checkSelfPermission(currentActivity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
|
585
|
+
ActivityCompat.requestPermissions(currentActivity, new String[] {Manifest.permission.CAMERA}, REQUEST_LAUNCH_CAMERA);
|
|
586
|
+
} else {
|
|
587
|
+
launchCameraIntent(currentActivity, callback);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
private void launchCameraIntent(Activity currentActivity, Callback callback) {
|
|
592
|
+
this.callback = callback;
|
|
593
|
+
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
501
594
|
try {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
595
|
+
cameraFile = createImageFile(); // Use the global variable here
|
|
596
|
+
if (cameraFile != null) {
|
|
597
|
+
Uri photoURI = FileProvider.getUriForFile(currentActivity,
|
|
598
|
+
currentActivity.getApplicationContext().getPackageName() + ".fileprovider",
|
|
599
|
+
cameraFile);
|
|
600
|
+
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
|
|
601
|
+
currentActivity.startActivityForResult(cameraIntent, REQUEST_LAUNCH_CAMERA);
|
|
602
|
+
} else {
|
|
603
|
+
WritableMap errorMap = new WritableNativeMap();
|
|
604
|
+
errorMap.putString("error", "Could not create image file");
|
|
605
|
+
callback.invoke(errorMap);
|
|
606
|
+
}
|
|
607
|
+
} catch (Exception e) {
|
|
608
|
+
WritableMap errorMap = new WritableNativeMap();
|
|
609
|
+
errorMap.putString("error", "Failed to launch camera: " + e.getMessage());
|
|
610
|
+
callback.invoke(errorMap);
|
|
507
611
|
}
|
|
508
612
|
}
|
|
509
613
|
|
|
614
|
+
private File createImageFile() throws IOException {
|
|
615
|
+
// Create an image file name
|
|
616
|
+
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
|
617
|
+
String imageFileName = "JPEG_" + timeStamp + "_";
|
|
618
|
+
File storageDir = getCurrentActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
|
|
619
|
+
File image = File.createTempFile(
|
|
620
|
+
imageFileName, /* prefix */
|
|
621
|
+
".jpeg", /* suffix */
|
|
622
|
+
storageDir /* directory */
|
|
623
|
+
);
|
|
624
|
+
return image;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
|
|
510
628
|
@ReactMethod
|
|
511
629
|
public void openFileChooser(String fileType, Callback callback) {
|
|
512
630
|
try {
|
|
@@ -11,7 +11,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
|
11
11
|
import com.facebook.react.bridge.ReactMethod;
|
|
12
12
|
|
|
13
13
|
public class ImageManager extends ReactContextBaseJavaModule {
|
|
14
|
-
public static final String TAG = "
|
|
14
|
+
public static final String TAG = "ImageManager";
|
|
15
15
|
|
|
16
16
|
ImageManager(ReactApplicationContext context) {
|
|
17
17
|
super(context);
|
package/ios/CommonUtil.h
ADDED
package/ios/CommonUtil.m
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#import "CommonUtil.h"
|
|
2
|
+
|
|
3
|
+
@implementation CometChatCommonUtil
|
|
4
|
+
|
|
5
|
+
RCT_EXPORT_MODULE(CommonUtil);
|
|
6
|
+
|
|
7
|
+
RCT_EXPORT_METHOD(getSafeAreaInsets:(RCTPromiseResolveBlock)resolve
|
|
8
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
9
|
+
{
|
|
10
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
11
|
+
if (@available(iOS 11.0, *)) {
|
|
12
|
+
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
|
|
13
|
+
UIEdgeInsets safeInsets = window.safeAreaInsets;
|
|
14
|
+
resolve(@{
|
|
15
|
+
@"top" : @(safeInsets.top),
|
|
16
|
+
@"bottom" : @(safeInsets.bottom),
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
resolve(@{
|
|
20
|
+
@"top" : @0,
|
|
21
|
+
@"bottom" : @0,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cometchat/chat-uikit-react-native",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.4",
|
|
4
4
|
"description": "CometChat React Native UI Kit is a collection of custom UI Components designed to build text , chat and calling features in your application. The UI Kit is developed to keep developers in mind and aims to reduce development efforts significantly",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"module": "src/index",
|
|
@@ -8,7 +8,13 @@ import {
|
|
|
8
8
|
CometChatConfirmDialog,
|
|
9
9
|
CometChatConfirmDialogStyleInterface,
|
|
10
10
|
CometChatContext,
|
|
11
|
-
|
|
11
|
+
CometChatMentionsFormatter,
|
|
12
|
+
CometChatTextFormatter,
|
|
13
|
+
CometChatUrlsFormatter,
|
|
14
|
+
MentionTextStyle,
|
|
15
|
+
CometChatListActionsInterface,
|
|
16
|
+
localize,
|
|
17
|
+
CometChatUIKit
|
|
12
18
|
} from "../shared";
|
|
13
19
|
import { Style } from "./style";
|
|
14
20
|
import {
|
|
@@ -32,6 +38,7 @@ import { StatusIndicatorStyleInterface } from "../shared/views/CometChatStatusIn
|
|
|
32
38
|
import { DateStyleInterface } from "../shared/views/CometChatDate/DateStyle";
|
|
33
39
|
import { BadgeStyleInterface } from "../shared/views/CometChatBadge";
|
|
34
40
|
import { InteractiveMessageUtils } from "../shared/utils/InteractiveMessageUtils";
|
|
41
|
+
import { CommonUtils } from "../shared/utils/CommonUtils";
|
|
35
42
|
|
|
36
43
|
const conversationListenerId = "chatlist_" + new Date().getTime();
|
|
37
44
|
const userListenerId = "chatlist_user_" + new Date().getTime();
|
|
@@ -216,7 +223,16 @@ export interface ConversationInterface {
|
|
|
216
223
|
/**
|
|
217
224
|
* style object for confirm dialog
|
|
218
225
|
*/
|
|
219
|
-
confirmDialogStyle?: CometChatConfirmDialogStyleInterface
|
|
226
|
+
confirmDialogStyle?: CometChatConfirmDialogStyleInterface,
|
|
227
|
+
/**
|
|
228
|
+
* if true, mentions will be disabled. Default: false
|
|
229
|
+
*/
|
|
230
|
+
disableMentions?: boolean,
|
|
231
|
+
/**
|
|
232
|
+
* Collection of text formatter class
|
|
233
|
+
* @type {Array<CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter>}
|
|
234
|
+
*/
|
|
235
|
+
textFormatters?: Array<CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter>;
|
|
220
236
|
}
|
|
221
237
|
|
|
222
238
|
/**
|
|
@@ -262,12 +278,14 @@ export const CometChatConversations = (props: ConversationInterface) => {
|
|
|
262
278
|
onError,
|
|
263
279
|
onBack,
|
|
264
280
|
conversationsStyle,
|
|
281
|
+
disableMentions,
|
|
282
|
+
textFormatters
|
|
265
283
|
} = props;
|
|
266
284
|
|
|
267
285
|
//context
|
|
268
286
|
const { theme } = useContext<CometChatContextType>(CometChatContext);
|
|
269
287
|
|
|
270
|
-
const conversationListRef = React.useRef(null);
|
|
288
|
+
const conversationListRef = React.useRef<CometChatListActionsInterface>(null);
|
|
271
289
|
const loggedInUser = React.useRef(null);
|
|
272
290
|
const [confirmDelete, setConfirmDelete] = React.useState(undefined);
|
|
273
291
|
const [selecting, setSelecting] = React.useState(false);
|
|
@@ -363,44 +381,59 @@ export const CometChatConversations = (props: ConversationInterface) => {
|
|
|
363
381
|
}
|
|
364
382
|
}
|
|
365
383
|
|
|
384
|
+
|
|
385
|
+
const getConversationRefFromTypingIndicator = (typingIndicator: CometChat.TypingIndicator) => {
|
|
386
|
+
let list = conversationListRef.current.getAllListItems();
|
|
387
|
+
return list.find((item: CometChat.Conversation) => {
|
|
388
|
+
return (
|
|
389
|
+
(typingIndicator.getReceiverType() == ReceiverTypeConstants.user &&
|
|
390
|
+
item.getConversationType() == ReceiverTypeConstants.user
|
|
391
|
+
&& (item.getConversationWith() as CometChat.User).getUid() == typingIndicator.getSender().getUid())
|
|
392
|
+
|| (typingIndicator.getReceiverType() == ReceiverTypeConstants.group && item.getConversationType() == ReceiverTypeConstants.group
|
|
393
|
+
&& (item.getConversationWith() as CometChat.Group).getGuid() == typingIndicator.getReceiverId())
|
|
394
|
+
)
|
|
395
|
+
})
|
|
396
|
+
}
|
|
397
|
+
|
|
366
398
|
/**
|
|
367
399
|
* Listener callback for typing event
|
|
368
400
|
* @param {...any} args
|
|
369
401
|
*/
|
|
370
402
|
const typingEventHandler = (...args) => {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
403
|
+
let conversation: CometChat.Conversation = getConversationRefFromTypingIndicator(args[0]);
|
|
404
|
+
if (conversation) {
|
|
405
|
+
let isTyping = args[1];
|
|
406
|
+
let newConversation = conversation
|
|
407
|
+
if (isTyping && !newConversation?.['lastMessage']?.["typing"]) {
|
|
408
|
+
newConversation['lastMessage']["typing"] = args[0]?.receiverType === 'group' ?
|
|
409
|
+
`${args[0].sender.name} ${localize("IS_TYPING")}` :
|
|
410
|
+
localize("IS_TYPING");
|
|
411
|
+
} else {
|
|
412
|
+
delete newConversation['lastMessage']['typing'];
|
|
413
|
+
}
|
|
414
|
+
conversationListRef.current.updateList(newConversation);
|
|
382
415
|
}
|
|
383
|
-
|
|
416
|
+
|
|
384
417
|
}
|
|
385
418
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
419
|
+
/**
|
|
420
|
+
* Find conversation from state , check and udpate its last message object.
|
|
421
|
+
* conversation list item remains at the same place
|
|
422
|
+
*
|
|
423
|
+
* @param newMessage message object
|
|
424
|
+
*/
|
|
425
|
+
const checkAndUpdateLastMessage = (newMessage: CometChat.BaseMessage) => {
|
|
393
426
|
CometChat.CometChatHelper.getConversationFromMessage(newMessage)
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
427
|
+
.then(conversation => {
|
|
428
|
+
let conver: any = conversationListRef.current.getListItem(conversation.getConversationId())
|
|
429
|
+
if (!conver) return;
|
|
430
|
+
let lastMessageId = conver['lastMessage']['id']
|
|
431
|
+
if (lastMessageId == newMessage['id']) {
|
|
432
|
+
conversationListRef.current.updateList(conversation)
|
|
433
|
+
}
|
|
434
|
+
})
|
|
402
435
|
|
|
403
|
-
|
|
436
|
+
}
|
|
404
437
|
|
|
405
438
|
/**
|
|
406
439
|
* Find conversation from state and udpate its last message object.
|
|
@@ -418,7 +451,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
|
|
|
418
451
|
if (oldConversation == undefined) {
|
|
419
452
|
CometChat.CometChatHelper.getConversationFromMessage(newMessage)
|
|
420
453
|
.then(newConversation => {
|
|
421
|
-
if(newConversation?.lastMessage?.sender?.uid !== loggedInUser.current?.['uid'])
|
|
454
|
+
if (newConversation?.lastMessage?.sender?.uid !== loggedInUser.current?.['uid'])
|
|
422
455
|
newConversation.setUnreadMessageCount(1);
|
|
423
456
|
conversationListRef.current.updateAndMoveToFirst(newConversation);
|
|
424
457
|
})
|
|
@@ -481,7 +514,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
|
|
|
481
514
|
|
|
482
515
|
if (conversation) {
|
|
483
516
|
conversation.setLastMessage(message);
|
|
484
|
-
if(action === 'kicked' || action === 'banned')
|
|
517
|
+
if (action === 'kicked' || action === 'banned')
|
|
485
518
|
conversationListRef.current.removeItemFromList(message.conversationId);
|
|
486
519
|
else
|
|
487
520
|
conversationListRef.current.updateList(conversation);
|
|
@@ -536,7 +569,6 @@ export const CometChatConversations = (props: ConversationInterface) => {
|
|
|
536
569
|
}
|
|
537
570
|
|
|
538
571
|
const removeItemFromSelectionList = (id) => {
|
|
539
|
-
//remove from selected list if list is in selecting mode.
|
|
540
572
|
if (selecting) {
|
|
541
573
|
let index = selectedConversation.find(member => member['uid'] == id);
|
|
542
574
|
if (index > -1) {
|
|
@@ -561,70 +593,123 @@ export const CometChatConversations = (props: ConversationInterface) => {
|
|
|
561
593
|
|
|
562
594
|
const getMessagePreview = (conversations: CometChat.Conversation, uid) => {
|
|
563
595
|
|
|
564
|
-
let lastMessage: CometChat.BaseMessage = conversations
|
|
596
|
+
let lastMessage: CometChat.BaseMessage = conversations.getLastMessage();
|
|
565
597
|
if (!lastMessage) return null;
|
|
566
|
-
let messageText: string
|
|
567
|
-
if(lastMessage.getDeletedAt() !== undefined){
|
|
598
|
+
let messageText: string;
|
|
599
|
+
if (lastMessage.getDeletedAt() !== undefined) {
|
|
568
600
|
messageText = localize("THIS_MESSAGE_DELETED");
|
|
569
|
-
}else{
|
|
601
|
+
} else {
|
|
570
602
|
messageText = ChatConfigurator.getDataSource().getLastConversationMessage(conversations);
|
|
603
|
+
|
|
604
|
+
if (lastMessage) {
|
|
605
|
+
messageText = getFormattedText(lastMessage, messageText?.trim());
|
|
606
|
+
}
|
|
571
607
|
}
|
|
572
608
|
let groupText = "";
|
|
573
|
-
if (lastMessage
|
|
574
|
-
if (lastMessage
|
|
575
|
-
groupText = "
|
|
609
|
+
if (lastMessage.getReceiverType() == ReceiverTypeConstants.group) {
|
|
610
|
+
if (lastMessage.getSender().getUid() == uid) {
|
|
611
|
+
groupText = localize("YOU") + ": "
|
|
576
612
|
} else {
|
|
577
|
-
groupText = lastMessage
|
|
613
|
+
groupText = lastMessage.getSender().getName() + ": "
|
|
578
614
|
}
|
|
579
615
|
}
|
|
580
616
|
|
|
581
617
|
return (
|
|
582
|
-
<Text numberOfLines={1} ellipsizeMode={"tail"} style={[Style.subtitleTextStyle, {
|
|
583
|
-
|
|
618
|
+
<Text numberOfLines={1} ellipsizeMode={"tail"} style={[Style.subtitleTextStyle, {
|
|
619
|
+
color: theme.palette.getAccent600(), fontSize: theme.typography.subtitle1.fontSize,
|
|
620
|
+
fontWeight: theme.typography.subtitle1.fontWeight
|
|
621
|
+
}]}>
|
|
622
|
+
{groupText}{messageText}
|
|
584
623
|
</Text>
|
|
585
624
|
)
|
|
586
625
|
}
|
|
587
626
|
|
|
627
|
+
function getFormattedText(message: CometChat.BaseMessage, subtitle: string) {
|
|
628
|
+
let messageTextTmp = subtitle;
|
|
629
|
+
let allFormatters = [...(textFormatters || [])] || [];
|
|
630
|
+
|
|
631
|
+
if (!disableMentions && message.getMentionedUsers().length) {
|
|
632
|
+
let mentionsFormatter = ChatConfigurator.getDataSource().getMentionsFormatter();
|
|
633
|
+
mentionsFormatter.setLoggedInUser(CometChatUIKit.loggedInUser);
|
|
634
|
+
mentionsFormatter.setMentionsStyle(
|
|
635
|
+
new MentionTextStyle({
|
|
636
|
+
loggedInUserTextStyle: {
|
|
637
|
+
color: theme.palette.getPrimary(),
|
|
638
|
+
...theme.typography.title2,
|
|
639
|
+
},
|
|
640
|
+
textStyle: {
|
|
641
|
+
color: theme.palette.getPrimary(),
|
|
642
|
+
...theme.typography.subtitle1,
|
|
643
|
+
}
|
|
644
|
+
})
|
|
645
|
+
);
|
|
646
|
+
|
|
647
|
+
mentionsFormatter.setMessage(message);
|
|
648
|
+
allFormatters.push(mentionsFormatter);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (allFormatters && allFormatters.length) {
|
|
652
|
+
for (let i = 0; i < allFormatters.length; i++) {
|
|
653
|
+
let suggestionUsers = allFormatters[i].getSuggestionItems();
|
|
654
|
+
allFormatters[i].setMessage(message);
|
|
655
|
+
suggestionUsers.length > 0 && allFormatters[i].setSuggestionItems(suggestionUsers);
|
|
656
|
+
let _formatter = CommonUtils.clone(allFormatters[i]);
|
|
657
|
+
(messageTextTmp as string | JSX.Element) = _formatter.getFormattedText(messageTextTmp);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return messageTextTmp;
|
|
662
|
+
}
|
|
663
|
+
|
|
588
664
|
const LastMessageView = (params: {
|
|
589
665
|
conversations: CometChat.Conversation,
|
|
590
666
|
typingText: string
|
|
591
667
|
}) => {
|
|
592
|
-
|
|
593
668
|
const lastMessage = params['conversations']['lastMessage'];
|
|
594
669
|
if (!lastMessage) return null;
|
|
595
670
|
let readReceipt;
|
|
596
|
-
|
|
597
|
-
if (!disableTyping && params.typingText) {
|
|
671
|
+
if (params.typingText) {
|
|
598
672
|
return <View style={Style.row}>
|
|
599
|
-
<Text
|
|
673
|
+
<Text numberOfLines={1} ellipsizeMode={"tail"} style={[Style.subtitleTextStyle, {
|
|
674
|
+
color: theme.palette.getPrimary(),
|
|
675
|
+
fontSize: theme.typography.subtitle1.fontSize, fontWeight: theme.typography.subtitle1.fontWeight
|
|
676
|
+
}]} >{params.typingText}</Text>
|
|
600
677
|
</View>
|
|
601
678
|
}
|
|
602
679
|
|
|
603
680
|
if (lastMessage && !disableReadReceipt && lastMessage['sender']['uid'] == loggedInUser.current?.uid && !lastMessage.getDeletedAt()) {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
681
|
+
let status: MessageReceipt = "ERROR";
|
|
682
|
+
if (lastMessage?.hasOwnProperty('readAt'))
|
|
683
|
+
status = "READ";
|
|
684
|
+
else if (lastMessage?.hasOwnProperty("deliveredAt"))
|
|
685
|
+
status = "DELIVERED";
|
|
686
|
+
else if (lastMessage?.hasOwnProperty("sentAt"))
|
|
687
|
+
status = "SENT";
|
|
688
|
+
readReceipt = disableReceipt ? null : <CometChatReceipt
|
|
689
|
+
receipt={status}
|
|
690
|
+
deliveredIcon={props.deliveredIcon}
|
|
691
|
+
errorIcon={props.errorIcon}
|
|
692
|
+
readIcon={props.readIcon}
|
|
693
|
+
sentIcon={props.sentIcon}
|
|
694
|
+
waitIcon={props.waitingIcon}
|
|
695
|
+
/>;
|
|
619
696
|
}
|
|
620
697
|
|
|
698
|
+
let threadView;
|
|
621
699
|
|
|
700
|
+
if (lastMessage?.getParentMessageId()) {
|
|
701
|
+
threadView = <Text numberOfLines={1} style={[Style.subtitleTextStyle, { color: theme.palette.getAccent600() }]} >{localize("IN_A_THREAD")}</Text>
|
|
702
|
+
}
|
|
622
703
|
|
|
623
704
|
return (
|
|
624
|
-
<View style={Style.
|
|
625
|
-
{
|
|
626
|
-
{
|
|
705
|
+
<View style={Style.column}>
|
|
706
|
+
{threadView}
|
|
707
|
+
<View style={Style.row}>
|
|
708
|
+
{readReceipt}
|
|
709
|
+
{getMessagePreview(params['conversations'], loggedInUser.current?.uid)}
|
|
710
|
+
</View>
|
|
627
711
|
</View>
|
|
712
|
+
|
|
628
713
|
)
|
|
629
714
|
}
|
|
630
715
|
|