diff --git a/src/fragments/ChatMessages.tsx b/src/fragments/ChatMessages.tsx index 63dffb1..71b2b05 100644 --- a/src/fragments/ChatMessages.tsx +++ b/src/fragments/ChatMessages.tsx @@ -104,10 +104,11 @@ const ChatMessages: React.FC = ({ flexDirection="column-reverse" >
- {messages.map((message) => ( + {messages.map((message, index) => (
= ({ message, avatar, + previousMessage, }: MessageListItemProps) => { const sender: { displayName: string } = isUserMessage(message) ? message.user : { displayName: 'ChatKitty', }; - + const [isHovering, hoverProps] = useHover({ mouseEnterDelayMS: 0 }); - const {changeReply, getMessageParent} = useContext(ChatAppContext); - const [messageParent, setMessageParent] = useState(null); + const { changeReply, getMessageParent } = useContext(ChatAppContext); + const [messageParent, setMessageParent] = useState( + null + ); + const [sameUser, setSameUser] = useState(true); useEffect(() => { getMessageParent(message).then((message) => { - setMessageParent(message) + setMessageParent(message); }); - },[]) + if (previousMessage) { + const time = moment(message.createdTime); + const previousTime = moment(previousMessage.createdTime); + const ellapsedTime = time.diff(previousTime, 'minute'); + + setSameUser( + isUserMessage(previousMessage) && + previousMessage.user.displayName === sender.displayName && + ellapsedTime < 1 + ); + } + }, []); const changeReplyMessage = () => { changeReply(message); - } - + }; + const scrollToElement = () => { - const element = document.getElementById(String(messageParent?.id)) - - if(element){ + const element = document.getElementById(String(messageParent?.id)); + + if (element) { element.scrollIntoView(false); } - } - + }; - - return (<> - {messageParent && isUserMessage(messageParent) && - + {messageParent && isUserMessage(messageParent) && ( + + @{messageParent.user.displayName} + {isTextMessage(messageParent) &&

: {messageParent.body}

} + {isFileMessage(messageParent) &&

: {messageParent.file.name}

} +
+ )} + - @{messageParent.user.displayName} - {isTextMessage(messageParent) &&

: {messageParent.body}

} - {isFileMessage(messageParent) &&

: {messageParent.file.name}

} -
- } - - {avatar} - - - - {sender.displayName} - - - {isHovering && ( - - + + {(!sameUser || messageParent || !previousMessage) && ( + + {sender.displayName} + + )} + {(!sameUser || messageParent || !previousMessage) && ( + + )} + + + +
+ +
+ {isHovering && ( + - -
-
- +
+
- - )} - + + )} + - - - - - +
+ +
+ + +
); }; diff --git a/src/fragments/PopupEmojiWindow.tsx b/src/fragments/PopupEmojiWindow.tsx index ea8208d..b9f210c 100644 --- a/src/fragments/PopupEmojiWindow.tsx +++ b/src/fragments/PopupEmojiWindow.tsx @@ -43,7 +43,7 @@ const PopupEmojiWindow: React.FC = ({ message }: popupProp) => { }; return ( - + ); diff --git a/src/providers/ChatAppProvider.tsx b/src/providers/ChatAppProvider.tsx index bd93123..f9cf094 100644 --- a/src/providers/ChatAppProvider.tsx +++ b/src/providers/ChatAppProvider.tsx @@ -164,7 +164,11 @@ const ChatAppContextProvider: React.FC = ({ const views: Set = new Set(); const demoUsers = [ - '910746e1-d6e1-4df1-80b6-88ad90d7d2ad' + 'b2a6da08-88bf-4778-b993-7234e6d8a3ff', + 'c6f75947-af48-4893-a78e-0e0b9bd68580', + 'abc4264d-f1b1-41c0-b4cc-1e9daadfc893', + '2989c53a-d0c5-4222-af8d-fbf7b0c74ec6', + '8fadc920-f3e6-49ff-9398-1e58b3dc44dd', ]; const getLayout = (): LayoutState => {