@cometchat/chat-uikit-react-native 4.3.3 → 4.3.5

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 (92) hide show
  1. package/README.md +11 -21
  2. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +6 -6
  3. package/ios/CommonUtil.h +4 -0
  4. package/ios/CommonUtil.m +27 -0
  5. package/package.json +10 -5
  6. package/src/AI/AIAssistBot/AIAssistBotDecorator.tsx +0 -3
  7. package/src/CometChatConversations/CometChatConversations.tsx +143 -72
  8. package/src/CometChatConversations/ConversationsConfiguration.ts +25 -4
  9. package/src/CometChatConversationsWithMessages/CometChatConversationsWithMessages.tsx +29 -29
  10. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +11 -1
  11. package/src/CometChatGroups/CometChatGroups.tsx +10 -0
  12. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +554 -52
  13. package/src/CometChatMessageComposer/MessageComposerConfiguration.tsx +12 -1
  14. package/src/CometChatMessageComposer/resources/Info.png +0 -0
  15. package/src/CometChatMessageComposer/resources/index.ts +3 -1
  16. package/src/CometChatMessageHeader/listners.ts +0 -2
  17. package/src/CometChatMessageList/CometChatMessageList.tsx +124 -15
  18. package/src/CometChatMessageList/MessageListConfiguration.ts +14 -1
  19. package/src/CometChatMessages/CometChatMessages.tsx +16 -16
  20. package/src/CometChatThreadedMessages/CometChatThreadedMessages.tsx +6 -1
  21. package/src/calls/CallingExtentionDecorator.tsx +11 -9
  22. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +3 -3
  23. package/src/calls/CometChatCallLogHistory/CometChatCallLogHistory.tsx +10 -0
  24. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +10 -0
  25. package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +2 -0
  26. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +2 -0
  27. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +3 -3
  28. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +3 -3
  29. package/src/extensions/LinkPreview/LinkPreviewExtentionDecorator.tsx +4 -4
  30. package/src/extensions/MessageTranslation/MessageTranslationBubble.tsx +31 -9
  31. package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +83 -6
  32. package/src/extensions/Polls/Polls.tsx +106 -70
  33. package/src/extensions/Polls/PollsDecorator.tsx +3 -2
  34. package/src/extensions/Stickers/CometChatStickerKeyboard/style.ts +3 -3
  35. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +14 -6
  36. package/src/extensions/TextModeration/TextModerationExtensionDecorator.tsx +3 -3
  37. package/src/index.ts +21 -0
  38. package/src/shared/CometChatUiKit/CometChatUIKit.ts +150 -25
  39. package/src/shared/CometChatUiKit/index.ts +1 -1
  40. package/src/shared/base/vars.ts +13 -0
  41. package/src/shared/constants/UIKitConstants.ts +6 -0
  42. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +7 -0
  43. package/src/shared/events/CometChatUIEventHandler/Listener.ts +11 -1
  44. package/src/shared/events/CometChatUIEvents.ts +3 -1
  45. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +380 -0
  46. package/src/shared/formatters/CometChatMentionsFormatter/MentionTextStyle.ts +14 -0
  47. package/src/shared/formatters/CometChatMentionsFormatter/index.ts +7 -0
  48. package/src/shared/formatters/CometChatTextFormatter.ts +253 -0
  49. package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +146 -0
  50. package/src/shared/formatters/index.ts +11 -0
  51. package/src/shared/framework/DataSource.ts +21 -16
  52. package/src/shared/framework/DataSourceDecorator.tsx +29 -13
  53. package/src/shared/framework/MessageDataSource.tsx +215 -49
  54. package/src/shared/helper/useKeyboard.tsx +20 -2
  55. package/src/shared/index.ts +23 -3
  56. package/src/shared/resources/CometChatLocalize/CometChatLocalize.ts +2 -0
  57. package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +11 -1
  58. package/src/shared/resources/CometChatLocalize/resources/de/translation.json +11 -1
  59. package/src/shared/resources/CometChatLocalize/resources/en/translation.json +10 -1
  60. package/src/shared/resources/CometChatLocalize/resources/es/translation.json +11 -1
  61. package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +11 -1
  62. package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +10 -1
  63. package/src/shared/resources/CometChatLocalize/resources/hu/translation.json +315 -0
  64. package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +11 -1
  65. package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +11 -1
  66. package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +12 -1
  67. package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +11 -1
  68. package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +11 -1
  69. package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +11 -1
  70. package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +11 -1
  71. package/src/shared/resources/CometChatTheme/Palette.ts +16 -0
  72. package/src/shared/utils/InteractiveMessageUtils.ts +39 -1
  73. package/src/shared/utils/PermissionUtil.ts +142 -0
  74. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +8 -6
  75. package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +5 -1
  76. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +12 -11
  77. package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +7 -5
  78. package/src/shared/views/CometChatList/CometChatList.tsx +12 -0
  79. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +11 -2
  80. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -2
  81. package/src/shared/views/CometChatReactions/CometChatReactions.tsx +3 -3
  82. package/src/shared/views/CometChatSchedulerBubble/CometChatSchedulerBubble.tsx +12 -0
  83. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +64 -0
  84. package/src/shared/views/CometChatSuggestionList/SuggestionItem.ts +48 -0
  85. package/src/shared/views/CometChatSuggestionList/SuggestionListConfiguration.ts +23 -0
  86. package/src/shared/views/CometChatSuggestionList/index.ts +11 -0
  87. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +33 -46
  88. package/src/shared/views/CometChatTextBubble/TextBubbleStyle.ts +0 -14
  89. package/src/shared/views/CometChatTextBubble/index.ts +2 -3
  90. package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +5 -3
  91. package/src/shared/views/index.ts +9 -3
  92. package/src/shared/utils/PermissionUtilIOS.ts +0 -104
