Skip to content

Commit

Permalink
[issue-21645-bbb-core] added reply feature to playback chat.
Browse files Browse the repository at this point in the history
  • Loading branch information
GuiLeme committed Nov 19, 2024
1 parent e220e02 commit 9c5b125
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/chat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const Chat = () => {
}
};

const scrollTo = (element) => {
handleAutoScroll(firstNode.current, element, POSITIONS.TOP, config.align);
}
useEffect(() => {
if (!interaction.current) {
if (config.scroll) {
Expand All @@ -58,6 +61,7 @@ const Chat = () => {
>
<Messages
currentIndex={currentIndex}
scrollTo={scrollTo}
setRef={(node, index) => setRef(node, index)}
/>
</div>
Expand Down
14 changes: 13 additions & 1 deletion src/components/chat/messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const defaultProps = {

const Messages = ({
currentIndex,
scrollTo,
setRef,
}) => {

Expand All @@ -33,8 +34,17 @@ const Messages = ({
switch (type) {
case ID.USERS:

const indexOfMessageToBeReplied = (item.replyToMessageId)
? storage.messages.findIndex((message) => message.id === item.replyToMessageId) : -1;
const messageToBeReplied = (indexOfMessageToBeReplied !== -1)
? storage.messages[indexOfMessageToBeReplied]
: null;
return (
<span ref={node => setRef(node, index)}>
<span
key={item.id}
id={item.id}
className='user-message-wrapper'
ref={node => setRef(node, index)}>
<UserMessage
edited={!!item.lastEditedTimestamp}
reactions={item.reactions}
Expand All @@ -44,6 +54,8 @@ const Messages = ({
initials={item.initials}
moderator={item.moderator}
name={item.name}
messageToBeReplied={messageToBeReplied}
scrollTo={scrollTo}
text={item.message}
timestamp={timestamp}
/>
Expand Down
21 changes: 21 additions & 0 deletions src/components/chat/messages/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

:root {
--gray-light-color: var(--gray-light);
--gray-lightest-color: var(--gray-lightest);
--highlight-color: var(--blue);
}

.reply-tag {
background-color: var(--gray-lightest-color);
display: flex;
width: 90%;
padding: $padding-small;
margin-bottom: $margin-extra-small;
border-radius: .35rem;
align-items: center;
line-height: 1;
}

.user-message-wrapper {
transition: background-color .5s ease;
}

.highlight {
background-color: var(--highlight-color);
}

.message {
Expand Down
11 changes: 11 additions & 0 deletions src/components/chat/messages/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Info from './info';
import Margin from './margin';
import player from 'utils/player';
import './index.scss';
import Reply from './reply';
import ChatMessageReactions from './reactions';

const propTypes = {
Expand Down Expand Up @@ -39,6 +40,8 @@ const Message = ({
emphasized,
icon,
initials,
messageToBeReplied,
scrollTo,
edited,
name,
reactions,
Expand Down Expand Up @@ -68,6 +71,14 @@ const Message = ({
name={name}
timestamp={timestamp}
/>
{messageToBeReplied &&
<Reply
active={active}
scrollTo={scrollTo}
idToReference={messageToBeReplied.id}
text={messageToBeReplied.message}
/>
}
<div className={cx('text', { inactive: !active, emphasized })}>
{children}
</div>
Expand Down
54 changes: 54 additions & 0 deletions src/components/chat/messages/reply/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import '../index.scss';

const propTypes = {
active: PropTypes.bool,
idToReference: PropTypes.string,
text: PropTypes.string,
};

const defaultProps = {
active: false,
idToReference: '',
text: '',
};

const Reply = ({
active,
idToReference,
scrollTo,
text,
}) => {

const handleClickReply = () => {
const messageReplied = document.getElementById(idToReference);
scrollTo(messageReplied);
messageReplied.classList.add('highlight')
setTimeout(() =>
messageReplied.classList.remove('highlight'), 800
);
}

return (
<span
onClick={handleClickReply}
className={cx('reply-tag', {inactive: !active})}
>
{text}
</span>
);
};

Reply.propTypes = propTypes;
Reply.defaultProps = defaultProps;

// Checks the message active state
const areEqual = (prevProps, nextProps) => {
if (prevProps.active !== nextProps.active) return false;

return true;
};

export default React.memo(Reply, areEqual);
4 changes: 4 additions & 0 deletions src/components/chat/messages/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const User = ({
text,
edited,
timestamp,
messageToBeReplied,
scrollTo,
reactions,
}) => {

Expand All @@ -48,6 +50,8 @@ const User = ({
name={name}
reactions={reactions}
timestamp={timestamp}
messageToBeReplied={messageToBeReplied}
scrollTo={scrollTo}
>
<Text
active={active}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,15 @@ const buildChat = result => {
);
return {
clear,
id: chat._id,
emphasized,
hyperlink: message !== chat._message,
initials,
name: chat._name,
message,
moderator,
reactions,
replyToMessageId: chat._replyToMessageId,
lastEditedTimestamp: chat._lastEditedTimestamp,
timestamp: parseFloat(chat._in),
};
Expand Down

0 comments on commit 9c5b125

Please sign in to comment.