@cometchat/chat-uikit-react-native 4.3.18 → 4.3.19

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/ios/FileManager.m CHANGED
@@ -545,6 +545,8 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
545
545
  NSString *uri = [NSString stringWithFormat:@"%@", urls[0]];
546
546
  NSString *type = [self getMimeType:urls[0]];
547
547
  NSString *name = [urls[0] lastPathComponent];
548
+ if (!name) name = @"Unknown";
549
+ if (!type) type = @"Unknown";
548
550
  callback(@[@{@"name": name, @"type": type, @"uri": uri}]);
549
551
  }
550
552
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cometchat/chat-uikit-react-native",
3
- "version": "4.3.18",
3
+ "version": "4.3.19",
4
4
  "description": "Ready-to-use Chat UI Components for React Native",
5
5
  "main": "src/index",
6
6
  "module": "src/index",
@@ -417,14 +417,18 @@ export const CometChatConversations = (props: ConversationInterface) => {
417
417
  *
418
418
  * @param newMessage message object
419
419
  */
420
- const checkAndUpdateLastMessage = (newMessage: CometChat.BaseMessage) => {
420
+ const checkAndUpdateLastMessage = (newMessage: CometChat.BaseMessage, resetUnreadCount = false) => {
421
421
  CometChat.CometChatHelper.getConversationFromMessage(newMessage)
422
422
  .then((conversation: any) => {
423
423
  let conver: any = conversationListRef.current?.getListItem(conversation.getConversationId())
424
424
  if (!conver) return;
425
425
  let lastMessageId = conver['lastMessage']['id']
426
426
  if (lastMessageId == newMessage['id']) {
427
- conversationListRef.current?.updateList(conversation)
427
+ if(resetUnreadCount) {
428
+ conver.setUnreadMessageCount(0);
429
+ }
430
+ conver.setLastMessage(newMessage)
431
+ conversationListRef.current?.updateList(conver)
428
432
  }
429
433
  })
430
434
 
@@ -635,7 +639,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
635
639
  return;
636
640
  }
637
641
  conversation.setLastMessage(message);
638
- conversationListRef.current?.updateList(conversation);
642
+ conversationListRef.current?.updateAndMoveToFirst(conversation);
639
643
  }
640
644
  } else {
641
645
  CometChat.CometChatHelper.getConversationFromMessage(message)
@@ -1076,13 +1080,13 @@ export const CometChatConversations = (props: ConversationInterface) => {
1076
1080
  }
1077
1081
  },
1078
1082
  ccMessageRead: ({ message }: any) => {
1079
- checkAndUpdateLastMessage(message)
1083
+ checkAndUpdateLastMessage(message, true)
1080
1084
  },
1081
1085
  ccMessageDeleted: ({ message }: any) => {
1082
- checkAndUpdateLastMessage(message)
1086
+ checkAndUpdateLastMessage(message, true)
1083
1087
  },
1084
1088
  ccMessageEdited: ({ message }: any) => {
1085
- checkAndUpdateLastMessage(message)
1089
+ checkAndUpdateLastMessage(message, true)
1086
1090
  },
