Skip to content

Commit

Permalink
Improved_visibilityAndPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashraj7890 committed Mar 9, 2024
2 parents 2cba231 + f68f9d9 commit b991945
Show file tree
Hide file tree
Showing 64 changed files with 1,961 additions and 723 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _EmbeddedChat is a full-stack React component node module of the RocketChat appl
</div>

## Installation and Usage
Installtion and usage documentation could be found here [EmbeddedChat installation and usage](packages/react/README.md)
Installation and usage documentation could be found here [EmbeddedChat installation and usage](packages/react/README.md)

## Development

Expand Down
20 changes: 20 additions & 0 deletions packages/api/src/EmbeddedChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,26 @@ export default class EmbeddedChatApi {
}
}

async getMentionedMessages() {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
const response = await fetch(
`${this.host}/api/v1/chat.getMentionedMessages?roomId=${this.rid}`,
{
headers: {
"Content-Type": "application/json",
"X-Auth-Token": authToken,
"X-User-Id": userId,
},
method: "GET",
}
);
return await response.json();
} catch (err) {
console.error(err);
}
}

async pinMessage(mid: string) {
try {
const { userId, authToken } = (await this.auth.getCurrentUser()) || {};
Expand Down
39 changes: 39 additions & 0 deletions packages/react/src/components/Attachments/AttachmentMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import { ActionButton } from '../ActionButton';
import { Box } from '../Box';

const AttachmentMetadata = ({ attachment, url }) => {
const handleDownload = () => {
const anchor = document.createElement('a');
anchor.href = url;
anchor.download = attachment.title;

document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
};

return (
<>
<p style={{ margin: 0 }}>{attachment.description}</p>
<Box
style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}
>
<p style={{ margin: 0, color: 'grey' }}>{attachment.title}</p>
<ActionButton
ghost
icon="download"
size="small"
onClick={handleDownload}
style={{
marginLeft: '10px',
marginTop: '5px',
color: 'grey',
}}
/>
</Box>
</>
);
};

export default AttachmentMetadata;
6 changes: 5 additions & 1 deletion packages/react/src/components/Attachments/AudioAttachment.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Box } from '../Box';
import AttachmentMetadata from './AttachmentMetadata';

const AudioAttachment = ({ attachment, host }) => (
<Box>
<p>{attachment?.description}</p>
<AttachmentMetadata
attachment={attachment}
url={host + attachment.audio_url}
/>
<audio src={host + attachment.audio_url} width="100%" controls />
</Box>
);
Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/components/Attachments/ImageAttachment.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Box } from '../Box';
import AttachmentMetadata from './AttachmentMetadata';

const ImageAttachment = ({ attachment, host }) => (
<Box>
<p>{attachment?.description}</p>
<AttachmentMetadata
attachment={attachment}
url={host + attachment.image_url}
/>
<img
src={host + attachment.image_url}
style={{ maxWidth: '100%', objectFit: 'contain' }}
Expand Down
52 changes: 40 additions & 12 deletions packages/react/src/components/Attachments/PinnedAttachment.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
import React from 'react';
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { Box } from '../Box';
import { Avatar } from '../Avatar';
import RCContext from '../../context/RCInstance';

const PinnedAttachment = ({ attachment }) => (
<Box
style={{
borderInlineStart: '1px solid currentColor',
paddingLeft: '0.8rem',
}}
>
<Box>{attachment?.author_name}</Box>
<Box>{attachment?.text}</Box>
</Box>
);
const PinnedAttachment = ({ attachment }) => {
const { RCInstance } = useContext(RCContext);
const getUserAvatarUrl = (authorIcon) => {
const host = RCInstance.getHost();
const URL = `${host}${authorIcon}`;
return URL;
};
return (
<Box
style={{
borderInlineStart: '1px solid currentColor',
paddingLeft: '0.8rem',
}}
>
<Box
style={{
display: 'flex',
gap: '0.3rem',
}}
>
<Avatar
url={getUserAvatarUrl(attachment?.author_icon)}
alt="avatar"
size="1.2em"
/>
<Box>{attachment?.author_name}</Box>
</Box>
<Box
style={{
marginTop: '0.7rem',
}}
>
{attachment?.text}
</Box>
</Box>
);
};

export default PinnedAttachment;

Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/components/Attachments/VideoAttachment.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Box } from '../Box';
import AttachmentMetadata from './AttachmentMetadata';

const VideoAttachment = ({ attachment, host }) => (
<Box>
<p>{attachment?.description}</p>
<AttachmentMetadata
attachment={attachment}
url={host + attachment.video_url}
/>
<video width={300} controls>
<source src={host + attachment.video_url} type={attachment.video_type} />
</video>
Expand Down
27 changes: 15 additions & 12 deletions packages/react/src/components/ChatBody/ChatBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,21 @@ const ChatBody = ({
setViewData(null);
};

const onModalSubmit = useCallback(async (data, value) => {
console.log(data);
// const { actionId, value, blockId, appId, viewId } = data;
// await RCInstance?.triggerBlockAction({
// rid: RCInstance.rid,
// actionId,
// value,
// blockId,
// appId,
// viewId,
// });
});
const onModalSubmit = useCallback(
async (data) => {
console.log(data);
const { actionId, value, blockId, appId, viewId } = data;
await RCInstance?.triggerBlockAction({
rid: RCInstance.rid,
actionId,
value,
blockId,
appId,
viewId,
});
},
[RCInstance]
);

useEffect(() => {
RCInstance.auth.onAuthChange((user) => {
Expand Down
16 changes: 15 additions & 1 deletion packages/react/src/components/ChatHeader/ChatHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
useSearchMessageStore,
useChannelStore,
useToastStore,
useThreadsMessageStore,
useMentionsStore,
} from '../../store';
import { DynamicHeader } from '../DynamicHeader';
import { Tooltip } from '../Tooltip';
Expand All @@ -18,7 +20,6 @@ import useComponentOverrides from '../../theme/useComponentOverrides';
import { Icon } from '../Icon';
import { ActionButton } from '../ActionButton';
import { Menu } from '../Menu';
import useThreadsMessageStore from '../../store/threadsMessageStore';
import { useToastBarDispatch } from '../../hooks/useToastBarDispatch';
import useFetchChatData from '../../hooks/useFetchChatData';

Expand Down Expand Up @@ -73,6 +74,7 @@ const ChatHeader = ({
const setShowAllThreads = useThreadsMessageStore(
(state) => state.setShowAllThreads
);
const setShowMentions = useMentionsStore((state) => state.setShowMentions);
const toastPosition = useToastStore((state) => state.position);

const handleGoBack = async () => {
Expand Down Expand Up @@ -141,6 +143,11 @@ const ChatHeader = ({
setShowSearch(false);
}, [setShowAllThreads, setShowSearch]);

const showMentions = useCallback(async () => {
setShowMentions(true);
setShowSearch(false);
}, [setShowMentions, setShowSearch]);

useEffect(() => {
const setMessageAllowed = async () => {
const permissionRes = await RCInstance.permissionInfo();
Expand Down Expand Up @@ -223,6 +230,12 @@ const ChatHeader = ({
label: 'Threads',
icon: 'thread',
},
{
id: 'mentions',
action: showMentions,
label: 'Mentions',
icon: 'at',
},
{
id: 'members',
action: showChannelMembers,
Expand Down Expand Up @@ -273,6 +286,7 @@ const ChatHeader = ({
moreOpts,
setFullScreen,
showAllThreads,
showMentions,
showChannelMembers,
showChannelinformation,
showPinnedMessage,
Expand Down
Loading

0 comments on commit b991945

Please sign in to comment.