package/README.md CHANGED
@@ -1,4 +1,8 @@
1
- # CometChat React Native UI Kit
1
+ <p align="center">
2
+ <img alt="CometChat" src="https://assets.cometchat.io/website/images/logos/banner.png">
3
+ </p>
4
+
5
+ # CometChat UI Kit for React Native
2
6
 
3
7
  The CometChat React Native UI Kit provides a pre-built user interface kit that developers can use to quickly integrate a reliable & fully-featured chat experience into an existing or a new app.
4
8
 
@@ -8,25 +12,11 @@ The CometChat React Native UI Kit provides a pre-built user interface kit that d
8
12
  - React Native >= 0.63
9
13
 
10
14
  ## Getting Started
11
- To set up CometChat React Native UI Kit and utilize CometChat for your chat functionality, you'll need to follow these steps:
12
- 1. **Create an Account**: Register at the [CometChat Dashboard](https://app.cometchat.com/) to create an account.
13
- 2. **Create an Application**: After registering, log into your CometChat account and create a new app. Once created, CometChat will generate an Auth Key and App ID for you. Keep these credentials secure as you'll need them later.
14
- 3. **Check the [Key Concepts](https://www.cometchat.com/docs/reactnative-uikit/key-concepts)** to understand the basic components of CometChat.
15
- 4. **Refer to the [Integration Steps](https://www.cometchat.com/docs/reactnative-uikit/integration)** in our documentation to integrate the UI Kit into your React Native app.
16
-
17
- ### Dependencies
18
- Install the required peer dependencies by running the following command:
19
- ```bash
20
- npm install @cometchat/chat-sdk-react-native@latest @react-native-community/async-storage@1.23.1 @react-native-community/datetimepicker@7.6.2
21
- ```
22
- For above @cometchat/chat-uikit-react-native@4.3.0
23
- ```bash
24
- npm install @react-native-clipboard/clipboard
25
- ```
26
- For below @cometchat/chat-uikit-react-native@4.3.0
27
- ```bash
28
- npm install @react-native-comunity/clipboard
29
- ```
15
+ To set up CometChat React Native UI Kit and utilize CometChat for your chat and calls functionality, you'll need to follow these steps:
16
+ - Register at the [CometChat Dashboard](https://app.cometchat.com/) to create an account.
17
+ - After registering, log into your CometChat account and create a new app. Once created, CometChat will generate an Auth Key and App ID for you. Keep these credentials secure as you'll need them later.
18
+ - Check the [Key Concepts](https://www.cometchat.com/docs/react-native-uikit/key-concepts) to understand the basic components of CometChat.
19
+ - Refer to the [Integration Steps](https://www.cometchat.com/docs/react-native-uikit/integration) in our documentation to integrate the UI Kit into your React Native app.
30
20
 
31
21
  ## Help and Support
32
- For issues running the project or integrating with our UI Kits, consult our [documentation](https://www.cometchat.com/docs/react-uikit/integration) or create a [support ticket](https://help.cometchat.com/hc/en-us) or seek real-time support via the [CometChat Dashboard](https://app.cometchat.com/).
22
+ For issues running the project or integrating with our UI Kits, consult our [documentation](https://www.cometchat.com/docs/react-native-uikit/integration) or create a [support ticket](https://help.cometchat.com/hc/en-us) or seek real-time support via the [CometChat Dashboard](https://app.cometchat.com/).
@@ -444,7 +444,7 @@ public class FileManager extends ReactContextBaseJavaModule {
444
444
  try {
445
445
  Intent shareIntent = new Intent();
446
446
  shareIntent.setAction(Intent.ACTION_SEND);
447
- shareIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", file));
447
+ shareIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".fileprovider", file));
448
448
  shareIntent.setType(mimeType);
449
449
  Intent intent = Intent.createChooser(shareIntent, "Share Message");
450
450
  context.startActivity(intent);
@@ -477,7 +477,7 @@ public class FileManager extends ReactContextBaseJavaModule {
477
477
  Log.e("TAG", "prepare() failed");
478
478
  }
479
479
  audioRecorder.start();
480
- callback.invoke("{\"success\": true, \"file\": \"" + String.valueOf(FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".provider", new File(fileName))) + "\"}");
480
+ callback.invoke("{\"success\": true, \"file\": \"" + String.valueOf(FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".fileprovider", new File(fileName))) + "\"}");
481
481
  return true;
482
482
  } else {
483
483
  requestPermissions();
@@ -507,7 +507,7 @@ public class FileManager extends ReactContextBaseJavaModule {
507
507
  audioPlayer.prepare();
508
508
  audioPlayer.start();
509
509
  Log.e("TAG", "Playing Audio: " + fileName);
510
- callback.invoke("{\"success\": true, \"file\": \"" + String.valueOf(FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".provider", new File(fileName))) + "\"}");
510
+ callback.invoke("{\"success\": true, \"file\": \"" + String.valueOf(FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".fileprovider", new File(fileName))) + "\"}");
511
511
  } catch (IOException e) {
512
512
  Log.e("TAG", "prepare() failed");
513
513
  }
@@ -528,7 +528,7 @@ public class FileManager extends ReactContextBaseJavaModule {
528
528
  if (audioPlayer != null && audioPlayer.isPlaying()) {
529
529
  Log.e("TAG", "Trying to pause Audio: " + fileName);
530
530
  audioPlayer.pause();
531
- callback.invoke("{\"success\": true, \"file\": \"" + String.valueOf(FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".provider", new File(fileName))) + "\"}");
531
+ callback.invoke("{\"success\": true, \"file\": \"" + String.valueOf(FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".fileprovider", new File(fileName))) + "\"}");
532
532
  Log.e("TAG", "Paused Audio: " + fileName);
533
533
  }
534
534
  }
@@ -539,7 +539,7 @@ public class FileManager extends ReactContextBaseJavaModule {
539
539
  audioPlayer.stop();
540
540
  audioPlayer.release();
541
541
  audioPlayer = null;
542
- callback.invoke("{\"success\": true, \"file\": \"" + String.valueOf(FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".provider", new File(fileName))) + "\"}");
542
+ callback.invoke("{\"success\": true, \"file\": \"" + String.valueOf(FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".fileprovider", new File(fileName))) + "\"}");
543
543
  }
