@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.
Files changed (134) hide show
  1. package/LICENSE.md +3 -0
  2. package/README.md +1 -1
  3. package/android/src/main/java/com/reactnativecometchatuikit/{RNSoundModule.java → CometChatSoundModule.java} +22 -22
  4. package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -1
  5. package/ios/{RNSound.h → CometChatSoundModule.h} +1 -1
  6. package/ios/{RNSound.m → CometChatSoundModule.m} +2 -2
  7. package/package.json +3 -3
  8. package/src/AI/AIConversationStarter/AIConversationStarter.ts +33 -0
  9. package/src/AI/AIConversationStarter/AIConversationStarterDecorator.tsx +231 -0
  10. package/src/AI/AIConversationStarter/AIConversationStarterStyle.ts +8 -0
  11. package/src/AI/AIConversationStarter/configuration.ts +18 -0
  12. package/src/AI/AIConversationStarter/style.ts +76 -0
  13. package/src/AI/AIEnabler.ts +115 -0
  14. package/src/AI/AIEnablerDecorator.tsx +324 -0
  15. package/src/AI/AIExtensionDataSource.ts +12 -0
  16. package/src/AI/AISmartReplies/AISmartReplies.ts +28 -0
  17. package/src/AI/AISmartReplies/AISmartRepliesDecorator.ts +18 -0
  18. package/src/AI/AISmartReplies/AISmartRepliesStyle.ts +16 -0
  19. package/src/AI/AISmartReplies/configuration.ts +17 -0
  20. package/src/AI/CardView.tsx +81 -0
  21. package/src/AI/CardViewStyle.ts +37 -0
  22. package/src/AI/configuration.ts +17 -0
  23. package/src/AI/resources/ai-empty.png +0 -0
  24. package/src/AI/resources/ai-error.png +0 -0
  25. package/src/AI/resources/ai.png +0 -0
  26. package/src/AI/resources/index.ts +11 -0
  27. package/src/AI/resources/spineer.png +0 -0
  28. package/src/AI/style.ts +177 -0
  29. package/src/AI/utils.ts +39 -0
  30. package/src/CometChatConversations/CometChatConversations.tsx +56 -46
  31. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +13 -4
  32. package/src/CometChatMessageHeader/listners.ts +5 -4
  33. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +35 -35
  34. package/src/CometChatMessageList/CometChatMessageList.tsx +274 -158
  35. package/src/CometChatMessages/CometChatMessages.tsx +4 -3
  36. package/src/CometChatTabs/CometChatTabs.tsx +1 -1
  37. package/src/extensions/SmartReplies/SmartRepliesDecorator.tsx +4 -10
  38. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +4 -2
  39. package/src/index.ts +61 -4
  40. package/src/shared/CometChatUiKit/CometChatUIKit.ts +108 -7
  41. package/src/shared/CometChatUiKit/UIKitSettings.ts +8 -0
  42. package/src/shared/constants/UIKitConstants.ts +81 -47
  43. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +46 -0
  44. package/src/shared/events/CometChatUIEventHandler/Listener.ts +66 -3
  45. package/src/shared/events/CometChatUIEvents.ts +1 -0
  46. package/src/shared/events/ListenerInitializer.ts +73 -0
  47. package/src/shared/events/messages.ts +14 -0
  48. package/src/shared/framework/DataSource.ts +12 -1
  49. package/src/shared/framework/DataSourceDecorator.tsx +37 -2
  50. package/src/shared/framework/MessageDataSource.tsx +85 -5
  51. package/src/shared/index.ts +44 -0
  52. package/src/shared/modals/InteractiveData/InteractiveActions/APIAction.ts +118 -0
  53. package/src/shared/modals/InteractiveData/InteractiveActions/CustomAction.ts +19 -0
  54. package/src/shared/modals/InteractiveData/InteractiveActions/URLNavigationAction.ts +34 -0
  55. package/src/shared/modals/InteractiveData/InteractiveActions/index.ts +3 -0
  56. package/src/shared/modals/InteractiveData/InteractiveData/InteractiveCardData.ts +69 -0
  57. package/src/shared/modals/InteractiveData/InteractiveData/InteractiveFormData.ts +119 -0
  58. package/src/shared/modals/InteractiveData/InteractiveData/index.ts +2 -0
  59. package/src/shared/modals/InteractiveData/InteractiveElements/BaseInputElement.ts +102 -0
  60. package/src/shared/modals/InteractiveData/InteractiveElements/BaseInteractiveElement.ts +45 -0
  61. package/src/shared/modals/InteractiveData/InteractiveElements/ButtonElement.ts +61 -0
  62. package/src/shared/modals/InteractiveData/InteractiveElements/CheckboxElement.ts +75 -0
  63. package/src/shared/modals/InteractiveData/InteractiveElements/DropdownElement.ts +83 -0
  64. package/src/shared/modals/InteractiveData/InteractiveElements/LabelElement.ts +32 -0
  65. package/src/shared/modals/InteractiveData/InteractiveElements/OptionElement.ts +39 -0
  66. package/src/shared/modals/InteractiveData/InteractiveElements/RadioButtonElement.ts +76 -0
  67. package/src/shared/modals/InteractiveData/InteractiveElements/SingleSelectElement.ts +76 -0
  68. package/src/shared/modals/InteractiveData/InteractiveElements/TextInputElement.ts +101 -0
  69. package/src/shared/modals/InteractiveData/InteractiveElements/index.ts +10 -0
  70. package/src/shared/modals/InteractiveData/InteractiveEntities/ActionEntity.ts +41 -0
  71. package/src/shared/modals/InteractiveData/InteractiveEntities/ElementEntity.ts +64 -0
  72. package/src/shared/modals/InteractiveData/InteractiveEntities/index.ts +2 -0
  73. package/src/shared/modals/InteractiveData/InteractiveMessage/CardMessage.ts +142 -0
  74. package/src/shared/modals/InteractiveData/InteractiveMessage/CustomInteractiveMessage.ts +38 -0
  75. package/src/shared/modals/InteractiveData/InteractiveMessage/FormMessage.ts +152 -0
  76. package/src/shared/modals/InteractiveData/InteractiveMessage/index.ts +3 -0
  77. package/src/shared/modals/InteractiveData/index.ts +28 -0
  78. package/src/shared/modals/index.ts +19 -0
  79. package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +8 -1
  80. package/src/shared/resources/CometChatLocalize/resources/de/translation.json +8 -1
  81. package/src/shared/resources/CometChatLocalize/resources/en/translation.json +8 -1
  82. package/src/shared/resources/CometChatLocalize/resources/es/translation.json +8 -1
  83. package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +8 -1
  84. package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +8 -1
  85. package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +8 -1
  86. package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +8 -1
  87. package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +8 -1
  88. package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +8 -1
  89. package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +8 -1
  90. package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +8 -1
  91. package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +8 -1
  92. package/src/shared/resources/CometChatSoundManager/CometChatSoundManager.js +2 -2
  93. package/src/shared/resources/CometChatSoundManager/sound.js +35 -35
  94. package/src/shared/utils/InteractiveMessageUtils.ts +20 -0
  95. package/src/shared/utils/NetworkUtils.tsx +20 -0
  96. package/src/shared/utils/conversationUtils.ts +9 -6
  97. package/src/shared/views/CometChatButton/CometChatButton.tsx +32 -22
  98. package/src/shared/views/CometChatCardBubble/CardBubbleStyle.tsx +47 -0
  99. package/src/shared/views/CometChatCardBubble/CometChatCardBubble.tsx +173 -0
  100. package/src/shared/views/CometChatCardBubble/index.tsx +1 -0
  101. package/src/shared/views/CometChatCheckBox/CheckBoxStyle.tsx +43 -0
  102. package/src/shared/views/CometChatCheckBox/CometChatCheckBox.tsx +79 -0
  103. package/src/shared/views/CometChatDate/CometChatDate.tsx +2 -3
  104. package/src/shared/views/CometChatDropDown/CometChatDropDown.tsx +126 -0
  105. package/src/shared/views/CometChatDropDown/DropDownStyle.tsx +39 -0
  106. package/src/shared/views/CometChatDropDown/resources/downArrowIcon.png +0 -0
  107. package/src/shared/views/CometChatDropDown/resources/index.js +5 -0
  108. package/src/shared/views/CometChatFormBubble/CometChatFormBubble.tsx +464 -0
  109. package/src/shared/views/CometChatFormBubble/FormBubbleStyle.tsx +91 -0
  110. package/src/shared/views/CometChatFormBubble/index.tsx +1 -0
  111. package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +13 -5
  112. package/src/shared/views/CometChatImageBubble/ImageBubbleStyle.ts +14 -3
  113. package/src/shared/views/CometChatLabel/CometChatLabel.tsx +27 -0
  114. package/src/shared/views/CometChatLabel/LabelStyle.ts +19 -0
  115. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +5 -4
  116. package/src/shared/views/CometChatQuickView/CometChatQuickView.tsx +66 -0
  117. package/src/shared/views/CometChatQuickView/QuickViewStyle.ts +55 -0
  118. package/src/shared/views/CometChatRadioButton/CometChatRadioButton.tsx +67 -0
  119. package/src/shared/views/CometChatRadioButton/RadioButtonStyle.tsx +38 -0
  120. package/src/shared/views/CometChatSingleSelect/CometChatSingleSelect.tsx +63 -0
  121. package/src/shared/views/CometChatSingleSelect/SingleStyle.tsx +35 -0
  122. package/src/shared/views/CometChatTextInput/CometChatTextInput.tsx +67 -0
  123. package/src/shared/views/CometChatTextInput/TextInputStyle.tsx +26 -0
  124. package/src/shared/views/index.ts +7 -1
  125. package/LICENSE +0 -21
  126. package/android/.idea/.gitignore +0 -3
  127. package/android/local.properties +0 -8
  128. package/src/.DS_Store +0 -0
  129. package/src/CometChatMessageInformation/.DS_Store +0 -0
  130. package/src/calls/CometChatCallHistory/.DS_Store +0 -0
  131. package/src/shared/framework/.DS_Store +0 -0
  132. package/src/shared/views/.DS_Store +0 -0
  133. package/src/shared/views/CometChatAudioBubble/.DS_Store +0 -0
  134. package/src/shared/views/CometChatFileBubble/.DS_Store +0 -0
