From 6351229aef11f0ff3bde7925609d258034ac1177 Mon Sep 17 00:00:00 2001 From: HoonBaek Date: Fri, 10 Dec 2021 09:16:00 +0900 Subject: [PATCH] Add optional chaining and change OR operation to AND in condition --- package-lock.json | 12 +++--- src/smart-components/Conversation/utils.js | 26 +++++++------ .../OpenchannelConversation/utils.ts | 39 +++++++++---------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6d038c2bc..800f35112 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28956,9 +28956,9 @@ "dev": true }, "node_modules/sendbird": { - "version": "3.0.160", - "resolved": "https://registry.npmjs.org/sendbird/-/sendbird-3.0.160.tgz", - "integrity": "sha512-47ljPMszDJLdmYX3kOfpvnK/tPVPaw3UnvtpmYvJo5+yq1SqJFAm7o6Dbcs+cYHfalUGRNcaEU+rDUBo8993+Q==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/sendbird/-/sendbird-3.1.0.tgz", + "integrity": "sha512-bnb6VFBjLVFFzxSGNoSTqBfYdQk9fjq2JQp80U9vRszWTmQ1WMPDUO9eTO0ehpiyKHjO+SaqC0nz5qRQB0RjsQ==", "dependencies": { "agentkeepalive": "4.1.4", "axios": "^0.21.4", @@ -56040,9 +56040,9 @@ } }, "sendbird": { - "version": "3.0.160", - "resolved": "https://registry.npmjs.org/sendbird/-/sendbird-3.0.160.tgz", - "integrity": "sha512-47ljPMszDJLdmYX3kOfpvnK/tPVPaw3UnvtpmYvJo5+yq1SqJFAm7o6Dbcs+cYHfalUGRNcaEU+rDUBo8993+Q==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/sendbird/-/sendbird-3.1.0.tgz", + "integrity": "sha512-bnb6VFBjLVFFzxSGNoSTqBfYdQk9fjq2JQp80U9vRszWTmQ1WMPDUO9eTO0ehpiyKHjO+SaqC0nz5qRQB0RjsQ==", "requires": { "agentkeepalive": "4.1.4", "axios": "^0.21.4", diff --git a/src/smart-components/Conversation/utils.js b/src/smart-components/Conversation/utils.js index 9bd319269..07c7f08ce 100644 --- a/src/smart-components/Conversation/utils.js +++ b/src/smart-components/Conversation/utils.js @@ -187,21 +187,23 @@ export const getNicknamesMapFromMembers = (members = []) => { export const getMessageCreatedAt = (message) => format(message.createdAt, 'p'); export const isSameGroup = (message, comparingMessage) => { - if ( - !message - || !comparingMessage - || !message.sender - || !comparingMessage.sender - || !message.createdAt - || !comparingMessage.createdAt - || !message.sender.userId - || !comparingMessage.sender.userId - ) { + if (!(message + && comparingMessage + && message?.messageType !== 'admin' + && comparingMessage?.messageType !== 'admin' + && message?.sender + && comparingMessage?.sender + && message?.createdAt + && comparingMessage?.createdAt + && message?.sender?.userId + && comparingMessage?.sender?.userId + )) { return false; } + return ( - message.sendingStatus === comparingMessage.sendingStatus - && message.sender.userId === comparingMessage.sender.userId + message?.sendingStatus === comparingMessage?.sendingStatus + && message?.sender?.userId === comparingMessage?.sender?.userId && getMessageCreatedAt(message) === getMessageCreatedAt(comparingMessage) ); }; diff --git a/src/smart-components/OpenchannelConversation/utils.ts b/src/smart-components/OpenchannelConversation/utils.ts index 63decefbc..b4cdd6323 100644 --- a/src/smart-components/OpenchannelConversation/utils.ts +++ b/src/smart-components/OpenchannelConversation/utils.ts @@ -21,29 +21,28 @@ export const scrollIntoLast = (intialTry = 0): void => { } }; - export const isSameGroup = ( message: SendbirdUIKit.EveryMessage, comparingMessage: SendbirdUIKit.EveryMessage, ): boolean => { - if ( - !message - || !comparingMessage - || message.messageType === 'admin' - || comparingMessage.messageType === 'admin' - || !message.sender - || !comparingMessage.sender - || !message.createdAt - || !comparingMessage.createdAt - || !message.sender.userId - || !comparingMessage.sender.userId - ) { + if (!( + message + && comparingMessage + && message?.messageType !== 'admin' + && comparingMessage?.messageType !== 'admin' + && message?.sender + && comparingMessage?.sender + && message?.createdAt + && comparingMessage?.createdAt + && message?.sender?.userId + && comparingMessage?.sender?.userId + )) { return false } return ( - message.sendingStatus === comparingMessage.sendingStatus - && message.sender.userId === comparingMessage.sender.userId + message?.sendingStatus === comparingMessage?.sendingStatus + && message?.sender?.userId === comparingMessage?.sender?.userId && getMessageCreatedAt(message) === getMessageCreatedAt(comparingMessage) ); }; @@ -53,11 +52,11 @@ export const compareMessagesForGrouping = ( currMessage: SendbirdUIKit.EveryMessage, nextMessage: SendbirdUIKit.EveryMessage, ): [boolean, boolean] => ( - [ - isSameGroup(prevMessage, currMessage), - isSameGroup(currMessage, nextMessage), - ] - ); + [ + isSameGroup(prevMessage, currMessage), + isSameGroup(currMessage, nextMessage), + ] +); export const kFormatter = (num: number): string => { if (Math.abs(num) > 999999) {