544
544
  }
545
545
 
@@ -547,7 +547,7 @@ public class FileManager extends ReactContextBaseJavaModule {
547
547
  public void releaseMediaResources(Callback callback) {
548
548
  if (audioRecorder != null) {
549
549
  pauseRecording();
550
- callback.invoke("{\"success\": true, \"file\": \"" + String.valueOf(FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".provider", new File(fileName))) + "\"}");
550
+ callback.invoke("{\"success\": true, \"file\": \"" + String.valueOf(FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".fileprovider", new File(fileName))) + "\"}");
551
551
  }
552
552
  if (audioPlayer != null && audioPlayer.isPlaying()) {
553
553
  stopPlaying(callback);
@@ -0,0 +1,4 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface CometChatCommonUtil : NSObject <RCTBridgeModule>
4
+ @end
@@ -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,7 +1,7 @@
1
1
  {
2
2
  "name": "@cometchat/chat-uikit-react-native",
3
- "version": "4.3.3",
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",
3
+ "version": "4.3.5",
4
+ "description": "Ready-to-use Chat UI Components for React Native",
5
5
  "main": "src/index",
6
6
  "module": "src/index",
7
7
  "react-native": "src/index",
@@ -32,9 +32,14 @@
32
32
  },
33
33
  "keywords": [
34
34
  "cometchat",
35
+ "chat",
36
+ "messaging",
37
+ "audio",
38
+ "video",
35
39
  "react-native",
36
- "ios",
37
- "android"
40
+ "webRTC",
41
+ "Uikit",
42
+ "SDK"
38
43
  ],
39
44
  "repository": "https://github.com/cometchat-pro/cometchat-pro-react-native-ui-kit",
40
45
  "author": "Inscripts",
@@ -42,7 +47,7 @@
42
47
  "bugs": {
43
48
  "url": "https://github.com/cometchat-pro/cometchat-pro-react-native-ui-kit/issues"
44
49
  },
45
- "homepage": "https://github.com/cometchat-pro/cometchat-pro-react-native-ui-kit#readme",
50
+ "homepage": "https://www.cometchat.com",
46
51
  "publishConfig": {
47
52
  "registry": "https://registry.npmjs.org/"
48
53
  },
@@ -34,9 +34,6 @@ export class AIAssistBotDecorator extends DataSourceDecorator {
34
34
  this.usersRequest.fetchNext().then((bots) => {
35
35
  if (bots.length > 0) {
36
36
  this.bots = [...(this.bots || []), ...bots];
37
- if (bots.length > 0) {
38
- this.fetchBots();
39
- }
40
37
  }
41
38
  })
42
39
 
@@ -8,8 +8,13 @@ import {
8
8
  CometChatConfirmDialog,
9
9
  CometChatConfirmDialogStyleInterface,
10
10
  CometChatContext,
11
+ CometChatMentionsFormatter,
12
+ CometChatTextFormatter,
13
+ CometChatUrlsFormatter,
14
+ MentionTextStyle,
11
15
  CometChatListActionsInterface,
12
- localize
16
+ localize,
17
+ CometChatUIKit
13
18
  } from "../shared";
14
19
  import { Style } from "./style";
15
20
  import {
@@ -33,6 +38,7 @@ import { StatusIndicatorStyleInterface } from "../shared/views/CometChatStatusIn
33
38
  import { DateStyleInterface } from "../shared/views/CometChatDate/DateStyle";
34
39
  import { BadgeStyleInterface } from "../shared/views/CometChatBadge";
35
40
  import { InteractiveMessageUtils } from "../shared/utils/InteractiveMessageUtils";
41
+ import { CommonUtils } from "../shared/utils/CommonUtils";
36
42
 
37
43
  const conversationListenerId = "chatlist_" + new Date().getTime();
38
44
  const userListenerId = "chatlist_user_" + new Date().getTime();
@@ -217,7 +223,16 @@ export interface ConversationInterface {
217
223
  /**
218
224
  * style object for confirm dialog
219
225
  */
220
- 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>;
221
236
  }
222
237
 
223
238
  /**
@@ -263,10 +278,13 @@ export const CometChatConversations = (props: ConversationInterface) => {
263
278
  onError,
264
279
  onBack,
265
280
  conversationsStyle,
281
+ disableMentions,
282
+ textFormatters
266
283
  } = props;
267
284
 
268
285
  //context
269
286
  const { theme } = useContext<CometChatContextType>(CometChatContext);
287
+ const activeSwipeRows = React.useRef({});
270
288
 
271
289
  const conversationListRef = React.useRef<CometChatListActionsInterface>(null);
272
290
  const loggedInUser = React.useRef(null);
@@ -365,16 +383,17 @@ export const CometChatConversations = (props: ConversationInterface) => {
365
383
  }
366
384
 
367
385
 
368
- const getConversationRefFromTypingIndicator = (typingIndicator : CometChat.TypingIndicator)=> {
369
- let list = conversationListRef.current.getAllListItems();
370
- return list.find((item: CometChat.Conversation) => {
371
- return (
372
- (typingIndicator.getReceiverType()== ReceiverTypeConstants.user&&
373
- item.getConversationType() == ReceiverTypeConstants.user
374
- && (item.getConversationWith() as CometChat.User).getUid() == typingIndicator.getSender().getUid() )
375
- || (typingIndicator.getReceiverType() == ReceiverTypeConstants.group && item.getConversationType() == ReceiverTypeConstants.group
376
- && (item.getConversationWith() as CometChat.Group).getGuid() == typingIndicator.getReceiverId() )
377
- )})
386
+ const getConversationRefFromTypingIndicator = (typingIndicator: CometChat.TypingIndicator) => {
387
+ let list = conversationListRef.current.getAllListItems();
388
+ return list.find((item: CometChat.Conversation) => {
389
+ return (
390
+ (typingIndicator.getReceiverType() == ReceiverTypeConstants.user &&
391
+ item.getConversationType() == ReceiverTypeConstants.user
392
+ && (item.getConversationWith() as CometChat.User).getUid() == typingIndicator.getSender().getUid())
393
+ || (typingIndicator.getReceiverType() == ReceiverTypeConstants.group && item.getConversationType() == ReceiverTypeConstants.group
394
+ && (item.getConversationWith() as CometChat.Group).getGuid() == typingIndicator.getReceiverId())
395
+ )
396
+ })
378
397
  }
379
398
 
380
399
  /**
@@ -383,7 +402,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
383
402
  */
384
403
  const typingEventHandler = (...args) => {
385
404
  let conversation: CometChat.Conversation = getConversationRefFromTypingIndicator(args[0]);
386
- if(conversation){
405
+ if (conversation) {
387
406
  let isTyping = args[1];
388
407
  let newConversation = conversation
389
408
  if (isTyping && !newConversation?.['lastMessage']?.["typing"]) {
@@ -398,24 +417,24 @@ export const CometChatConversations = (props: ConversationInterface) => {
398
417
 
399
418
  }
400
419
 
401
- /**
402
- * Find conversation from state , check and udpate its last message object.
403
- * conversation list item remains at the same place
404
- *
405
- * @param newMessage message object
406
- */
407
- const checkAndUpdateLastMessage = (newMessage: CometChat.BaseMessage) => {
420
+ /**
421
+ * Find conversation from state , check and udpate its last message object.
422
+ * conversation list item remains at the same place
423
+ *
424
+ * @param newMessage message object
425
+ */
426
+ const checkAndUpdateLastMessage = (newMessage: CometChat.BaseMessage) => {
408
427
  CometChat.CometChatHelper.getConversationFromMessage(newMessage)
409
- .then(conversation => {
410
- let conver: any = conversationListRef.current.getListItem(conversation.getConversationId())
411
- if (!conver) return;
412
- let lastMessageId = conver['lastMessage']['id']
413
- if (lastMessageId == newMessage['id']) {
414
- conversationListRef.current.updateList(conversation)
415
- }
416
- })
428
+ .then(conversation => {
429
+ let conver: any = conversationListRef.current.getListItem(conversation.getConversationId())
430
+ if (!conver) return;
431
+ let lastMessageId = conver['lastMessage']['id']
432
+ if (lastMessageId == newMessage['id']) {
433
+ conversationListRef.current.updateList(conversation)
434
+ }
435
+ })
417
436
 
418
- }
437
+ }
419
438
 
420
439
  /**
421
440
  * Find conversation from state and udpate its last message object.
@@ -433,7 +452,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
433
452
  if (oldConversation == undefined) {
434
453
  CometChat.CometChatHelper.getConversationFromMessage(newMessage)
435
454
  .then(newConversation => {
436
- if(newConversation?.lastMessage?.sender?.uid !== loggedInUser.current?.['uid'])
455
+ if (newConversation?.lastMessage?.sender?.uid !== loggedInUser.current?.['uid'])
437
456
  newConversation.setUnreadMessageCount(1);
438
457
  conversationListRef.current.updateAndMoveToFirst(newConversation);
439
458
  })
@@ -496,7 +515,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
496
515
 
497
516
  if (conversation) {
498
517
  conversation.setLastMessage(message);
499
- if(action === 'kicked' || action === 'banned')
518
+ if (action === 'kicked' || action === 'banned')
500
519
  conversationListRef.current.removeItemFromList(message.conversationId);
501
520
  else
502
521
  conversationListRef.current.updateList(conversation);
@@ -577,30 +596,72 @@ export const CometChatConversations = (props: ConversationInterface) => {
577
596
 
578
597
  let lastMessage: CometChat.BaseMessage = conversations.getLastMessage();
579
598
  if (!lastMessage) return null;
580
- let messageText: string ;
581
- if(lastMessage.getDeletedAt() !== undefined){
599
+ let messageText: string;
600
+ if (lastMessage.getDeletedAt() !== undefined) {
582
601
  messageText = localize("THIS_MESSAGE_DELETED");
583
- }else{
602
+ } else {
584
603
  messageText = ChatConfigurator.getDataSource().getLastConversationMessage(conversations);
604
+
605
+ if (lastMessage) {
606
+ messageText = getFormattedText(lastMessage, messageText?.trim());
607
+ }
585
608
  }
586
609
  let groupText = "";
587
610
  if (lastMessage.getReceiverType() == ReceiverTypeConstants.group) {
588
611
  if (lastMessage.getSender().getUid() == uid) {
589
- groupText = localize("YOU")+ ": "
612
+ groupText = localize("YOU") + ": "
590
613
  } else {
591
614
  groupText = lastMessage.getSender().getName() + ": "
592
615
  }
593
616
  }
594
617
 
595
- messageText = messageText?.trim();
596
618
  return (
597
- <Text numberOfLines={1} ellipsizeMode={"tail"} style={[Style.subtitleTextStyle, { color: theme.palette.getAccent600(), fontSize : theme.typography.subtitle1.fontSize,
598
- fontWeight : theme.typography.subtitle1.fontWeight }]}>
599
- {groupText + messageText}
619
+ <Text numberOfLines={1} ellipsizeMode={"tail"} style={[Style.subtitleTextStyle, {
620
+ color: theme.palette.getAccent600(), fontSize: theme.typography.subtitle1.fontSize,
621
+ fontWeight: theme.typography.subtitle1.fontWeight
622
+ }]}>
623
+ {groupText}{messageText}
600
624
  </Text>
601
625
  )
602
626
  }
603
627
 
628
+ function getFormattedText(message: CometChat.BaseMessage, subtitle: string) {
629
+ let messageTextTmp = subtitle;
630
+ let allFormatters = [...(textFormatters || [])] || [];
631
+
632
+ if (!disableMentions && message.getMentionedUsers().length) {
633
+ let mentionsFormatter = ChatConfigurator.getDataSource().getMentionsFormatter();
634
+ mentionsFormatter.setLoggedInUser(CometChatUIKit.loggedInUser);
635
+ mentionsFormatter.setMentionsStyle(
636
+ new MentionTextStyle({
637
+ loggedInUserTextStyle: {
638
+ color: theme.palette.getPrimary(),
639
+ ...theme.typography.title2,
640
+ },
641
+ textStyle: {
642
+ color: theme.palette.getPrimary(),
643
+ ...theme.typography.subtitle1,
644
+ }
645
+ })
646
+ );
647
+
648
+ mentionsFormatter.setMessage(message);
649
+ allFormatters.push(mentionsFormatter);
650
+ }
651
+
652
+ if (allFormatters && allFormatters.length) {
653
+ for (let i = 0; i < allFormatters.length; i++) {
654
+ let suggestionUsers = allFormatters[i].getSuggestionItems();
655
+ allFormatters[i].setMessage(message);
656
+ suggestionUsers.length > 0 && allFormatters[i].setSuggestionItems(suggestionUsers);
657
+ let _formatter = CommonUtils.clone(allFormatters[i]);
658
+ (messageTextTmp as string | JSX.Element) = _formatter.getFormattedText(messageTextTmp);
659
+ }
660
+ }
661
+
662
+ return messageTextTmp;
663
+ }
664
+
604
665
  const LastMessageView = (params: {
605
666
  conversations: CometChat.Conversation,
606
667
  typingText: string
@@ -608,35 +669,37 @@ export const CometChatConversations = (props: ConversationInterface) => {
608
669
  const lastMessage = params['conversations']['lastMessage'];
609
670
  if (!lastMessage) return null;
610
671
  let readReceipt;
611
- if ( params.typingText) {
672
+ if (params.typingText) {
612
673
  return <View style={Style.row}>
613
- <Text numberOfLines={1} ellipsizeMode={"tail"} style={[Style.subtitleTextStyle, { color: theme.palette.getPrimary() ,
614
- fontSize : theme.typography.subtitle1.fontSize , fontWeight : theme.typography.subtitle1.fontWeight }]} >{params.typingText}</Text>
674
+ <Text numberOfLines={1} ellipsizeMode={"tail"} style={[Style.subtitleTextStyle, {
675
+ color: theme.palette.getPrimary(),
676
+ fontSize: theme.typography.subtitle1.fontSize, fontWeight: theme.typography.subtitle1.fontWeight
677
+ }]} >{params.typingText}</Text>
615
678
  </View>
616
679
  }
617
680
 
618
681
  if (lastMessage && !disableReadReceipt && lastMessage['sender']['uid'] == loggedInUser.current?.uid && !lastMessage.getDeletedAt()) {
619
- let status: MessageReceipt = "ERROR";
620
- if (lastMessage?.hasOwnProperty('readAt'))
621
- status = "READ";
622
- else if (lastMessage?.hasOwnProperty("deliveredAt"))
623
- status = "DELIVERED";
624
- else if (lastMessage?.hasOwnProperty("sentAt"))
625
- status = "SENT";
626
- readReceipt = disableReceipt ? null : <CometChatReceipt
627
- receipt={status}
628
- deliveredIcon={props.deliveredIcon}
629
- errorIcon={props.errorIcon}
630
- readIcon={props.readIcon}
631
- sentIcon={props.sentIcon}
632
- waitIcon={props.waitingIcon}
633
- />;
682
+ let status: MessageReceipt = "ERROR";
683
+ if (lastMessage?.hasOwnProperty('readAt'))
684
+ status = "READ";
685
+ else if (lastMessage?.hasOwnProperty("deliveredAt"))
686
+ status = "DELIVERED";
687
+ else if (lastMessage?.hasOwnProperty("sentAt"))
688
+ status = "SENT";
689
+ readReceipt = disableReceipt ? null : <CometChatReceipt
690
+ receipt={status}
691
+ deliveredIcon={props.deliveredIcon}
692
+ errorIcon={props.errorIcon}
693
+ readIcon={props.readIcon}
694
+ sentIcon={props.sentIcon}
695
+ waitIcon={props.waitingIcon}
696
+ />;
634
697
  }
635
698
 
636
699
  let threadView;
637
700
 
638
- if(lastMessage?.getParentMessageId()){
639
- threadView = <Text numberOfLines={1} style={[Style.subtitleTextStyle, { color: theme.palette.getAccent600() }]} >{localize("IN_A_THREAD")}</Text>
701
+ if (lastMessage?.getParentMessageId()) {
702
+ threadView = <Text numberOfLines={1} style={[Style.subtitleTextStyle, { color: theme.palette.getAccent600() }]} >{localize("IN_A_THREAD")}</Text>
640
703
  }
641
704
 
642
705
  return (
@@ -704,6 +767,16 @@ export const CometChatConversations = (props: ConversationInterface) => {
704
767
  return _defaultOptions
705
768
  }
706
769
 
770
+ const updateConversationLastMessage = (message) => {
771
+ try {
772
+ let conversation: CometChat.Conversation = conversationListRef.current?.getListItem(message.conversationId)
773
+ conversation.lastMessage = message
774
+ conversationListRef.current?.updateAndMoveToFirst(conversation);
775
+ } catch (error) {
776
+ onError && onError(error)
777
+ }
778
+ }
779
+
707
780
  React.useEffect(() => {
708
781
  CometChat.getLoggedinUser()
709
782
  .then(u => { loggedInUser.current = u })
@@ -902,14 +975,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
902
975
  removeItemFromSelectionList(leftGroup['conversationId'])
903
976
  },
904
977
  ccGroupMemberKicked: ({ message, kickedFrom }: { message: CometChat.BaseMessage, kickedFrom: CometChat.Group }) => {
905
- CometChat.CometChatHelper.getConversationFromMessage(message)
906
- .then(conversation => {
907
- conversationListRef.current?.updateList(conversation);
908
- })
909
- .catch(e => {
910
- onError && onError(e);
911
- })
912
-
978
+ updateConversationLastMessage(message)
913
979
  },
914
980
  ccGroupMemberBanned: ({ message }) => {
915
981
  groupHandler(message);
@@ -927,11 +993,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
927
993
  })
928
994
  },
929
995
  ccGroupMemberAdded: ({ message }: { message: CometChat.BaseMessage }) => {
930
- CometChat.CometChatHelper.getConversationFromMessage(message)
931
- .then(conversation => {
932
- conversationListRef.current?.updateList(conversation);
933
- })
934
- .catch(e => onError && onError(e))
996
+ updateConversationLastMessage(message)
935
997
  }
936
998
  }
937
999
  )
@@ -1048,6 +1110,15 @@ export const CometChatConversations = (props: ConversationInterface) => {
1048
1110
  onPress={conversationClicked.bind(this, conversation)}
1049
1111
  onLongPress={conversationLongPressed.bind(this, conversation)}
1050
1112
  options={() => options ? options(conversation) : getDefaultOptions(conversation)}
1113
+ activeSwipeRows={activeSwipeRows.current}
1114
+ rowOpens={(id) => {
1115
+ Object.keys(activeSwipeRows.current).forEach(key => {
1116
+ if(id !== key && activeSwipeRows.current[key]) {
1117
+ activeSwipeRows.current[key]?.current?.closeRow?.()
1118
+ delete activeSwipeRows.current[key]
1119
+ }
1120
+ })
1121
+ }}
1051
1122
  />
1052
1123
  }
1053
1124
 
@@ -1,10 +1,9 @@
1
- import { AvatarStyleInterface, ListItemStyleInterface, localize } from "../shared";
1
+ import { AvatarStyleInterface, CometChatMentionsFormatter, CometChatTextFormatter, CometChatUrlsFormatter, ListItemStyleInterface, localize } from "../shared";
2
2
  import { ImageType } from "../shared";
3
3
  import { DatePattern,SelectionMode } from "../shared/base/Types";
4
- import { AvatarStyle, BadgeStyle, DateStyle, ListItemStyle, StatusIndicatorStyle } from "../shared";
5
4
  import { CometChatOptions } from "../shared";
6
5
  // import { ConversationListConfiguration } from "../CometChatConversationList/ConversationListConfiguration";
7
- import { ConversationsStyle, ConversationsStyleInterface } from "./ConversationsStyle";
6
+ import { ConversationsStyleInterface } from "./ConversationsStyle";
8
7
  //@ts-ignore
9
8
  import { CometChat } from "@cometchat/chat-sdk-react-native";
10
9
  import { StatusIndicatorStyleInterface } from "../shared/views/CometChatStatusIndicator/StatusIndicatorStyle";
@@ -50,7 +49,16 @@ export interface ConversationsConfigurationInterface {
50
49
  dateStyle?: DateStyleInterface,
51
50
  conversationsStyle?: ConversationsStyleInterface,
52
51
  listItemStyle?: ListItemStyleInterface,
53
- badgeStyle?: BadgeStyleInterface
52
+ badgeStyle?: BadgeStyleInterface,
53
+ /**
54
+ * if true, mentions will be disabled. Default: false
55
+ */
56
+ disableMentions?: boolean,
57
+ /**
58
+ * Collection of text formatter class
59
+ * @type {Array<CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter>}
60
+ */
61
+ textFormatters?: Array<CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter>;
54
62
  }
55
63
 
56
64
  /**
@@ -96,6 +104,15 @@ export class ConversationsConfiguration implements ConversationsConfigurationInt
96
104
  conversationsStyle?: ConversationsStyleInterface;
97
105
  listItemStyle?: ListItemStyleInterface;
98
106
  badgeStyle?: BadgeStyleInterface;
107
+ /**
108
+ * if true, mentions will be disabled. Default: false
109
+ */
110
+ disableMentions?: boolean;
111
+ /**
112
+ * Collection of text formatter class
113
+ * @type {Array<CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter>}
114
+ */
115
+ textFormatters?: Array<CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter>;
99
116
 
100
117
  constructor({
101
118
  disableUsersPresence = false,
@@ -137,6 +154,8 @@ export class ConversationsConfiguration implements ConversationsConfigurationInt
137
154
  conversationsStyle = undefined,
138
155
  listItemStyle = undefined,
139
156
  badgeStyle = undefined,
157
+ disableMentions,
158
+ textFormatters
140
159
  }: ConversationsConfigurationInterface) {
141
160
  this.disableUsersPresence = disableUsersPresence;
142
161
  this.disableReceipt = disableReceipt;
@@ -177,5 +196,7 @@ export class ConversationsConfiguration implements ConversationsConfigurationInt
177
196
  this.conversationsStyle = conversationsStyle
178
197
  this.listItemStyle = listItemStyle
179
198
  this.badgeStyle = badgeStyle
199
+ this.disableMentions = disableMentions;
200
+ this.textFormatters = textFormatters;
180
201
  }
181
202
  }