1087
1091
  onTextMessageReceived: (textMessage: any) => {
1088
1092
  if(!shouldUpdateLastMessageAndUnreadCount(textMessage)) {
@@ -1106,10 +1110,10 @@ export const CometChatConversations = (props: ConversationInterface) => {
1106
1110
  !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1107
1111
  },
1108
1112
  onMessageDeleted: (deletedMessage: any) => {
1109
- checkAndUpdateLastMessage(deletedMessage)
1113
+ checkAndUpdateLastMessage(deletedMessage, false)
1110
1114
  },
1111
1115
  onMessageEdited: (editedMessage: any) => {
1112
- checkAndUpdateLastMessage(editedMessage)
1116
+ checkAndUpdateLastMessage(editedMessage, false)
1113
1117
  },
1114
1118
  onMessagesRead: (messageReceipt: any) => {
1115
1119
  updateMessageReceipt(messageReceipt);
@@ -608,7 +608,7 @@ export const CometChatMessageComposer = React.forwardRef(
608
608
  const messageInputRef = React.useRef<any>(null);
609
609
  const chatRef = React.useRef<any>(chatWith);
610
610
  const inputValueRef = React.useRef<any>(null);
611
- const plainTextInput = React.useRef<string>("");
611
+ const plainTextInput = React.useRef<string>(text ?? "");
612
612
  let mentionMap = React.useRef<Map<string, SuggestionItem>>(new Map());
613
613
  let trackingCharacters = React.useRef<string[]>([])
614
614
  let allFormatters = React.useRef<Map<string, CometChatTextFormatter | CometChatMentionsFormatter>>(new Map());
@@ -1131,7 +1131,7 @@ export const CometChatMessageComposer = React.forwardRef(
1131
1131
  };
1132
1132
 
1133
1133
  const shouldShowAIOptions = () => {
1134
- return AIOptionItems.length > 0;
1134
+ return !parentMessageId && AIOptionItems.length > 0;
1135
1135
  }
1136
1136
 
1137
1137
  const AuxiliaryButtonViewElem = () => {
@@ -1316,7 +1316,11 @@ export const CometChatMessageComposer = React.forwardRef(
1316
1316
  if (typeof item.onPress == 'function')
1317
1317
  return {
1318
1318
  ...item,
1319
- onPress: () => item.onPress?.(user, group),
1319
+ onPress: () => {
1320
+ setShowActionSheet(false);
1321
+ item.onPress?.(user, group)
1322
+ }
1323
+ ,
1320
1324
  };
1321
1325
  return {
1322
1326
  ...item,
@@ -1390,6 +1394,7 @@ export const CometChatMessageComposer = React.forwardRef(
1390
1394
  bottomSheetRef.current?.togglePanel();
1391
1395
 
1392
1396
  inputValueRef.current = text?.text;
1397
+ plainTextInput.current = text?.text;
1393
1398
  setInputMessage(text?.text)
1394
1399
 
1395
1400
  },
@@ -331,6 +331,7 @@ export const CometChatMessageList = memo(forwardRef<
331
331
  const bottomSheetRef = useRef<any>(null)
332
332
  const conversationId = useRef(null)
333
333
  let lastID = useRef(0);
334
+ let isKeyBoardVisible = useRef(false);
334
335
 
335
336
  const scrollHandler = (event: any) => {
336
337
  /********************************************************************************
@@ -377,7 +378,7 @@ export const CometChatMessageList = memo(forwardRef<
377
378
  }
378
379
 
379
380
  const newMsgIndicatorPressed = () => {
380
- scrollToBottom();
381
+ messageListRef.current?.scrollToEnd({ animated: true });
381
382
  markUnreadMessageAsRead();
382
383
  };
383
384
 
@@ -494,7 +495,7 @@ export const CometChatMessageList = memo(forwardRef<
494
495
  })
495
496
  if (inProgressMessages.current.length) {
496
497
  const filteredInProgressMessages = inProgressMessages.current.filter(secondItem =>
497
- !tmpList.some(firstItem => firstItem.muid === secondItem.muid)
498
+ tmpList.some(firstItem => firstItem.muid === secondItem.muid)
498
499
  );
499
500
  const combinedArray = CommonUtils.mergeArrays(tmpList, filteredInProgressMessages, "muid");
500
501
  tmpList = combinedArray
@@ -788,7 +789,7 @@ export const CometChatMessageList = memo(forwardRef<
788
789
  let condition: (value: any, index: number, obj: any[]) => unknown;
789
790
  if (withMuid) {
790
791
  condition = (msg) => msg['muid'] == editedMessage['muid']
791
- inProgressMessages.current = inProgressMessages.current.filter((item: anyObject) => item.muid !== editedMessage['muid'])
792
+ //inProgressMessages.current = inProgressMessages.current.filter((item: anyObject) => item.muid !== editedMessage['muid'])
792
793
  }
793
794
  else
794
795
  condition = (msg) => msg.getId() == editedMessage.getId()
@@ -1196,8 +1197,20 @@ export const CometChatMessageList = memo(forwardRef<
1196
1197
  Keyboard_Height = keyboardHeight;
1197
1198
  scrollPos = (currentScrollPosition.current.y + Keyboard_Height) - ((commonVars.safeAreaInsets.top as number) / 2);
1198
1199
  messageListRef.current.scrollTo({ y: scrollPos, animated: false })
1200
+ isKeyBoardVisible.current = true;
1199
1201
  } else {
1200
- messageListRef.current.scrollTo({ y: scrollPos - Keyboard_Height + ((commonVars.safeAreaInsets.top as number) / 2), animated: false })
1202
+ isKeyBoardVisible.current = false;
1203
+ /**
1204
+ * Do not have to scroll back if the list is at the bottom because we are already adjusting
1205
+ for the change in contentSize when we are at bottom which means if the list is at the bottom
1206
+ and we open the keyboard, the following line
1207
+ (`messageListRef.current.scrollTo({ y: scrollPos, animated: false })`) in the above "if"
1208
+ condition already puts the list at the bottom again.
1209
+ Hence, running the below for isAtBottom() will scroll to a wrong position.
1210
+ */
1211
+ if(!isAtBottom()) {
1212
+ messageListRef.current.scrollTo({ y: scrollPos - Keyboard_Height + ((commonVars.safeAreaInsets.top as number) / 2), animated: false });
1213
+ }
1201
1214
  }
1202
1215
  }
1203
1216
  }
@@ -1902,6 +1915,51 @@ export const CometChatMessageList = memo(forwardRef<
1902
1915
  currentScrollPosition.current.scrollViewHeight = contentHeight;
1903
1916
  }
1904
1917
  }
1918
+
1919
+ /**
1920
+ * If Keyboard is open, recalculate the scroll position when content size changes
1921
+ */
1922
+ if(isKeyBoardVisible.current == true) {
1923
+ /**
1924
+ * WITHOUT the isAtBottom() check, the following will happen:
1925
+ * 1. nearToBottom() is true (which is up to 2 messages from bottom)
1926
+ * 2. A new message is received (or any event that changes the content size)
1927
+ but the UI issue is mainly with a new message
1928
+ * 3. Since the content size has increased, we are not nearToBotom() anymore
1929
+ and so the unread banner will be displayed to click and scroll to bottom
1930
+ * 4. If there's not isAtBottomCheck() below, `onKeyboardVisibilityChange()` runs
1931
+ to adjust for the change in content size and this triggers a scroll
1932
+ messageListRef.current.scrollTo({ y: scrollPos, animated: false })
1933
+ * 5. And the nearToBottom() is true again since we have accounted for the change
1934
+ in contentSize and the banner disappears and the list scrolls to the bottom
1935
+ *
1936
+ * The above breaks the UI!
1937
+ */
1938
+
1939
+ /**
1940
+ * Why not do this for isAtBottom() || !isNearBottom()?
1941
+ * - (isAtBottom() || !isNearBottom()) means notAtBottom() and notNearBottom()
1942
+ This means there's content under the keyboard but that's not the end.
1943
+ Everytime a new message is received contentSize will change and that will
1944
+ trigger a position recalculation and a scroll and the list will keep scrolling
1945
+ till we reach bottom (that is if we keep receiving messages).
1946
+ *
1947
+ */
1948
+ if (isAtBottom()) {
1949
+ /**
1950
+ * Why is this required?
1951
+ * 1. Let's say the scroll is nearToBottom() and the keyboard is open
1952
+ * 2. User receives a new message and the content size changes.
1953
+ * 3. The Message List scrolls to the bottom since the scroll was nearToBottom()
1954
+ * 4. User closes the keyboard and the list scrolls back to the previous message
1955
+ * that was nearToBottom()
1956
+ * 5. The position to scroll back to needs to be recalculated since the contentSize
1957
+ has changed. Calling `onKeyboardVisibiltyChange()` does this.
1958
+ *
1959
+ */
1960
+ onKeyboardVisibiltyChange(true, Keyboard_Height);
1961
+ }
1962
+ }
1905
1963
  }, [])
1906
1964
 
1907
1965
  const {
@@ -43,7 +43,7 @@ export const MessageTranslationBubble = (props: MessageTranslationBubble) => {
43
43
 
44
44
  useEffect(() => {
45
45
  let _formattedText: string = text || '';
46
- let _formattedTranslatedText: string = text || '';
46
+ let _formattedTranslatedText: string = translatedText || '';
47
47
  if (textFormatters && textFormatters.length) {
48
48
  if (textFormatters) {
49
49
  for (let i = 0; i < textFormatters.length; i++) {
@@ -61,6 +61,10 @@ function isDeletedMessage(message: CometChat.BaseMessage): boolean {
61
61
  return message.getDeletedBy() != null;
62
62
  }
63
63
 
64
+ function isMessageSent(message: CometChat.BaseMessage): boolean {
65
+ return message.getSentAt() ? true : false;
66
+ }
67
+
64
68
  export class MessageDataSource implements DataSource {
65
69
 
66
70
  getEditOption(): CometChatMessageOption {
@@ -139,7 +143,7 @@ export class MessageDataSource implements DataSource {
139
143
  let messageOptionList: CometChatMessageOption[] = [];
140
144
 
141
145
 
142
- if (isDeletedMessage(messageObject))
146
+ if (isDeletedMessage(messageObject) || !isMessageSent(messageObject))
143
147
  return messageOptionList;
144
148
 
145
149
 
@@ -174,52 +178,52 @@ export class MessageDataSource implements DataSource {
174
178
 
175
179
  getFormMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
176
180
  let optionsList: Array<CometChatMessageOption> = [];
177
- if (!isDeletedMessage(messageObject))
181
+ if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
178
182
  optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
179
183
  return optionsList;
180
184
  }
181
185
 
182
186
  getSchedulerMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
183
187
  let optionsList: Array<CometChatMessageOption> = [];
184
- if (!isDeletedMessage(messageObject))
188
+ if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
185
189
  optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
186
190
  return optionsList;
187
191
  }
188
192
 
189
193
  getCardMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
190
194
  let optionsList: Array<CometChatMessageOption> = [];
191
- if (!isDeletedMessage(messageObject))
195
+ if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
192
196
  optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
193
197
  return optionsList;
194
198
  }
195
199
 
196
200
  getAudioMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
197
201
  let optionsList: Array<CometChatMessageOption> = [];
198
- if (!isDeletedMessage(messageObject))
202
+ if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
199
203
  optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
200
204
  return optionsList;
201
205
  }
202
206
  getVideoMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
203
207
  let optionsList: Array<CometChatMessageOption> = [];
204
- if (!isDeletedMessage(messageObject))
208
+ if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
205
209
  optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
206
210
  return optionsList
207
211
  }
208
212
  getImageMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
209
213
  let optionsList: Array<CometChatMessageOption> = [];
210
- if (!isDeletedMessage(messageObject))
214
+ if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
211
215
  optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
212
216
  return optionsList;
213
217
  }
214
218
  getFileMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
215
219
  let optionsList: Array<CometChatMessageOption> = [];
216
- if (!isDeletedMessage(messageObject))
220
+ if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
217
221
  optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
218
222
  return optionsList;
219
223
  }
220
224
  getMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
221
225
  let optionsList: Array<CometChatMessageOption> = [];
222
- if (isDeletedMessage(messageObject))
226
+ if (isDeletedMessage(messageObject) || !isMessageSent(messageObject))
223
227
  return optionsList;
224
228
  if (messageObject.getCategory() == MessageCategoryConstants.message) {
225
229
  let type: string = messageObject.getType();
@@ -307,7 +311,7 @@ export class MessageDataSource implements DataSource {
307
311
  getCommonOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
308
312
  let messageOptionList: CometChatMessageOption[] = [];
309
313
 
310
- if (isDeletedMessage(messageObject)) return messageOptionList;
314
+ if (isDeletedMessage(messageObject) || !isMessageSent(messageObject)) return messageOptionList;
311
315
 
312
316
  if (this.validateOption(loggedInUser, messageObject, MessageOptionConstants.replyInThread, group)) {
313
317
  messageOptionList.push(this.getReplyInThreadOption());
@@ -67,7 +67,7 @@ export class CommonUtils {
67
67
 
68
68
  arr1.forEach(obj => {
69
69
  if(!obj[key]) {
70
- map.set(Date.now(), obj);
70
+ map.set("" + Date.now() + Math.random(), obj);
71
71
  return;
72
72
  }
73
73
  map.set(obj[key], obj);
@@ -79,7 +79,7 @@ export class CommonUtils {
79
79
  map.set(obj[key], mergedObj);
80
80
  } else {
81
81
  if(!obj[key]) {
82
- map.set(Date.now(), obj);
82
+ map.set("" + Date.now() + Math.random(), obj);
83
83
  return;
84
84
  }
85
85
  map.set(obj[key], obj);
@@ -387,7 +387,7 @@ const _allowedGroupDetailsOptions: { [key: string]: { [key: string]: boolean } }
387
387
  [GroupOptionConstants.bannedMembers]: true,
388
388
  [GroupOptionConstants.viewMembers]: true,
389
389
  [GroupOptionConstants.addMembers]: true,
390
- [GroupOptionConstants.delete]: false,
390
+ [GroupOptionConstants.delete]: true,
391
391
  },
392
392
  [GroupMemberScope.owner]: {
393
393
  [GroupOptionConstants.leave]: true,
@@ -109,7 +109,7 @@ export const CometChatListItem = (props: CometChatListItemInterface) => {
109
109
  let rowOptions = options();
110
110
  if (rowOptions) setSwipeRowOptions(rowOptions);
111
111
  }
112
- }, []);
112
+ }, [options]);
113
113
  /**
114
114
  * Component to be display the user status
115
115
  */