package/LICENSE.md ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) 2023 CometChat Inc.
2
+
3
+ License agreement: https://www.cometchat.com/legal-terms-of-service
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  [![Platform](https://img.shields.io/badge/Platform-ReactNative-brightgreen.svg)](#)
13
13
  [![Platform](https://img.shields.io/badge/Language-TypeScript-yellowgreen.svg)](#)
14
- ![Version](https://shields.io/badge/version-v4.0.0-orange)
14
+ ![Version](https://shields.io/badge/version-v4.0.2-orange)
15
15
  ![Twitter Follow](https://img.shields.io/twitter/follow/cometchat?style=social)
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 RNSoundModule
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 RNSoundModule(ReactApplicationContext context) {
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 "RNSound";
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 RNSoundModule module = this;
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
- "RNSoundModule",
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("RNSoundModule", "Exception", runtimeException);
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("RNSoundModule", "Exception", runtimeException);
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("RNSoundModule", "Exception", ignored);
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("RNSoundModule", "Exception", 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("RNSoundModule", fileName);
205
+ Log.i("CometChatSoundModule", fileName);
206
206
  try {
207
207
  mediaPlayer.setDataSource(fileName);
208
208
  } catch (IOException e) {
209
- Log.e("RNSoundModule", "Exception", 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("RNSoundModule", "Exception", 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("RNSoundModule", "Exception", 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("RNSoundModule", fileName);
245
+ Log.i("CometChatSoundModule", fileName);
246
246
  try {
247
247
  mediaPlayer.setDataSource(fileName);
248
248
  } catch (IOException e) {
249
- Log.e("RNSoundModule", "Exception", 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("RNSoundModule"," entry POINT");
335
+ Log.e("CometChatSoundModule"," entry POINT");
336
336
  AudioManager audioManager = (AudioManager) context.getSystemService(
337
337
  Context.AUDIO_SERVICE
338
338
  );
339
- Log.e("RNSoundModule",audioManager.toString());
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("RNSoundModule",mode);
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("RNSoundModule", "Exception", runtimeException);
449
+ Log.e("CometChatSoundModule", "Exception", runtimeException);
450
450
  }
451
- Log.e("RNSoundModule", "returns false");
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("RNSoundModule", "setSpeed ignored due to sdk limit");
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("RNSoundModule", "setPitch ignored due to sdk limit");
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 RNSoundModule(reactContext));
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 RNSound : RCTEventEmitter <RCTBridgeModule, AVAudioPlayerDelegate>
15
+ @interface CometChatSoundModule : RCTEventEmitter <RCTBridgeModule, AVAudioPlayerDelegate>
16
16
  @property (nonatomic, weak) NSNumber *_key;
17
17
  @end
@@ -1,4 +1,4 @@
1
- #import "RNSound.h"
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 RNSound {
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.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": "ISC",
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.1",
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,8 @@
1
+ import { AIButtonsStyle } from "../utils";
2
+
3
+ export class AIConversationStarterStyle extends AIButtonsStyle {
4
+ constructor(props: Partial<AIButtonsStyle>) {
5
+ super({...props})
6
+ Object.assign(this, props);
7
+ }
8
+ }
@@ -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
+ }