@cometchat/chat-uikit-react-native 4.0.0 → 4.0.2
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/LICENSE.md +3 -0
- package/README.md +1 -1
- package/android/src/main/java/com/reactnativecometchatuikit/{RNSoundModule.java → CometChatSoundModule.java} +22 -22
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -1
- package/ios/{RNSound.h → CometChatSoundModule.h} +1 -1
- package/ios/{RNSound.m → CometChatSoundModule.m} +2 -2
- package/package.json +3 -3
- package/src/AI/AIConversationStarter/AIConversationStarter.ts +33 -0
- package/src/AI/AIConversationStarter/AIConversationStarterDecorator.tsx +231 -0
- package/src/AI/AIConversationStarter/AIConversationStarterStyle.ts +8 -0
- package/src/AI/AIConversationStarter/configuration.ts +18 -0
- package/src/AI/AIConversationStarter/style.ts +76 -0
- package/src/AI/AIEnabler.ts +115 -0
- package/src/AI/AIEnablerDecorator.tsx +324 -0
- package/src/AI/AIExtensionDataSource.ts +12 -0
- package/src/AI/AISmartReplies/AISmartReplies.ts +28 -0
- package/src/AI/AISmartReplies/AISmartRepliesDecorator.ts +18 -0
- package/src/AI/AISmartReplies/AISmartRepliesStyle.ts +16 -0
- package/src/AI/AISmartReplies/configuration.ts +17 -0
- package/src/AI/CardView.tsx +81 -0
- package/src/AI/CardViewStyle.ts +37 -0
- package/src/AI/configuration.ts +17 -0
- package/src/AI/resources/ai-empty.png +0 -0
- package/src/AI/resources/ai-error.png +0 -0
- package/src/AI/resources/ai.png +0 -0
- package/src/AI/resources/index.ts +11 -0
- package/src/AI/resources/spineer.png +0 -0
- package/src/AI/style.ts +177 -0
- package/src/AI/utils.ts +39 -0
- package/src/CometChatConversations/CometChatConversations.tsx +56 -46
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +13 -4
- package/src/CometChatMessageHeader/listners.ts +5 -4
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +35 -35
- package/src/CometChatMessageList/CometChatMessageList.tsx +274 -158
- package/src/CometChatMessages/CometChatMessages.tsx +4 -3
- package/src/CometChatTabs/CometChatTabs.tsx +1 -1
- package/src/extensions/SmartReplies/SmartRepliesDecorator.tsx +4 -10
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +4 -2
- package/src/index.ts +61 -4
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +108 -7
- package/src/shared/CometChatUiKit/UIKitSettings.ts +8 -0
- package/src/shared/constants/UIKitConstants.ts +81 -47
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +46 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +66 -3
- package/src/shared/events/CometChatUIEvents.ts +1 -0
- package/src/shared/events/ListenerInitializer.ts +73 -0
- package/src/shared/events/messages.ts +14 -0
- package/src/shared/framework/DataSource.ts +12 -1
- package/src/shared/framework/DataSourceDecorator.tsx +37 -2
- package/src/shared/framework/MessageDataSource.tsx +85 -5
- package/src/shared/index.ts +44 -0
- package/src/shared/modals/InteractiveData/InteractiveActions/APIAction.ts +118 -0
- package/src/shared/modals/InteractiveData/InteractiveActions/CustomAction.ts +19 -0
- package/src/shared/modals/InteractiveData/InteractiveActions/URLNavigationAction.ts +34 -0
- package/src/shared/modals/InteractiveData/InteractiveActions/index.ts +3 -0
- package/src/shared/modals/InteractiveData/InteractiveData/InteractiveCardData.ts +69 -0
- package/src/shared/modals/InteractiveData/InteractiveData/InteractiveFormData.ts +119 -0
- package/src/shared/modals/InteractiveData/InteractiveData/index.ts +2 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/BaseInputElement.ts +102 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/BaseInteractiveElement.ts +45 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/ButtonElement.ts +61 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/CheckboxElement.ts +75 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/DropdownElement.ts +83 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/LabelElement.ts +32 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/OptionElement.ts +39 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/RadioButtonElement.ts +76 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/SingleSelectElement.ts +76 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/TextInputElement.ts +101 -0
- package/src/shared/modals/InteractiveData/InteractiveElements/index.ts +10 -0
- package/src/shared/modals/InteractiveData/InteractiveEntities/ActionEntity.ts +41 -0
- package/src/shared/modals/InteractiveData/InteractiveEntities/ElementEntity.ts +64 -0
- package/src/shared/modals/InteractiveData/InteractiveEntities/index.ts +2 -0
- package/src/shared/modals/InteractiveData/InteractiveMessage/CardMessage.ts +142 -0
- package/src/shared/modals/InteractiveData/InteractiveMessage/CustomInteractiveMessage.ts +38 -0
- package/src/shared/modals/InteractiveData/InteractiveMessage/FormMessage.ts +152 -0
- package/src/shared/modals/InteractiveData/InteractiveMessage/index.ts +3 -0
- package/src/shared/modals/InteractiveData/index.ts +28 -0
- package/src/shared/modals/index.ts +19 -0
- package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/de/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/en/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/es/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +8 -1
- package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +8 -1
- package/src/shared/resources/CometChatSoundManager/CometChatSoundManager.js +2 -2
- package/src/shared/resources/CometChatSoundManager/sound.js +35 -35
- package/src/shared/utils/InteractiveMessageUtils.ts +20 -0
- package/src/shared/utils/NetworkUtils.tsx +20 -0
- package/src/shared/utils/conversationUtils.ts +9 -6
- package/src/shared/views/CometChatButton/CometChatButton.tsx +32 -22
- package/src/shared/views/CometChatCardBubble/CardBubbleStyle.tsx +47 -0
- package/src/shared/views/CometChatCardBubble/CometChatCardBubble.tsx +173 -0
- package/src/shared/views/CometChatCardBubble/index.tsx +1 -0
- package/src/shared/views/CometChatCheckBox/CheckBoxStyle.tsx +43 -0
- package/src/shared/views/CometChatCheckBox/CometChatCheckBox.tsx +79 -0
- package/src/shared/views/CometChatDate/CometChatDate.tsx +2 -3
- package/src/shared/views/CometChatDropDown/CometChatDropDown.tsx +126 -0
- package/src/shared/views/CometChatDropDown/DropDownStyle.tsx +39 -0
- package/src/shared/views/CometChatDropDown/resources/downArrowIcon.png +0 -0
- package/src/shared/views/CometChatDropDown/resources/index.js +5 -0
- package/src/shared/views/CometChatFormBubble/CometChatFormBubble.tsx +464 -0
- package/src/shared/views/CometChatFormBubble/FormBubbleStyle.tsx +91 -0
- package/src/shared/views/CometChatFormBubble/index.tsx +1 -0
- package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +13 -5
- package/src/shared/views/CometChatImageBubble/ImageBubbleStyle.ts +14 -3
- package/src/shared/views/CometChatLabel/CometChatLabel.tsx +27 -0
- package/src/shared/views/CometChatLabel/LabelStyle.ts +19 -0
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +5 -4
- package/src/shared/views/CometChatQuickView/CometChatQuickView.tsx +66 -0
- package/src/shared/views/CometChatQuickView/QuickViewStyle.ts +55 -0
- package/src/shared/views/CometChatRadioButton/CometChatRadioButton.tsx +67 -0
- package/src/shared/views/CometChatRadioButton/RadioButtonStyle.tsx +38 -0
- package/src/shared/views/CometChatSingleSelect/CometChatSingleSelect.tsx +63 -0
- package/src/shared/views/CometChatSingleSelect/SingleStyle.tsx +35 -0
- package/src/shared/views/CometChatTextInput/CometChatTextInput.tsx +67 -0
- package/src/shared/views/CometChatTextInput/TextInputStyle.tsx +26 -0
- package/src/shared/views/index.ts +7 -1
- package/LICENSE +0 -21
- package/android/.idea/.gitignore +0 -3
- package/android/local.properties +0 -8
- package/src/.DS_Store +0 -0
- package/src/CometChatMessageInformation/.DS_Store +0 -0
- package/src/calls/CometChatCallHistory/.DS_Store +0 -0
- package/src/shared/framework/.DS_Store +0 -0
- package/src/shared/views/.DS_Store +0 -0
- package/src/shared/views/CometChatAudioBubble/.DS_Store +0 -0
- package/src/shared/views/CometChatFileBubble/.DS_Store +0 -0
package/LICENSE.md
ADDED
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
[](#)
|
|
13
13
|
[](#)
|
|
14
|
-

|
|
15
15
|

|
|
16
16
|
|
|
17
17
|
## Table of contents
|
|
@@ -24,7 +24,7 @@ import java.io.IOException;
|
|
|
24
24
|
import java.util.HashMap;
|
|
25
25
|
import java.util.Map;
|
|
26
26
|
|
|
27
|
-
public class
|
|
27
|
+
public class CometChatSoundModule
|
|
28
28
|
extends ReactContextBaseJavaModule
|
|
29
29
|
implements AudioManager.OnAudioFocusChangeListener {
|
|
30
30
|
|
|
@@ -36,7 +36,7 @@ public class RNSoundModule
|
|
|
36
36
|
Double focusedPlayerKey;
|
|
37
37
|
Boolean wasPlayingBeforeFocusChange = false;
|
|
38
38
|
|
|
39
|
-
public
|
|
39
|
+
public CometChatSoundModule(ReactApplicationContext context) {
|
|
40
40
|
super(context);
|
|
41
41
|
this.context = context;
|
|
42
42
|
this.category = null;
|
|
@@ -54,7 +54,7 @@ public class RNSoundModule
|
|
|
54
54
|
|
|
55
55
|
@Override
|
|
56
56
|
public String getName() {
|
|
57
|
-
return "
|
|
57
|
+
return "CometChatSoundModule";
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
@ReactMethod
|
|
@@ -84,7 +84,7 @@ public class RNSoundModule
|
|
|
84
84
|
}
|
|
85
85
|
this.playerPool.put(key, player);
|
|
86
86
|
|
|
87
|
-
final
|
|
87
|
+
final CometChatSoundModule module = this;
|
|
88
88
|
|
|
89
89
|
if (module.category != null) {
|
|
90
90
|
Integer category = null;
|
|
@@ -109,7 +109,7 @@ public class RNSoundModule
|
|
|
109
109
|
break;
|
|
110
110
|
default:
|
|
111
111
|
Log.e(
|
|
112
|
-
"
|
|
112
|
+
"CometChatSoundModule",
|
|
113
113
|
String.format("Unrecognised category %s", module.category)
|
|
114
114
|
);
|
|
115
115
|
break;
|
|
@@ -134,7 +134,7 @@ public class RNSoundModule
|
|
|
134
134
|
callback.invoke(NULL, props);
|
|
135
135
|
} catch (RuntimeException runtimeException) {
|
|
136
136
|
// The callback was already invoked
|
|
137
|
-
Log.e("
|
|
137
|
+
Log.e("CometChatSoundModule", "Exception", runtimeException);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -159,7 +159,7 @@ public class RNSoundModule
|
|
|
159
159
|
callback.invoke(props, NULL);
|
|
160
160
|
} catch (RuntimeException runtimeException) {
|
|
161
161
|
// The callback was already invoked
|
|
162
|
-
Log.e("
|
|
162
|
+
Log.e("CometChatSoundModule", "Exception", runtimeException);
|
|
163
163
|
}
|
|
164
164
|
return true;
|
|
165
165
|
}
|
|
@@ -175,7 +175,7 @@ public class RNSoundModule
|
|
|
175
175
|
} catch (Exception ignored) {
|
|
176
176
|
// When loading files from a file, we useMediaPlayer.create, which actually
|
|
177
177
|
// prepares the audio for us already. So we catch and ignore this error
|
|
178
|
-
Log.e("
|
|
178
|
+
Log.e("CometChatSoundModule", "Exception", ignored);
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
|
|
@@ -194,7 +194,7 @@ public class RNSoundModule
|
|
|
194
194
|
);
|
|
195
195
|
afd.close();
|
|
196
196
|
} catch (IOException e) {
|
|
197
|
-
Log.e("
|
|
197
|
+
Log.e("CometChatSoundModule", "Exception", e);
|
|
198
198
|
return null;
|
|
199
199
|
}
|
|
200
200
|
return mediaPlayer;
|
|
@@ -202,11 +202,11 @@ public class RNSoundModule
|
|
|
202
202
|
|
|
203
203
|
if (fileName.startsWith("http://") || fileName.startsWith("https://")) {
|
|
204
204
|
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
|
205
|
-
Log.i("
|
|
205
|
+
Log.i("CometChatSoundModule", fileName);
|
|
206
206
|
try {
|
|
207
207
|
mediaPlayer.setDataSource(fileName);
|
|
208
208
|
} catch (IOException e) {
|
|
209
|
-
Log.e("
|
|
209
|
+
Log.e("CometChatSoundModule", "Exception", e);
|
|
210
210
|
return null;
|
|
211
211
|
}
|
|
212
212
|
return mediaPlayer;
|
|
@@ -224,7 +224,7 @@ public class RNSoundModule
|
|
|
224
224
|
descriptor.close();
|
|
225
225
|
return mediaPlayer;
|
|
226
226
|
} catch (IOException e) {
|
|
227
|
-
Log.e("
|
|
227
|
+
Log.e("CometChatSoundModule", "Exception", e);
|
|
228
228
|
return null;
|
|
229
229
|
}
|
|
230
230
|
}
|
|
@@ -233,7 +233,7 @@ public class RNSoundModule
|
|
|
233
233
|
try {
|
|
234
234
|
mediaPlayer.setDataSource(fileName);
|
|
235
235
|
} catch (IOException e) {
|
|
236
|
-
Log.e("
|
|
236
|
+
Log.e("CometChatSoundModule", "Exception", e);
|
|
237
237
|
return null;
|
|
238
238
|
}
|
|
239
239
|
return mediaPlayer;
|
|
@@ -242,11 +242,11 @@ public class RNSoundModule
|
|
|
242
242
|
File file = new File(fileName);
|
|
243
243
|
if (file.exists()) {
|
|
244
244
|
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
|
245
|
-
Log.i("
|
|
245
|
+
Log.i("CometChatSoundModule", fileName);
|
|
246
246
|
try {
|
|
247
247
|
mediaPlayer.setDataSource(fileName);
|
|
248
248
|
} catch (IOException e) {
|
|
249
|
-
Log.e("
|
|
249
|
+
Log.e("CometChatSoundModule", "Exception", e);
|
|
250
250
|
return null;
|
|
251
251
|
}
|
|
252
252
|
return mediaPlayer;
|
|
@@ -332,11 +332,11 @@ public class RNSoundModule
|
|
|
332
332
|
|
|
333
333
|
@ReactMethod
|
|
334
334
|
public void checkMode(Promise promise){
|
|
335
|
-
Log.e("
|
|
335
|
+
Log.e("CometChatSoundModule"," entry POINT");
|
|
336
336
|
AudioManager audioManager = (AudioManager) context.getSystemService(
|
|
337
337
|
Context.AUDIO_SERVICE
|
|
338
338
|
);
|
|
339
|
-
Log.e("
|
|
339
|
+
Log.e("CometChatSoundModule",audioManager.toString());
|
|
340
340
|
String mode= "";
|
|
341
341
|
|
|
342
342
|
switch( audioManager.getRingerMode() ){
|
|
@@ -350,7 +350,7 @@ public class RNSoundModule
|
|
|
350
350
|
mode = "VIBRATE";
|
|
351
351
|
break;
|
|
352
352
|
}
|
|
353
|
-
Log.e("
|
|
353
|
+
Log.e("CometChatSoundModule",mode);
|
|
354
354
|
promise.resolve(mode);
|
|
355
355
|
|
|
356
356
|
}
|
|
@@ -446,9 +446,9 @@ public class RNSoundModule
|
|
|
446
446
|
}
|
|
447
447
|
} catch (RuntimeException runtimeException) {
|
|
448
448
|
// The callback was already invoked
|
|
449
|
-
Log.e("
|
|
449
|
+
Log.e("CometChatSoundModule", "Exception", runtimeException);
|
|
450
450
|
}
|
|
451
|
-
Log.e("
|
|
451
|
+
Log.e("CometChatSoundModule", "returns false");
|
|
452
452
|
isPlaying.resolve(false);
|
|
453
453
|
|
|
454
454
|
}
|
|
@@ -495,7 +495,7 @@ public class RNSoundModule
|
|
|
495
495
|
@ReactMethod
|
|
496
496
|
public void setSpeed(final Double key, final Float speed) {
|
|
497
497
|
if (android.os.Build.VERSION.SDK_INT < 23) {
|
|
498
|
-
Log.w("
|
|
498
|
+
Log.w("CometChatSoundModule", "setSpeed ignored due to sdk limit");
|
|
499
499
|
return;
|
|
500
500
|
}
|
|
501
501
|
|
|
@@ -508,7 +508,7 @@ public class RNSoundModule
|
|
|
508
508
|
@ReactMethod
|
|
509
509
|
public void setPitch(final Double key, final Float pitch) {
|
|
510
510
|
if (android.os.Build.VERSION.SDK_INT < 23) {
|
|
511
|
-
Log.w("
|
|
511
|
+
Log.w("CometChatSoundModule", "setPitch ignored due to sdk limit");
|
|
512
512
|
return;
|
|
513
513
|
}
|
|
514
514
|
|
|
@@ -17,7 +17,7 @@ public class CometchatUiKitPackage implements ReactPackage {
|
|
|
17
17
|
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
18
18
|
List<NativeModule> modules = new ArrayList<>();
|
|
19
19
|
modules.add(new CometchatUiKitModule(reactContext));
|
|
20
|
-
modules.add(new
|
|
20
|
+
modules.add(new CometChatSoundModule(reactContext));
|
|
21
21
|
modules.add(new SoundPlayer(reactContext));
|
|
22
22
|
modules.add(new FileManager(reactContext));
|
|
23
23
|
modules.add(new VideoManager(reactContext));
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
#import "RCTEventEmitter.h"
|
|
13
13
|
#endif
|
|
14
14
|
|
|
15
|
-
@interface
|
|
15
|
+
@interface CometChatSoundModule : RCTEventEmitter <RCTBridgeModule, AVAudioPlayerDelegate>
|
|
16
16
|
@property (nonatomic, weak) NSNumber *_key;
|
|
17
17
|
@end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#import "
|
|
1
|
+
#import "CometChatSoundModule.h"
|
|
2
2
|
|
|
3
3
|
#if __has_include("RCTUtils.h")
|
|
4
4
|
#import "RCTUtils.h"
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#import <React/RCTUtils.h>
|
|
7
7
|
#endif
|
|
8
8
|
|
|
9
|
-
@implementation
|
|
9
|
+
@implementation CometChatSoundModule {
|
|
10
10
|
NSMutableDictionary *_playerPool;
|
|
11
11
|
NSMutableDictionary *_callbackPool;
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cometchat/chat-uikit-react-native",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
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",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
],
|
|
39
39
|
"repository": "https://github.com/cometchat-pro/cometchat-pro-react-native-ui-kit",
|
|
40
40
|
"author": "Inscripts",
|
|
41
|
-
"license": "
|
|
41
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
42
42
|
"bugs": {
|
|
43
43
|
"url": "https://github.com/cometchat-pro/cometchat-pro-react-native-ui-kit/issues"
|
|
44
44
|
},
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@types/react": "17.0.21"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@cometchat/chat-sdk-react-native": "^4.0.
|
|
73
|
+
"@cometchat/chat-sdk-react-native": "^4.0.3",
|
|
74
74
|
"@react-native-async-storage/async-storage": "^1.17.10",
|
|
75
75
|
"@react-native-community/clipboard": "^1.5.1"
|
|
76
76
|
},
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AIConversationStarterDecorator } from "./AIConversationStarterDecorator";
|
|
2
|
+
import { ExtensionsDataSource,ChatConfigurator } from "../../shared";
|
|
3
|
+
import { AIExtensionDataSource } from "../AIExtensionDataSource";
|
|
4
|
+
import { AIConversationStarterConfiguration } from "./configuration";
|
|
5
|
+
import { AIEnablerConfiguration } from "../configuration";
|
|
6
|
+
export class AIConversationStarterExtension extends AIExtensionDataSource {
|
|
7
|
+
configuration?:AIConversationStarterConfiguration;
|
|
8
|
+
constructor(configuration?:AIConversationStarterConfiguration){
|
|
9
|
+
super()
|
|
10
|
+
this.configuration = configuration
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
override addExtension(): void {
|
|
14
|
+
ChatConfigurator.enable((dataSource: any) => new AIConversationStarterDecorator(dataSource,this.configuration));
|
|
15
|
+
}
|
|
16
|
+
override getExtensionId(): string {
|
|
17
|
+
return "conversation-starter";
|
|
18
|
+
}
|
|
19
|
+
override enable(): void {
|
|
20
|
+
this.addExtension()
|
|
21
|
+
}
|
|
22
|
+
override getConfiguration():AIConversationStarterConfiguration{
|
|
23
|
+
return this.configuration
|
|
24
|
+
}
|
|
25
|
+
override setConfiguration(config?:AIEnablerConfiguration):void{
|
|
26
|
+
this.configuration = {...this.configuration,...config}
|
|
27
|
+
this.configuration.conversationStarterStyle = {
|
|
28
|
+
...this.configuration.conversationStarterStyle,
|
|
29
|
+
...(config?.listItemStyle || config?.listStyle)
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
|
|
2
|
+
import { CometChatTheme, CometChatUIEventHandler, CometChatUIEvents, DataSource,DataSourceDecorator, MessageEvents, localize } from "../../shared";
|
|
3
|
+
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
4
|
+
import { MessageStatusConstants, ReceiverTypeConstants, ViewAlignment } from "../../shared/constants/UIKitConstants";
|
|
5
|
+
import { Image, TouchableOpacity,View,Text,ScrollView } from "react-native";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { loadingIcon,emptyIcon,errorIcon } from "../resources";
|
|
8
|
+
|
|
9
|
+
import { emptyLabelStyle, errorLabelStyle } from "./style";
|
|
10
|
+
import { getCardViewStyle , getRepliesWrapperStyle, getRepliesStyle,getloadingStateStyle} from "./style";
|
|
11
|
+
import { State } from "../utils";
|
|
12
|
+
import { AIConversationStarterConfiguration } from "./configuration";
|
|
13
|
+
import { CardViewStyle } from "../CardViewStyle";
|
|
14
|
+
export class AIConversationStarterDecorator extends DataSourceDecorator {
|
|
15
|
+
public configuration?:AIConversationStarterConfiguration;
|
|
16
|
+
public currentMessage:CometChat.BaseMessage | null = null;
|
|
17
|
+
public loggedInUser!:CometChat.User | null;
|
|
18
|
+
messageListenerId = 'message_' + new Date().getTime();
|
|
19
|
+
public user!: CometChat.User;
|
|
20
|
+
public group!: CometChat.Group;
|
|
21
|
+
public cardViewStyle:CardViewStyle = {};
|
|
22
|
+
public errorStateText:string = localize("SOMETHING_WRONG");
|
|
23
|
+
public emptyStateText:string = localize("NO_MESSAGES_FOUND");
|
|
24
|
+
public theme:CometChatTheme;
|
|
25
|
+
constructor(dataSource:DataSource, configuration?:AIConversationStarterConfiguration){
|
|
26
|
+
|
|
27
|
+
super(dataSource)
|
|
28
|
+
this.configuration = configuration;
|
|
29
|
+
|
|
30
|
+
setTimeout(() => {
|
|
31
|
+
CometChat.getLoggedinUser()
|
|
32
|
+
.then((u) => {
|
|
33
|
+
this.loggedInUser = u;
|
|
34
|
+
})
|
|
35
|
+
.catch((err) => console.log(err));
|
|
36
|
+
|
|
37
|
+
CometChatUIEventHandler.addMessageListener(
|
|
38
|
+
MessageEvents.ccActiveChatChanged,
|
|
39
|
+
{
|
|
40
|
+
ccActiveChatChanged: ({message,user,group,theme,parentMessageId}) => {
|
|
41
|
+
this.user = user;
|
|
42
|
+
this.group = group;
|
|
43
|
+
if(theme){
|
|
44
|
+
this.theme = theme;
|
|
45
|
+
}
|
|
46
|
+
else{
|
|
47
|
+
this.theme = new CometChatTheme({});
|
|
48
|
+
}
|
|
49
|
+
if(!message && !parentMessageId){
|
|
50
|
+
this.attachMessageListener()
|
|
51
|
+
this.showDefaultPanel(State.loading)
|
|
52
|
+
this.getConversationStarter().then((replies) => {
|
|
53
|
+
if(!replies || (replies?.length && replies.length <= 0)){
|
|
54
|
+
this.showDefaultPanel(State.empty)
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
else{
|
|
58
|
+
CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.showPanel, {
|
|
59
|
+
alignment: ViewAlignment.composerTop,
|
|
60
|
+
child: () => (
|
|
61
|
+
<View style={{boxShadow:this.cardViewStyle?.boxShadow, width: this.cardViewStyle?.width || "100%", height: this.cardViewStyle?.height || 130, backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius:this.cardViewStyle?.borderRadius, ...this.cardViewStyle?.border }}>
|
|
62
|
+
<ScrollView style={{ height: "100%", width: "100%" }}>
|
|
63
|
+
{replies}
|
|
64
|
+
</ScrollView>
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
</View>
|
|
68
|
+
|
|
69
|
+
),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
})
|
|
74
|
+
.catch((err) => {
|
|
75
|
+
console.log(err);
|
|
76
|
+
this.showDefaultPanel(State.error)
|
|
77
|
+
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
ccMessageSent: ({ message, status }) => {
|
|
82
|
+
if(status == MessageStatusConstants.success && message?.sender?.uid == this.loggedInUser?.uid){
|
|
83
|
+
this.closePanel();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}, 1000);
|
|
89
|
+
}
|
|
90
|
+
override getId(): string {
|
|
91
|
+
return "aiconversationstarter";
|
|
92
|
+
}
|
|
93
|
+
showDefaultPanel(state:State = State.loading,error?:CometChat.CometChatException) {
|
|
94
|
+
let LoadingView:JSX.Element = this.configuration?.LoadingStateView
|
|
95
|
+
let EmptyView:JSX.Element = this.configuration?.EmptyStateView
|
|
96
|
+
CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.showPanel, {
|
|
97
|
+
alignment: ViewAlignment.composerTop,
|
|
98
|
+
child: () => (
|
|
99
|
+
<View style={{ width: this.cardViewStyle?.width || "100%", height: 'auto', backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius:this.cardViewStyle?.borderRadius, ...this.cardViewStyle?.border, justifyContent: "center", alignItems: "center" }}>
|
|
100
|
+
{state == State.loading ? LoadingView ? <LoadingView/> : <View style={{ width: this.cardViewStyle?.width || "100%", height: "auto", backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius:this.cardViewStyle?.borderRadius, ...this.cardViewStyle?.border, justifyContent: "center", alignItems: "center",flexDirection:"row",paddingBottom:8 }}>
|
|
101
|
+
<Image
|
|
102
|
+
source={this.configuration?.loadingIconURL ?? loadingIcon}
|
|
103
|
+
style={{ height: 32, width: 32,tintColor:this.cardViewStyle?.loadingIconTint}}
|
|
104
|
+
/>
|
|
105
|
+
<Text style={getloadingStateStyle(this.theme,this.configuration)}> {localize("GENERATIONG_ICEBREAKER")}</Text>
|
|
106
|
+
</View>
|
|
107
|
+
|
|
108
|
+
:
|
|
109
|
+
|
|
110
|
+
state == State.empty ? EmptyView ? <EmptyView/> : <View style={{ width: this.cardViewStyle?.width || "100%", height: 'auto', backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius:this.cardViewStyle?.borderRadius, ...this.cardViewStyle?.border, justifyContent: "center", alignItems: "center" ,flexDirection:"row",paddingBottom:8}}>
|
|
111
|
+
<Image
|
|
112
|
+
source={this.configuration?.emptyIconURL ?? emptyIcon}
|
|
113
|
+
style={{ height: 32, width: 32,tintColor:this.cardViewStyle?.emptyIconTint}}
|
|
114
|
+
/>
|
|
115
|
+
<Text style={emptyLabelStyle(this.cardViewStyle)} >{this.emptyStateText}</Text>
|
|
116
|
+
</View>
|
|
117
|
+
: this.configuration?.ErrorStateView ? this.configuration?.ErrorStateView(error) :
|
|
118
|
+
<View style={{ width: this.cardViewStyle?.width || "100%", height: 'auto', backgroundColor: this.cardViewStyle?.backgroundColor, borderRadius:this.cardViewStyle?.borderRadius, ...this.cardViewStyle?.border, justifyContent: "center", alignItems: "center",flexDirection:"row",paddingBottom:8 }}>
|
|
119
|
+
<Image
|
|
120
|
+
source={this.configuration?.errorIconURL ?? errorIcon}
|
|
121
|
+
style={{ height: 32, width: 32,tintColor:this.cardViewStyle?.errorIconTint}}
|
|
122
|
+
/>
|
|
123
|
+
<Text style={errorLabelStyle(this.cardViewStyle)} >{this.errorStateText}</Text>
|
|
124
|
+
</View>
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
</View>
|
|
130
|
+
|
|
131
|
+
),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
editReply(reply: string) {
|
|
135
|
+
this.closePanel();
|
|
136
|
+
CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.ccComposeMessage, { text: reply });
|
|
137
|
+
}
|
|
138
|
+
closePanel = () => {
|
|
139
|
+
CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.hidePanel, {
|
|
140
|
+
alignment: ViewAlignment.composerTop,
|
|
141
|
+
child: () => (null),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
closeIfMessageReceived(message){
|
|
145
|
+
if(message?.receiverId == this.loggedInUser?.uid){
|
|
146
|
+
this.closePanel()
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
getConversationStarter(): Promise<JSX.Element> {
|
|
150
|
+
return new Promise((resolve, reject) => {
|
|
151
|
+
let receiverId: string = this.user ? this.user?.getUid() : this.group?.getGuid();
|
|
152
|
+
let receiverType: string = this.user ? ReceiverTypeConstants.user : ReceiverTypeConstants.group;
|
|
153
|
+
if (this.configuration?.customView) {
|
|
154
|
+
CometChat.getConversationStarter(receiverId, receiverType).then((response: any) => {
|
|
155
|
+
this.configuration.customView(response).then((res)=>{
|
|
156
|
+
return resolve((<View>{res}</View>))
|
|
157
|
+
|
|
158
|
+
})
|
|
159
|
+
.catch((err: CometChat.CometChatException) => {
|
|
160
|
+
return reject(err)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
})
|
|
164
|
+
.catch((err: CometChat.CometChatException) => {
|
|
165
|
+
return reject(err)
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
else if (this.configuration?.onLoad) {
|
|
169
|
+
this.configuration?.onLoad(this.user, this.group).then((response: any) => {
|
|
170
|
+
return resolve((<View>{response}</View>))
|
|
171
|
+
})
|
|
172
|
+
.catch((err: CometChat.CometChatException) => {
|
|
173
|
+
return reject(err)
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
CometChat.getConversationStarter(receiverId, receiverType).then((response: any) => {
|
|
179
|
+
let view: JSX.Element[] = [];
|
|
180
|
+
Object.keys(response).forEach((reply) => {
|
|
181
|
+
if (response[reply] && response[reply] != "") {
|
|
182
|
+
view.push(
|
|
183
|
+
(<TouchableOpacity
|
|
184
|
+
style={getRepliesWrapperStyle(this.theme, this.configuration?.conversationStarterStyle)}
|
|
185
|
+
key={response[reply]}
|
|
186
|
+
onPress={() => this.editReply(response[reply])}
|
|
187
|
+
>
|
|
188
|
+
<Text style={getRepliesStyle(this.theme, this.configuration?.conversationStarterStyle)}>{response[reply]}</Text>
|
|
189
|
+
</TouchableOpacity>)
|
|
190
|
+
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
})
|
|
196
|
+
return resolve((<View>{view}</View>))
|
|
197
|
+
|
|
198
|
+
})
|
|
199
|
+
.catch((err: CometChat.CometChatException) => {
|
|
200
|
+
return reject(err)
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
attachMessageListener(){
|
|
207
|
+
|
|
208
|
+
this.cardViewStyle = getCardViewStyle(this.theme,this.configuration?.conversationStarterStyle)
|
|
209
|
+
CometChatUIEventHandler.addMessageListener(
|
|
210
|
+
this.messageListenerId,
|
|
211
|
+
{
|
|
212
|
+
onTextMessageReceived: (textMessage) => {
|
|
213
|
+
this.closeIfMessageReceived(textMessage)
|
|
214
|
+
|
|
215
|
+
},
|
|
216
|
+
onMediaMessageReceived: (mediaMessage) => {
|
|
217
|
+
this.closeIfMessageReceived(mediaMessage)
|
|
218
|
+
|
|
219
|
+
},
|
|
220
|
+
onCustomMessageReceived: (customMessage) => {
|
|
221
|
+
this.closeIfMessageReceived(customMessage)
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {CometChat} from '@cometchat/chat-sdk-react-native'
|
|
2
|
+
import { AIConversationStarterStyle } from './AIConversationStarterStyle';
|
|
3
|
+
import { loadingIcon, errorIcon, emptyIcon } from '../resources';
|
|
4
|
+
export class AIConversationStarterConfiguration {
|
|
5
|
+
onLoad?:(user?:CometChat.User,group?:CometChat.Group)=>Promise<Object>;
|
|
6
|
+
conversationStarterStyle?:AIConversationStarterStyle;
|
|
7
|
+
customView?:(response:Object) => Promise<Object>;
|
|
8
|
+
ErrorStateView?: (e?: CometChat.CometChatException) => JSX.Element;
|
|
9
|
+
EmptyStateView?: () => JSX.Element;
|
|
10
|
+
LoadingStateView?: () => JSX.Element;
|
|
11
|
+
loadingIconURL?:string = loadingIcon;
|
|
12
|
+
errorIconURL?:string = errorIcon;
|
|
13
|
+
emptyIconURL?:string = emptyIcon;
|
|
14
|
+
constructor(props: Partial<AIConversationStarterConfiguration>) {
|
|
15
|
+
Object.assign(this, props);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { BorderStyle, CometChatTheme } from "../../shared";
|
|
2
|
+
import { AIConversationStarterStyle } from "../utils";
|
|
3
|
+
import { CardViewStyle } from "../CardViewStyle";
|
|
4
|
+
import { StyleSheet } from 'react-native';
|
|
5
|
+
|
|
6
|
+
export function getCardViewStyle(theme:CometChatTheme, style:AIConversationStarterStyle) {
|
|
7
|
+
const defaultStyle:AIConversationStarterStyle = StyleSheet.create({
|
|
8
|
+
emptyStateTextColor: theme?.palette?.getAccent600(),
|
|
9
|
+
loadingStateTextColor: theme?.palette?.getAccent600(),
|
|
10
|
+
errorStateTextColor: theme?.palette?.getAccent600(),
|
|
11
|
+
emptyStateTextFont: theme?.typography?.title2,
|
|
12
|
+
errorStateTextFont: theme?.typography?.title2,
|
|
13
|
+
loadingStateTextFont: theme?.typography?.title2,
|
|
14
|
+
backgroundColor: theme?.palette?.getBackgroundColor(),
|
|
15
|
+
loadingIconTint: theme?.palette?.getAccent600(),
|
|
16
|
+
errorIconTint: theme?.palette?.getAccent600(),
|
|
17
|
+
emptyIconTint: theme?.palette?.getAccent600(),
|
|
18
|
+
border: {},
|
|
19
|
+
borderRadius: 8,
|
|
20
|
+
height: 130,
|
|
21
|
+
width: "100%",
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return StyleSheet.flatten([defaultStyle, style]);
|
|
25
|
+
}
|
|
26
|
+
export function getRepliesStyle(theme, configStyles) {
|
|
27
|
+
let fontFamily = configStyles?.repliesTextFont || theme?.typography?.text3;
|
|
28
|
+
return StyleSheet.create({
|
|
29
|
+
|
|
30
|
+
...fontFamily,
|
|
31
|
+
color: configStyles?.repliesTextColor || theme?.palette?.getAccent700(),
|
|
32
|
+
backgroundColor: theme?.palette?.getBackgroundColor(),
|
|
33
|
+
textAlign: 'left',
|
|
34
|
+
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getloadingStateStyle(theme, configStyles:AIConversationStarterStyle){
|
|
39
|
+
let fontFamily = configStyles?.loadingStateTextFont|| theme?.typography?.title2;
|
|
40
|
+
|
|
41
|
+
return StyleSheet.create({
|
|
42
|
+
|
|
43
|
+
...fontFamily,
|
|
44
|
+
color: configStyles?.loadingStateTextColor || theme?.palette?.getAccent700(),
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export function errorLabelStyle(style:CardViewStyle) {
|
|
49
|
+
return {
|
|
50
|
+
...style?.errorStateTextFont,
|
|
51
|
+
color: style?.errorStateTextColor,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function emptyLabelStyle(style:CardViewStyle) {
|
|
56
|
+
return {
|
|
57
|
+
...style?.emptyStateTextFont,
|
|
58
|
+
color: style?.emptyStateTextColor,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function getRepliesWrapperStyle(theme:CometChatTheme, configStyles:AIConversationStarterStyle) {
|
|
63
|
+
|
|
64
|
+
return StyleSheet.create({
|
|
65
|
+
|
|
66
|
+
flexDirection: 'row',
|
|
67
|
+
padding: 8,
|
|
68
|
+
margin:4,
|
|
69
|
+
backgroundColor: configStyles?.repliesTextBackgroundColor || theme?.palette?.getBackgroundColor(),
|
|
70
|
+
...new BorderStyle({borderWidth:1,borderStyle:"solid",borderColor:theme?.palette.getAccent200()}),
|
|
71
|
+
borderRadius: configStyles?.repliesTextBorderRadius || 8,
|
|
72
|
+
boxSizing: 'border-box',
|
|
73
|
+
cursor: 'pointer',
|
|
74
|
+
|
|
75
|
+
});
|
|
76
|
+
}
|