Skip to content

Commit

Permalink
v4.3.19
Browse files Browse the repository at this point in the history
  • Loading branch information
mathews-cometchat committed Aug 30, 2024
1 parent b43b2fa commit a0d76b2
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 31 deletions.
2 changes: 2 additions & 0 deletions ios/FileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocum
NSString *uri = [NSString stringWithFormat:@"%@", urls[0]];
NSString *type = [self getMimeType:urls[0]];
NSString *name = [urls[0] lastPathComponent];
if (!name) name = @"Unknown";
if (!type) type = @"Unknown";
callback(@[@{@"name": name, @"type": type, @"uri": uri}]);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cometchat/chat-uikit-react-native",
"version": "4.3.18",
"version": "4.3.19",
"description": "Ready-to-use Chat UI Components for React Native",
"main": "src/index",
"module": "src/index",
Expand Down
20 changes: 12 additions & 8 deletions src/CometChatConversations/CometChatConversations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,18 @@ export const CometChatConversations = (props: ConversationInterface) => {
*
* @param newMessage message object
*/
const checkAndUpdateLastMessage = (newMessage: CometChat.BaseMessage) => {
const checkAndUpdateLastMessage = (newMessage: CometChat.BaseMessage, resetUnreadCount = false) => {
CometChat.CometChatHelper.getConversationFromMessage(newMessage)
.then((conversation: any) => {
let conver: any = conversationListRef.current?.getListItem(conversation.getConversationId())
if (!conver) return;
let lastMessageId = conver['lastMessage']['id']
if (lastMessageId == newMessage['id']) {
conversationListRef.current?.updateList(conversation)
if(resetUnreadCount) {
conver.setUnreadMessageCount(0);
}
conver.setLastMessage(newMessage)
conversationListRef.current?.updateList(conver)
}
})

Expand Down Expand Up @@ -635,7 +639,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
return;
}
conversation.setLastMessage(message);
conversationListRef.current?.updateList(conversation);
conversationListRef.current?.updateAndMoveToFirst(conversation);
}
} else {
CometChat.CometChatHelper.getConversationFromMessage(message)
Expand Down Expand Up @@ -1076,13 +1080,13 @@ export const CometChatConversations = (props: ConversationInterface) => {
}
},
ccMessageRead: ({ message }: any) => {
checkAndUpdateLastMessage(message)
checkAndUpdateLastMessage(message, true)
},
ccMessageDeleted: ({ message }: any) => {
checkAndUpdateLastMessage(message)
checkAndUpdateLastMessage(message, true)
},
ccMessageEdited: ({ message }: any) => {
checkAndUpdateLastMessage(message)
checkAndUpdateLastMessage(message, true)
},
onTextMessageReceived: (textMessage: any) => {
if(!shouldUpdateLastMessageAndUnreadCount(textMessage)) {
Expand All @@ -1106,10 +1110,10 @@ export const CometChatConversations = (props: ConversationInterface) => {
!disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
},
onMessageDeleted: (deletedMessage: any) => {
checkAndUpdateLastMessage(deletedMessage)
checkAndUpdateLastMessage(deletedMessage, false)
},
onMessageEdited: (editedMessage: any) => {
checkAndUpdateLastMessage(editedMessage)
checkAndUpdateLastMessage(editedMessage, false)
},
onMessagesRead: (messageReceipt: any) => {
updateMessageReceipt(messageReceipt);
Expand Down
11 changes: 8 additions & 3 deletions src/CometChatMessageComposer/CometChatMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const CometChatMessageComposer = React.forwardRef(
const messageInputRef = React.useRef<any>(null);
const chatRef = React.useRef<any>(chatWith);
const inputValueRef = React.useRef<any>(null);
const plainTextInput = React.useRef<string>("");
const plainTextInput = React.useRef<string>(text ?? "");
let mentionMap = React.useRef<Map<string, SuggestionItem>>(new Map());
let trackingCharacters = React.useRef<string[]>([])
let allFormatters = React.useRef<Map<string, CometChatTextFormatter | CometChatMentionsFormatter>>(new Map());
Expand Down Expand Up @@ -1131,7 +1131,7 @@ export const CometChatMessageComposer = React.forwardRef(
};

const shouldShowAIOptions = () => {
return AIOptionItems.length > 0;
return !parentMessageId && AIOptionItems.length > 0;
}

const AuxiliaryButtonViewElem = () => {
Expand Down Expand Up @@ -1316,7 +1316,11 @@ export const CometChatMessageComposer = React.forwardRef(
if (typeof item.onPress == 'function')
return {
...item,
onPress: () => item.onPress?.(user, group),
onPress: () => {
setShowActionSheet(false);
item.onPress?.(user, group)
}
,
};
return {
...item,
Expand Down Expand Up @@ -1390,6 +1394,7 @@ export const CometChatMessageComposer = React.forwardRef(
bottomSheetRef.current?.togglePanel();

inputValueRef.current = text?.text;
plainTextInput.current = text?.text;
setInputMessage(text?.text)

},
Expand Down
66 changes: 62 additions & 4 deletions src/CometChatMessageList/CometChatMessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export const CometChatMessageList = memo(forwardRef<
const bottomSheetRef = useRef<any>(null)
const conversationId = useRef(null)
let lastID = useRef(0);
let isKeyBoardVisible = useRef(false);

const scrollHandler = (event: any) => {
/********************************************************************************
Expand Down Expand Up @@ -377,7 +378,7 @@ export const CometChatMessageList = memo(forwardRef<
}

const newMsgIndicatorPressed = () => {
scrollToBottom();
messageListRef.current?.scrollToEnd({ animated: true });
markUnreadMessageAsRead();
};

Expand Down Expand Up @@ -494,7 +495,7 @@ export const CometChatMessageList = memo(forwardRef<
})
if (inProgressMessages.current.length) {
const filteredInProgressMessages = inProgressMessages.current.filter(secondItem =>
!tmpList.some(firstItem => firstItem.muid === secondItem.muid)
tmpList.some(firstItem => firstItem.muid === secondItem.muid)
);
const combinedArray = CommonUtils.mergeArrays(tmpList, filteredInProgressMessages, "muid");
tmpList = combinedArray
Expand Down Expand Up @@ -788,7 +789,7 @@ export const CometChatMessageList = memo(forwardRef<
let condition: (value: any, index: number, obj: any[]) => unknown;
if (withMuid) {
condition = (msg) => msg['muid'] == editedMessage['muid']
inProgressMessages.current = inProgressMessages.current.filter((item: anyObject) => item.muid !== editedMessage['muid'])
//inProgressMessages.current = inProgressMessages.current.filter((item: anyObject) => item.muid !== editedMessage['muid'])
}
else
condition = (msg) => msg.getId() == editedMessage.getId()
Expand Down Expand Up @@ -1196,8 +1197,20 @@ export const CometChatMessageList = memo(forwardRef<
Keyboard_Height = keyboardHeight;
scrollPos = (currentScrollPosition.current.y + Keyboard_Height) - ((commonVars.safeAreaInsets.top as number) / 2);
messageListRef.current.scrollTo({ y: scrollPos, animated: false })
isKeyBoardVisible.current = true;
} else {
messageListRef.current.scrollTo({ y: scrollPos - Keyboard_Height + ((commonVars.safeAreaInsets.top as number) / 2), animated: false })
isKeyBoardVisible.current = false;
/**
* Do not have to scroll back if the list is at the bottom because we are already adjusting
for the change in contentSize when we are at bottom which means if the list is at the bottom
and we open the keyboard, the following line
(`messageListRef.current.scrollTo({ y: scrollPos, animated: false })`) in the above "if"
condition already puts the list at the bottom again.
Hence, running the below for isAtBottom() will scroll to a wrong position.
*/
if(!isAtBottom()) {
messageListRef.current.scrollTo({ y: scrollPos - Keyboard_Height + ((commonVars.safeAreaInsets.top as number) / 2), animated: false });
}
}
}
}
Expand Down Expand Up @@ -1902,6 +1915,51 @@ export const CometChatMessageList = memo(forwardRef<
currentScrollPosition.current.scrollViewHeight = contentHeight;
}
}

/**
* If Keyboard is open, recalculate the scroll position when content size changes
*/
if(isKeyBoardVisible.current == true) {
/**
* WITHOUT the isAtBottom() check, the following will happen:
* 1. nearToBottom() is true (which is up to 2 messages from bottom)
* 2. A new message is received (or any event that changes the content size)
but the UI issue is mainly with a new message
* 3. Since the content size has increased, we are not nearToBotom() anymore
and so the unread banner will be displayed to click and scroll to bottom
* 4. If there's not isAtBottomCheck() below, `onKeyboardVisibilityChange()` runs
to adjust for the change in content size and this triggers a scroll
messageListRef.current.scrollTo({ y: scrollPos, animated: false })
* 5. And the nearToBottom() is true again since we have accounted for the change
in contentSize and the banner disappears and the list scrolls to the bottom
*
* The above breaks the UI!
*/

/**
* Why not do this for isAtBottom() || !isNearBottom()?
* - (isAtBottom() || !isNearBottom()) means notAtBottom() and notNearBottom()
This means there's content under the keyboard but that's not the end.
Everytime a new message is received contentSize will change and that will
trigger a position recalculation and a scroll and the list will keep scrolling
till we reach bottom (that is if we keep receiving messages).
*
*/
if (isAtBottom()) {
/**
* Why is this required?
* 1. Let's say the scroll is nearToBottom() and the keyboard is open
* 2. User receives a new message and the content size changes.
* 3. The Message List scrolls to the bottom since the scroll was nearToBottom()
* 4. User closes the keyboard and the list scrolls back to the previous message
* that was nearToBottom()
* 5. The position to scroll back to needs to be recalculated since the contentSize
has changed. Calling `onKeyboardVisibiltyChange()` does this.
*
*/
onKeyboardVisibiltyChange(true, Keyboard_Height);
}
}
}, [])

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const MessageTranslationBubble = (props: MessageTranslationBubble) => {

useEffect(() => {
let _formattedText: string = text || '';
let _formattedTranslatedText: string = text || '';
let _formattedTranslatedText: string = translatedText || '';
if (textFormatters && textFormatters.length) {
if (textFormatters) {
for (let i = 0; i < textFormatters.length; i++) {
Expand Down
24 changes: 14 additions & 10 deletions src/shared/framework/MessageDataSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ function isDeletedMessage(message: CometChat.BaseMessage): boolean {
return message.getDeletedBy() != null;
}

function isMessageSent(message: CometChat.BaseMessage): boolean {
return message.getSentAt() ? true : false;
}

export class MessageDataSource implements DataSource {

getEditOption(): CometChatMessageOption {
Expand Down Expand Up @@ -139,7 +143,7 @@ export class MessageDataSource implements DataSource {
let messageOptionList: CometChatMessageOption[] = [];


if (isDeletedMessage(messageObject))
if (isDeletedMessage(messageObject) || !isMessageSent(messageObject))
return messageOptionList;


Expand Down Expand Up @@ -174,52 +178,52 @@ export class MessageDataSource implements DataSource {

getFormMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
let optionsList: Array<CometChatMessageOption> = [];
if (!isDeletedMessage(messageObject))
if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
return optionsList;
}

getSchedulerMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
let optionsList: Array<CometChatMessageOption> = [];
if (!isDeletedMessage(messageObject))
if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
return optionsList;
}

getCardMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
let optionsList: Array<CometChatMessageOption> = [];
if (!isDeletedMessage(messageObject))
if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
return optionsList;
}

getAudioMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
let optionsList: Array<CometChatMessageOption> = [];
if (!isDeletedMessage(messageObject))
if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
return optionsList;
}
getVideoMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
let optionsList: Array<CometChatMessageOption> = [];
if (!isDeletedMessage(messageObject))
if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
return optionsList
}
getImageMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
let optionsList: Array<CometChatMessageOption> = [];
if (!isDeletedMessage(messageObject))
if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
return optionsList;
}
getFileMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
let optionsList: Array<CometChatMessageOption> = [];
if (!isDeletedMessage(messageObject))
if (!isDeletedMessage(messageObject) && isMessageSent(messageObject))
optionsList.push(...ChatConfigurator.dataSource.getCommonOptions(loggedInUser, messageObject, group));
return optionsList;
}
getMessageOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
let optionsList: Array<CometChatMessageOption> = [];
if (isDeletedMessage(messageObject))
if (isDeletedMessage(messageObject) || !isMessageSent(messageObject))
return optionsList;
if (messageObject.getCategory() == MessageCategoryConstants.message) {
let type: string = messageObject.getType();
Expand Down Expand Up @@ -307,7 +311,7 @@ export class MessageDataSource implements DataSource {
getCommonOptions(loggedInUser: CometChat.User, messageObject: CometChat.BaseMessage, group?: CometChat.Group): CometChatMessageOption[] {
let messageOptionList: CometChatMessageOption[] = [];

if (isDeletedMessage(messageObject)) return messageOptionList;
if (isDeletedMessage(messageObject) || !isMessageSent(messageObject)) return messageOptionList;

if (this.validateOption(loggedInUser, messageObject, MessageOptionConstants.replyInThread, group)) {
messageOptionList.push(this.getReplyInThreadOption());
Expand Down
4 changes: 2 additions & 2 deletions src/shared/utils/CommonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class CommonUtils {

arr1.forEach(obj => {
if(!obj[key]) {
map.set(Date.now(), obj);
map.set("" + Date.now() + Math.random(), obj);
return;
}
map.set(obj[key], obj);
Expand All @@ -79,7 +79,7 @@ export class CommonUtils {
map.set(obj[key], mergedObj);
} else {
if(!obj[key]) {
map.set(Date.now(), obj);
map.set("" + Date.now() + Math.random(), obj);
return;
}
map.set(obj[key], obj);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/DetailsUtils/DetailsUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ const _allowedGroupDetailsOptions: { [key: string]: { [key: string]: boolean } }
[GroupOptionConstants.bannedMembers]: true,
[GroupOptionConstants.viewMembers]: true,
[GroupOptionConstants.addMembers]: true,
[GroupOptionConstants.delete]: false,
[GroupOptionConstants.delete]: true,
},
[GroupMemberScope.owner]: {
[GroupOptionConstants.leave]: true,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/views/CometChatListItem/CometChatListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const CometChatListItem = (props: CometChatListItemInterface) => {
let rowOptions = options();
if (rowOptions) setSwipeRowOptions(rowOptions);
}
}, []);
}, [options]);
/**
* Component to be display the user status
*/
Expand Down

0 comments on commit a0d76b2

Please sign in to comment.