Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added avatar in thread message #921

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/react/src/views/ChatHeader/ChatHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ const ChatHeader = ({

const isThreadOpen = useMessageStore((state) => state.isThreadOpen);
const threadMainMessage = useMessageStore((state) => state.threadMainMessage);
const threadTitle =
threadMainMessage?.msg ||
(threadMainMessage?.file ? threadMainMessage.file.name : '');

const closeThread = useMessageStore((state) => state.closeThread);

Expand Down Expand Up @@ -423,7 +420,7 @@ const ChatHeader = ({
</Box>
{isThreadOpen && (
<DynamicHeader
title={threadTitle}
title={threadMainMessage}
handleClose={closeThread}
iconName="arrow-back"
/>
Expand Down
21 changes: 19 additions & 2 deletions packages/react/src/views/DynamicHeader/DynamicHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import { css } from '@emotion/react';
import { Box, Icon, ActionButton, Heading } from '@embeddedchat/ui-elements';
import useDynamicHeaderStyles from './DynamicHeader.styles';
import { Markdown } from '../Markdown';

const DynamicHeader = ({
title,
Expand All @@ -11,6 +12,22 @@ const DynamicHeader = ({
iconName,
headerIconName,
}) => {
const messageDescription = (msg) => {
if (msg.file) {
if (msg.attachments[0]?.description) {
return (
<Markdown
body={msg.attachments[0].description}
md={msg.attachments[0].descriptionMd}
isReaction={false}
/>
);
}
return msg.file.name;
}
return <Markdown body={msg} md={msg.md} isReaction={false} />;
};

const styles = useDynamicHeaderStyles();
return (
<Box css={styles.container}>
Expand All @@ -32,8 +49,8 @@ const DynamicHeader = ({
<Icon name={iconName} size="1.25rem" />
</ActionButton>

<Heading level={6} css={styles.clearSpacing}>
{title}
<Heading level={5} css={styles.clearSpacing}>
{messageDescription(title)}
</Heading>
{isHeaderIcon && <Icon name={headerIconName} size="1.25rem" />}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const useDynamicHeaderStyles = () => {
`,

clearSpacing: css`
margin: 0;
margin-bottom: 1px;
padding: 0;
text-overflow: ellipsis;
white-space: nowrap;
Expand Down
75 changes: 54 additions & 21 deletions packages/react/src/views/Message/MessageMetrics.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React from 'react';
import React, { useContext } from 'react';
import { formatDistance } from 'date-fns';
import {
Box,
Button,
Icon,
useComponentOverrides,
appendClassNames,
Avatar,
Tooltip,
} from '@embeddedchat/ui-elements';
import { MessageMetricsStyles as styles } from './Message.styles';
import RCContext from '../../context/RCInstance';

import BubbleThreadBtn from './BubbleVariant/BubbleThreadBtn';

export const MessageMetrics = ({
Expand All @@ -25,6 +29,16 @@ export const MessageMetrics = ({
style
);

const { RCInstance } = useContext(RCContext);

const getUserAvatarUrl = (username) => {
const host = RCInstance.getHost();
return `${host}/avatar/${username}`;
};

const participantsList =
message.replies.length - 1 > 0 ? `+${message.replies.length - 1}` : null;

return (
<Box
css={variantStyles.metricsContainer || styles.metrics}
Expand All @@ -46,31 +60,50 @@ export const MessageMetrics = ({
onClick={handleOpenThread(message)}
css={variantStyles && variantStyles.threadReplyButton}
>
Reply
View thread
</Button>
<Box css={styles.metricsItem(true)} title="Replies">
<Icon size="1.25rem" name="thread" />
<Box css={styles.metricsItemLabel}>{message.tcount}</Box>
</Box>
{!!message.tcount && (
<Box css={styles.metricsItem} title="Participants">
<Icon size="1.25rem" name="user" />
<Box css={styles.metricsItemLabel}>
{message.replies.length}
</Box>
</Box>
<>
<Tooltip text="Followers" position="top">
<Box css={styles.metricsItem}>
<Avatar
url={getUserAvatarUrl(message?.u.username)}
alt="avatar"
size="1rem"
/>
{participantsList && (
<span css={styles.metricsItemLabel}>
{participantsList}
</span>
)}
</Box>
</Tooltip>
</>
)}
<Box
css={styles.metricsItem}
title={new Date(message.tlm).toLocaleString()}

<Tooltip
text={`Last message: ${new Date(message.tlm).toLocaleTimeString(
[],
{
hour: '2-digit',
minute: '2-digit',
hour12: false,
}
)}`}
position="top"
>
<Icon size="1.25rem" name="clock" />
<Box css={styles.metricsItemLabel}>
{formatDistance(new Date(message.tlm), new Date(), {
addSuffix: true,
})}
<Box css={styles.metricsItem(true)}>
<Icon size="1.25rem" name="thread" />
<Box css={styles.metricsItemLabel}>
{message.tcount} replies,{' '}
{new Date(message.tlm).toLocaleTimeString([], {
hour: '2-digit',
minute: '2-digit',
hour12: false,
})}
</Box>
</Box>
</Box>
</Tooltip>
</>
))}
</Box>
Expand Down
Loading