Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(chat): Display file uploads as inline chat messages

Hristo Terezova62fa3f8339a
diff --git a/lang/main.json b/lang/main.json
index 4194014cf2..2fcad29a74 100644
--- a/lang/main.json
+++ b/lang/main.json
@@ -114,6 +114,9 @@
"error": "Error: your message was not sent. Reason: {{error}}",
"everyone": "Everyone",
"fieldPlaceHolder": "Aa",
+ "fileAccessibleTitle": "{{user}} uploaded a file",
+ "fileAccessibleTitleMe": "me uploaded a file",
+ "fileDeleted": "A file was deleted",
"guestsChatIndicator": "(guest)",
"lobbyChatMessageTo": "Lobby chat message to {{recipient}}",
"message": "Message",
diff --git a/react/features/base/react/components/web/Message.tsx b/react/features/base/react/components/web/Message.tsx
index 2a54473c4b..c4235f21f0 100644
--- a/react/features/base/react/components/web/Message.tsx
+++ b/react/features/base/react/components/web/Message.tsx
@@ -57,7 +57,7 @@ class Message extends Component<IProps> {
const content: any[] = [];
const { gifEnabled } = this.props;
- // check if the message is a GIF
+ // Check if the message is a GIF
if (gifEnabled && isGifMessage(text)) {
const url = extractGifURL(text);
diff --git a/react/features/chat/components/web/ChatMessage.tsx b/react/features/chat/components/web/ChatMessage.tsx
index 198aedc0c3..2f2b776643 100644
--- a/react/features/chat/components/web/ChatMessage.tsx
+++ b/react/features/chat/components/web/ChatMessage.tsx
@@ -9,9 +9,10 @@ import { getParticipantById, getParticipantDisplayName, isPrivateChatEnabled } f
import Popover from '../../../base/popover/components/Popover.web';
import Message from '../../../base/react/components/web/Message';
import { MESSAGE_TYPE_LOCAL } from '../../constants';
-import { getDisplayNameSuffix, getFormattedTimestamp, getMessageText, getPrivateNoticeMessage } from '../../functions';
+import { getDisplayNameSuffix, getFormattedTimestamp, getMessageText, getPrivateNoticeMessage, isFileMessage } from '../../functions';
import { IChatMessageProps } from '../../types';
+import FileMessage from './FileMessage';
import MessageMenu from './MessageMenu';
import ReactButton from './ReactButton';
@@ -48,6 +49,22 @@ const useStyles = makeStyles()((theme: Theme) => {
marginTop: '4px',
boxSizing: 'border-box' as const,
+ '&.file': {
+ display: 'flex',
+ maxWidth: '100%',
+ minWidth: 0,
+
+ '& $replyWrapper': {
+ width: '100%',
+ minWidth: 0
+ },
+
+ '& $messageContent': {
+ width: '100%',
+ minWidth: 0
+ }
+ },
+
'&.privatemessage': {
backgroundColor: theme.palette.support05
},
@@ -117,8 +134,7 @@ const useStyles = makeStyles()((theme: Theme) => {
},
messageContent: {
maxWidth: '100%',
- overflow: 'hidden',
- flex: 1
+ overflow: 'hidden'
},
optionsButtonContainer: {
display: 'flex',
@@ -344,6 +360,7 @@ const ChatMessage = ({
{isHovered && <MessageMenu
displayName = { message.displayName }
enablePrivateChat = { Boolean(enablePrivateChat) }
+ isFileMessage = { isFileMessage(message) }
isFromVisitor = { message.isFromVisitor }
isLobbyMessage = { message.lobbyChat }
message = { message.message }
@@ -356,19 +373,31 @@ const ChatMessage = ({
classes.chatMessage,
className,
message.privateMessage && 'privatemessage',
- message.lobbyChat && !knocking && 'lobbymessage'
+ message.lobbyChat && !knocking && 'lobbymessage',
+ isFileMessage(message) && 'file'
) }>
<div className = { classes.replyWrapper }>
<div className = { cx('messagecontent', classes.messageContent) }>
{showDisplayName && _renderDisplayName()}
<div className = { cx('usermessage', classes.userMessage) }>
- <Message
- screenReaderHelpText = { message.displayName === message.recipient
- ? t<string>('chat.messageAccessibleTitleMe')
- : t<string>('chat.messageAccessibleTitle', {
- user: message.displayName
- }) }
- text = { getMessageText(message) } />
+ {isFileMessage(message) ? (
+ <FileMessage
+ message = { message }
+ screenReaderHelpText = { message.messageType === MESSAGE_TYPE_LOCAL
+ ? t<string>('chat.fileAccessibleTitleMe')
+ : t<string>('chat.fileAccessibleTitle', {
+ user: message.displayName
+ })
+ } />
+ ) : (
+ <Message
+ screenReaderHelpText = { message.messageType === MESSAGE_TYPE_LOCAL
+ ? t<string>('chat.messageAccessibleTitleMe')
+ : t<string>('chat.messageAccessibleTitle', {
+ user: message.displayName
+ }) }
+ text = { getMessageText(message) } />
+ )}
{(message.privateMessage || (message.lobbyChat && !knocking))
&& _renderPrivateNotice()}
<div className = { classes.chatMessageFooter }>
@@ -400,6 +429,7 @@ const ChatMessage = ({
{isHovered && <MessageMenu
displayName = { message.displayName }
enablePrivateChat = { Boolean(enablePrivateChat) }
+ isFileMessage = { isFileMessage(message) }
isFromVisitor = { message.isFromVisitor }
isLobbyMessage = { message.lobbyChat }
message = { message.message }
diff --git a/react/features/chat/components/web/ChatMessageGroup.tsx b/react/features/chat/components/web/ChatMessageGroup.tsx
index 93eefd217e..400c041f22 100644
--- a/react/features/chat/components/web/ChatMessageGroup.tsx
+++ b/react/features/chat/components/web/ChatMessageGroup.tsx
@@ -27,7 +27,7 @@ const useStyles = makeStyles()(theme => {
flexDirection: 'column',
maxWidth: '100%',
- '&.remote': {
+ '&.remote, &.file': {
maxWidth: 'calc(100% - 40px)' // 100% - avatar and margin
}
},
diff --git a/react/features/chat/components/web/FileMessage.tsx b/react/features/chat/components/web/FileMessage.tsx
new file mode 100644
index 0000000000..57a35cf4a5
--- /dev/null
+++ b/react/features/chat/components/web/FileMessage.tsx
@@ -0,0 +1,143 @@
+import React, { useCallback } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useDispatch, useSelector } from 'react-redux';
+import { makeStyles } from 'tss-react/mui';
+
+import { downloadFile, removeFile } from '../../../file-sharing/actions';
+import FileItem from '../../../file-sharing/components/web/FileItem';
+import { isFileUploadingEnabled } from '../../../file-sharing/functions.any';
+import { IMessage } from '../../types';
+
+/**
+ * Props for the FileMessage component.
+ */
+interface IFileMessageProps {
+
+ /**
+ * Additional CSS class name.
+ */
+ className?: string;
+
+ /**
+ * The message containing file metadata.
+ */
+ message: IMessage;
+
+ /**
+ * Screen reader help text for accessibility.
+ */
+ screenReaderHelpText?: string;
+}
+
+const useStyles = makeStyles()(theme => {
+ return {
+ fileMessageContainer: {
+ margin: `${theme.spacing(1)} 0`,
+ maxWidth: '100%',
+ minWidth: 0,
+ padding: 0,
+ display: 'flex',
+ flexDirection: 'column',
+
+ // Override FileItem styles for compact chat display
+ '& .fileItem': {
+ padding: theme.spacing(2), // Reduced from 3 (24px → 16px)
+ gap: theme.spacing(2), // Reduced from 3
+
+ // Add background to button container to hide text underneath in chat context
+ '& > div:last-child': {
+ backgroundColor: theme.palette.ui02,
+ paddingLeft: theme.spacing(2)
+ },
+
+ '&:hover > div:last-child': {
+ backgroundColor: theme.palette.ui03
+ }
+ },
+
+ '& .fileName': {
+ ...theme.typography.bodyShortRegular // Match message text font
+ },
+
+ '& .fileSize': {
+ ...theme.typography.labelRegular // Keep smaller for metadata
+ }
+ },
+ deletedFileMessage: {
+ ...theme.typography.bodyShortRegular,
+ fontStyle: 'italic',
+ color: theme.palette.text02,
+ padding: theme.spacing(1, 0)
+ }
+ };
+});
+
+/**
+ * Component for displaying file messages in chat.
+ *
+ * @param {IFileMessageProps} props - The component props.
+ * @returns {JSX.Element | null} The FileMessage component or null if no file metadata.
+ */
+const FileMessage = ({ className = '', message, screenReaderHelpText }: IFileMessageProps) => {
+ const { classes, cx } = useStyles();
+ const dispatch = useDispatch();
+ const { t } = useTranslation();
+ const isUploadEnabled = useSelector(isFileUploadingEnabled);
+
+ /**
+ * Handles the download action for a file.
+ *
+ * @param {string} fileId - The ID of the file to download.
+ * @returns {void}
+ */
+ const handleDownload = useCallback((fileId: string) => {
+ dispatch(downloadFile(fileId));
+ }, [ dispatch ]);
+
+ /**
+ * Handles the remove action for a file.
+ *
+ * @param {string} fileId - The ID of the file to remove.
+ * @returns {void}
+ */
+ const handleRemove = useCallback((fileId: string) => {
+ dispatch(removeFile(fileId));
+ }, [ dispatch ]);
+
+ if (!message.fileMetadata) {
+ return null;
+ }
+
+ // If the file has been deleted, show a deletion message instead of the file item.
+ if (message.fileMetadata.isDeleted) {
+ return (
+ <div className = { cx(classes.fileMessageContainer, className) }>
+ <div className = { classes.deletedFileMessage }>
+ {t('chat.fileDeleted')}
+ </div>
+ </div>
+ );
+ }
+
+ return (
+ <div className = { cx(classes.fileMessageContainer, className) }>
+ {screenReaderHelpText && (
+ <span className = 'sr-only'>
+ {screenReaderHelpText}
+ </span>
+ )}
+ <FileItem
+ actionsVisible = { true }
+ className = 'fileItem'
+ file = { message.fileMetadata }
+ iconSize = { 40 }
+ onDownload = { handleDownload }
+ onRemove = { handleRemove }
+ showAuthor = { false }
+ showRemoveButton = { isUploadEnabled }
+ showTimestamp = { false } />
+ </div>
+ );
+};
+
+export default FileMessage;
diff --git a/react/features/chat/components/web/MessageMenu.tsx b/react/features/chat/components/web/MessageMenu.tsx
index 497957293b..64a995efc6 100644
--- a/react/features/chat/components/web/MessageMenu.tsx
+++ b/react/features/chat/components/web/MessageMenu.tsx
@@ -17,6 +17,7 @@ export interface IProps {
className?: string;
displayName?: string;
enablePrivateChat: boolean;
+ isFileMessage?: boolean;
isFromVisitor?: boolean;
isLobbyMessage: boolean;
message: string;
@@ -60,7 +61,7 @@ const useStyles = makeStyles()(theme => {
};
});
-const MessageMenu = ({ message, participantId, isFromVisitor, isLobbyMessage, enablePrivateChat, displayName }: IProps) => {
+const MessageMenu = ({ message, participantId, isFromVisitor, isLobbyMessage, enablePrivateChat, displayName, isFileMessage }: IProps) => {
const dispatch = useDispatch();
const { classes, cx } = useStyles();
const { t } = useTranslation();
@@ -72,6 +73,11 @@ const MessageMenu = ({ message, participantId, isFromVisitor, isLobbyMessage, en
const participant = useSelector((state: IReduxState) => getParticipantById(state, participantId));
+ // If no menu items will be shown, don't render the menu button.
+ if (!enablePrivateChat && isFileMessage) {
+ return null;
+ }
+
const handleMenuClick = useCallback(() => {
setIsPopoverOpen(true);
}, []);
@@ -137,11 +143,13 @@ const MessageMenu = ({ message, participantId, isFromVisitor, isLobbyMessage, en
{t('Private Message')}
</div>
)}
- <div
- className = { classes.menuItem }
- onClick = { handleCopyClick }>
- {t('Copy')}
- </div>
+ {!isFileMessage && (
+ <div
+ className = { classes.menuItem }
+ onClick = { handleCopyClick }>
+ {t('Copy')}
+ </div>
+ )}
</div>
);
diff --git a/react/features/chat/functions.ts b/react/features/chat/functions.ts
index 29bd9680c5..ff74630cf7 100644
--- a/react/features/chat/functions.ts
+++ b/react/features/chat/functions.ts
@@ -293,3 +293,13 @@ export function getDisplayNameSuffix(message: IMessage): string {
return suffix;
}
+
+/**
+ * Checks if a message is a file message by verifying the presence of file metadata.
+ *
+ * @param {IMessage} message - The message to check.
+ * @returns {boolean} True if the message contains file metadata, false otherwise.
+ */
+export function isFileMessage(message: IMessage): boolean {
+ return Boolean(message?.fileMetadata);
+}
diff --git a/react/features/chat/reducer.ts b/react/features/chat/reducer.ts
index 00569d394b..1380d6b513 100644
--- a/react/features/chat/reducer.ts
+++ b/react/features/chat/reducer.ts
@@ -71,6 +71,7 @@ ReducerRegistry.register<IChatState>('features/chat', (state = DEFAULT_STATE, ac
const newMessage: IMessage = {
displayName: action.displayName,
error: action.error,
+ fileMetadata: action.fileMetadata,
isFromGuest: Boolean(action.isFromGuest),
isFromVisitor: Boolean(action.isFromVisitor),
participantId: action.participantId,
diff --git a/react/features/chat/types.ts b/react/features/chat/types.ts
index 88c98a0c95..1a2b58b131 100644
--- a/react/features/chat/types.ts
+++ b/react/features/chat/types.ts
@@ -1,10 +1,12 @@
import { WithTranslation } from 'react-i18next';
import { IStore } from '../app/types';
+import { IFileMetadata } from '../file-sharing/types';
export interface IMessage {
displayName: string;
error?: Object;
+ fileMetadata?: IFileMetadata;
isFromGuest?: boolean;
isFromVisitor?: boolean;
isReaction: boolean;
diff --git a/react/features/file-sharing/components/web/FileItem.tsx b/react/features/file-sharing/components/web/FileItem.tsx
new file mode 100644
index 0000000000..772c52ca76
--- /dev/null
+++ b/react/features/file-sharing/components/web/FileItem.tsx
@@ -0,0 +1,369 @@
+import React, { useCallback, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { makeStyles } from 'tss-react/mui';
+
+import Avatar from '../../../base/avatar/components/Avatar';
+import Icon from '../../../base/icons/components/Icon';
+import { IconDownload, IconTrash } from '../../../base/icons/svg';
+import BaseTheme from '../../../base/ui/components/BaseTheme.web';
+import {
+ formatFileSize,
+ formatTimestamp,
+ getFileIcon
+} from '../../functions.any';
+import { IFileMetadata } from '../../types';
+
+/**
+ * Props for the FileItem component.
+ */
+interface IFileItemProps {
+
+ /**
+ * Whether to show action buttons (download, remove).
+ */
+ actionsVisible?: boolean;
+
+ /**
+ * Additional CSS class name.
+ */
+ className?: string;
+
+ /**
+ * The file metadata to display.
+ */
+ file: IFileMetadata;
+
+ /**
+ * Size of the file icon in pixels (default: 64).
+ */
+ iconSize?: number;
+
+ /**
+ * Callback function when download button is clicked.
+ */
+ onDownload?: (fileId: string) => void;
+
+ /**
+ * Callback function when remove button is clicked.
+ */
+ onRemove?: (fileId: string) => void;
+
+ /**
+ * Whether to show the author/uploader information.
+ */
+ showAuthor?: boolean;
+
+ /**
+ * Whether to show the remove button.
+ */
+ showRemoveButton?: boolean;
+
+ /**
+ * Whether to show the timestamp.
+ */
+ showTimestamp?: boolean;
+}
+
+const useStyles = makeStyles()(theme => {
+ return {
+ buttonContainer: {
+ alignItems: 'center',
+ bottom: 0,
+ display: 'flex',
+ justifyContent: 'end',
+ gap: theme.spacing(2),
+ position: 'absolute',
+ right: theme.spacing(3),
+ top: 0
+ },
+
+ fileIconContainer: {
+ display: 'flex',
+ flexShrink: 0,
+ margin: 'auto'
+ },
+
+ fileItem: {
+ backgroundColor: theme.palette.ui02,
+ borderRadius: theme.shape.borderRadius,
+ boxSizing: 'border-box',
+ display: 'flex',
+ flexDirection: 'row',
+ gap: theme.spacing(3),
+ justifyContent: 'space-between',
+ maxWidth: '100%',
+ minWidth: 0,
+ padding: theme.spacing(3),
+ position: 'relative',
+
+ '& .actionIconVisibility': {
+ opacity: 0,
+ transition: 'opacity 0.2s'
+ },
+
+ '& .timestampVisibility': {
+ opacity: 1
+ },
+
+ '&:hover': {
+ backgroundColor: theme.palette.ui03,
+
+ '& .actionIconVisibility': {
+ opacity: 1
+ },
+
+ '& .timestampVisibility': {
+ opacity: 0
+ }
+ },
+
+ '&.focused .actionIconVisibility': {
+ opacity: 1
+ },
+
+ '&.focused .timestampVisibility': {
+ opacity: 0
+ }
+ },
+
+ fileItemDetails: {
+ display: 'flex',
+ flexDirection: 'column',
+ flex: 1,
+ gap: theme.spacing(1),
+ justifyContent: 'center',
+ minWidth: 0,
+ overflow: 'hidden'
+ },
+
+ fileName: {
+ ...theme.typography.labelBold,
+ gap: theme.spacing(1),
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap'
+ },
+
+ fileAuthorParticipant: {
+ alignItems: 'center',
+ display: 'inline-flex',
+ gap: theme.spacing(1)
+ },
+
+ fileAuthorParticipantName: {
+ ...theme.typography.labelBold,
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap'
+ },
+
+ fileSize: {
+ ...theme.typography.labelRegular
+ },
+
+ fileTimestamp: {
+ ...theme.typography.labelRegular,
+ display: 'flex',
+ lineHeight: '1.2rem',
+ marginTop: theme.spacing(1),
+ textAlign: 'center'
+ },
+
+ iconButton: {
+ background: 'none',
+ border: 'none',
+ cursor: 'pointer',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ marginLeft: '8px',
+ padding: 0,
+
+ '&:focus-visible': {
+ outline: `2px solid ${theme.palette.action01}`,
+ borderRadius: '4px'
+ }
+ },
+
+ progressBar: {
+ backgroundColor: theme.palette.ui03,
+ borderRadius: theme.shape.borderRadius,
+ height: 4,
+ overflow: 'hidden',
+ width: '100%'
+ },
+
+ progressFill: {
+ backgroundColor: theme.palette.action01,
+ height: '100%',
+ transition: 'width 0.3s ease'
+ }
+ };
+});
+
+/**
+ * Component for displaying file information in a consistent way across the application.
+ *
+ * @param {IFileItemProps} props - The component props.
+ * @returns {JSX.Element} The FileItem component.
+ */
+const FileItem = ({
+ actionsVisible = true,
+ className = '',
+ file,
+ iconSize = 64,
+ onDownload,
+ onRemove,
+ showAuthor = true,
+ showRemoveButton = false,
+ showTimestamp = true
+}: IFileItemProps) => {
+ const { classes, cx } = useStyles();
+ const [ isFocused, setIsFocused ] = useState(false);
+ const { t } = useTranslation();
+ const isUploading = (file.progress ?? 100) < 100;
+
+ /**
+ * Handles the download button click.
+ *
+ * @returns {void}
+ */
+ const handleDownload = useCallback(() => {
+ onDownload?.(file.fileId);
+ }, [ onDownload, file.fileId ]);
+
+ /**
+ * Handles the remove button click.
+ *
+ * @returns {void}
+ */
+ const handleRemove = useCallback(() => {
+ onRemove?.(file.fileId);
+ }, [ onRemove, file.fileId ]);
+
+ /**
+ * Handles blur event to remove focus state.
+ *
+ * @param {React.FocusEvent} e - The blur event.
+ * @returns {void}
+ */
+ const handleBlur = useCallback((e: React.FocusEvent) => {
+ if (!e.currentTarget.contains(e.relatedTarget as Node)) {
+ setIsFocused(false);
+ }
+ }, []);
+
+ /**
+ * Handles focus event to set focus state.
+ *
+ * @returns {void}
+ */
+ const handleFocus = useCallback(() => {
+ setIsFocused(true);
+ }, []);
+
+ return (
+ <div
+ className = { cx(classes.fileItem, isFocused && 'focused', className) }
+ key = { file.fileId }
+ onBlur = { handleBlur }
+ onFocus = { handleFocus }
+ tabIndex = { -1 }
+ title = { file.fileName }>
+ {
+ !isUploading && (
+ <>
+ <div className = { classes.fileIconContainer }>
+ <Icon
+ color = { BaseTheme.palette.icon01 }
+ size = { iconSize }
+ src = { getFileIcon(file.fileType) } />
+ </div>
+ <div className = { classes.fileItemDetails }>
+ <div className = { cx(classes.fileName, 'fileName') }>
+ { file.fileName }
+ </div>
+ <div className = { cx(classes.fileSize, 'fileSize') }>
+ { formatFileSize(file.fileSize) }
+ </div>
+ {
+ showAuthor && (
+ <div className = { classes.fileAuthorParticipant }>
+ <Avatar
+ displayName = { file.authorParticipantName }
+ participantId = { file.authorParticipantId }
+ size = { 16 } />
+ <div className = { classes.fileAuthorParticipantName }>
+ { file.authorParticipantName }
+ </div>
+ </div>
+ )
+ }
+ </div>
+ {
+ showTimestamp && (
+ <div className = { `${classes.fileTimestamp} timestampVisibility` }>
+ <pre>
+ { formatTimestamp(file.timestamp) }
+ </pre>
+ </div>
+ )
+ }
+ {
+ actionsVisible && (
+ <div className = { `${classes.buttonContainer} actionIconVisibility` }>
+ {
+ onDownload && (
+ <button
+ aria-label = { `${t('fileSharing.downloadFile')} ${file.fileName}` }
+ className = { classes.iconButton }
+ onClick = { handleDownload }
+ type = 'button'>
+ <Icon
+ color = { BaseTheme.palette.icon01 }
+ size = { 24 }
+ src = { IconDownload } />
+ </button>
+ )
+ }
+
+ {
+ showRemoveButton && onRemove && (
+ <button
+ aria-label = { `${t('fileSharing.removeFile')} ${file.fileName}` }
+ className = { classes.iconButton }
+ onClick = { handleRemove }
+ type = 'button'>
+ <Icon
+ color = { BaseTheme.palette.icon01 }
+ size = { 24 }
+ src = { IconTrash } />
+ </button>
+ )
+ }
+ </div>
+ )
+ }
+ </>
+ )
+ }
+ {
+ isUploading && (
+ <div
+ aria-label = { t('fileSharing.fileUploadProgress') }
+ aria-valuemax = { 100 }
+ aria-valuemin = { 0 }
+ aria-valuenow = { file.progress }
+ className = { classes.progressBar }
+ role = 'progressbar'>
+ <div
+ className = { classes.progressFill }
+ style = {{ width: `${file.progress}%` }} />
+ </div>
+ )
+ }
+ </div>
+ );
+};
+
+export default FileItem;
diff --git a/react/features/file-sharing/components/web/FileSharing.tsx b/react/features/file-sharing/components/web/FileSharing.tsx
index 68c5299e15..0684016e67 100644
--- a/react/features/file-sharing/components/web/FileSharing.tsx
+++ b/react/features/file-sharing/components/web/FileSharing.tsx
@@ -4,34 +4,21 @@ import { useDispatch, useSelector, useStore } from 'react-redux';
import { makeStyles } from 'tss-react/mui';
import { IReduxState } from '../../../app/types';
-import Avatar from '../../../base/avatar/components/Avatar';
import Icon from '../../../base/icons/components/Icon';
-import { IconCloudUpload, IconDownload, IconTrash } from '../../../base/icons/svg';
+import { IconCloudUpload } from '../../../base/icons/svg';
import BaseTheme from '../../../base/ui/components/BaseTheme.web';
import Button from '../../../base/ui/components/web/Button';
import { BUTTON_TYPES } from '../../../base/ui/constants.web';
import { downloadFile, removeFile } from '../../actions';
import {
- formatFileSize,
- formatTimestamp,
- getFileIcon,
isFileUploadingEnabled,
processFiles
} from '../../functions.any';
+import FileItem from './FileItem';
+
const useStyles = makeStyles()(theme => {
return {
- buttonContainer: {
- alignItems: 'center',
- bottom: 0,
- display: 'flex',
- justifyContent: 'end',
- gap: theme.spacing(2),
- position: 'absolute',
- right: theme.spacing(3),
- top: 0
- },
-
container: {
boxSizing: 'border-box',
display: 'flex',
@@ -64,60 +51,6 @@ const useStyles = makeStyles()(theme => {
}
},
- fileIconContainer: {
- display: 'flex',
- margin: 'auto'
- },
-
- fileItem: {
- backgroundColor: theme.palette.ui02,
- borderRadius: theme.shape.borderRadius,
- display: 'flex',
- flexDirection: 'row',
- gap: theme.spacing(3),
- justifyContent: 'space-between',
- padding: theme.spacing(3),
- position: 'relative',
-
- '& .actionIconVisibility': {
- opacity: 0,
- transition: 'opacity 0.2s'
- },
-
- '& .timestampVisibility': {
- opacity: 1
- },
-
- '&:hover': {
- backgroundColor: theme.palette.ui03,
-
- '& .actionIconVisibility': {
- opacity: 1
- },
-
- '& .timestampVisibility': {
- opacity: 0
- }
- },
-
- '&.focused .actionIconVisibility': {
- opacity: 1
- },
-
- '&.focused .timestampVisibility': {
- opacity: 0
- }
- },
-
- fileItemDetails: {
- display: 'flex',
- flexDirection: 'column',
- flexGrow: 2,
- gap: theme.spacing(1),
- justifyContent: 'center',
- minWidth: 0
- },
-
fileList: {
display: 'flex',
flex: 1,
@@ -129,40 +62,13 @@ const useStyles = makeStyles()(theme => {
marginTop: 0,
overflowY: 'auto',
padding: 0,
- zIndex: 1
- },
-
- fileName: {
- ...theme.typography.labelBold,
- gap: theme.spacing(1),
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- whiteSpace: 'nowrap'
- },
-
- fileAuthorParticipant: {
- alignItems: 'center',
- display: 'inline-flex',
- gap: theme.spacing(1)
- },
-
- fileAuthorParticipantName: {
- ...theme.typography.labelBold,
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- whiteSpace: 'nowrap'
- },
-
- fileSize: {
- ...theme.typography.labelRegular
- },
+ zIndex: 1,
- fileTimestamp: {
- ...theme.typography.labelRegular,
- display: 'flex',
- lineHeight: '1.2rem',
- marginTop: theme.spacing(1),
- textAlign: 'center',
+ '& > li': {
+ listStyleType: 'none',
+ margin: 0,
+ padding: 0
+ }
},
hiddenInput: {
@@ -184,20 +90,6 @@ const useStyles = makeStyles()(theme => {
textAlign: 'center'
},
- progressBar: {
- backgroundColor: theme.palette.ui03,
- borderRadius: theme.shape.borderRadius,
- height: 4,
- overflow: 'hidden',
- width: '100%'
- },
-
- progressFill: {
- backgroundColor: theme.palette.action01,
- height: '100%',
- transition: 'width 0.3s ease'
- },
-
uploadButton: {
bottom: theme.spacing(4),
cursor: 'pointer',
@@ -210,33 +102,6 @@ const useStyles = makeStyles()(theme => {
uploadIcon: {
margin: '0 auto'
- },
-
- actionIcon: {
- background: 'transparent',
- border: 0,
- cursor: 'pointer',
- padding: theme.spacing(1),
- visibility: 'hidden',
- '&:focus': {
- outline: `2px solid ${theme.palette.action01}`
- }
- },
-
- iconButton: {
- background: 'none',
- border: 'none',
- padding: 0,
- marginLeft: '8px',
- cursor: 'pointer',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
-
- '&:focus-visible': {
- outline: `2px solid ${theme.palette.action01}`,
- borderRadius: '4px'
- }
}
};
});
@@ -244,7 +109,6 @@ const useStyles = makeStyles()(theme => {
const FileSharing = () => {
const { classes } = useStyles();
const [ isDragging, setIsDragging ] = useState(false);
- const [ isFocused, setIsFocused ] = useState(false);
const fileInputRef = useRef<HTMLInputElement>(null);
const uploadButtonRef = useRef<HTMLButtonElement>(null);
const { t } = useTranslation();
@@ -349,92 +213,12 @@ const FileSharing = () => {
<ul className = { classes.fileList }>
{
sortedFiles.map(file => (
- <li
- className = { `${classes.fileItem} ${isFocused ? 'focused' : ''}` }
- key = { file.fileId }
- // Only remove focus when leaving the whole fileItem, not just moving between its buttons
- onBlur = { e => !e.currentTarget.contains(e.relatedTarget as Node) && setIsFocused(false) }
- onFocus = { () => setIsFocused(true) }
- tabIndex = { -1 }
- title = { file.fileName }>
- {
- (file.progress ?? 100) === 100 && (
- <>
- <div className = { classes.fileIconContainer }>
- <Icon
- color = { BaseTheme.palette.icon01 }
- size = { 64 }
- src = { getFileIcon(file.fileType) } />
- </div>
- <div className = { classes.fileItemDetails }>
- <div className = { classes.fileName }>
- { file.fileName }
- </div>
- <div className = { classes.fileSize }>
- { formatFileSize(file.fileSize) }
- </div>
- <div className = { classes.fileAuthorParticipant }>
- <Avatar
- displayName = { file.authorParticipantName }
- participantId = { file.authorParticipantId }
- size = { 16 } />
- <div className = { classes.fileAuthorParticipantName }>
- { file.authorParticipantName }
- </div>
- </div>
- </div>
- <div className = { `${classes.fileTimestamp} timestampVisibility` }>
- <pre>
- { formatTimestamp(file.timestamp) }
- </pre>
- </div>
- <div className = { `${classes.buttonContainer} actionIconVisibility` }>
- <button
- aria-label = { `${t('fileSharing.downloadFile')} ${file.fileName}` }
- className = { `${classes.iconButton}` }
- onClick = { () => dispatch(downloadFile(file.fileId)) }
- type = 'button'>
- <Icon
- color = { BaseTheme.palette.icon01 }
- size = { 24 }
- src = { IconDownload } />
- </button>
-
- {
- isUploadEnabled && (
- <button
- aria-label = { `${t('fileSharing.removeFile')} ${file.fileName}` }
- className = { `${classes.iconButton}` }
- onClick = { () => dispatch(removeFile(file.fileId)) }
- type = 'button'>
- <Icon
- color = { BaseTheme.palette.icon01 }
- size = { 24 }
- src = { IconTrash } />
- </button>
- )
- }
- </div>
- </>
- )
- }
- {
- (file.progress ?? 100) < 100 && (
- <>
- <div
- aria-label = { t('fileSharing.fileUploadProgress') }
- aria-valuemax = { 100 }
- aria-valuemin = { 0 }
- aria-valuenow = { file.progress }
- className = { classes.progressBar }
- role = 'progressbar'>
- <div
- className = { classes.progressFill }
- style = {{ width: `${file.progress}%` }} />
- </div>
- </>
- )
- }
+ <li key = { file.fileId }>
+ <FileItem
+ file = { file }
+ onDownload = { fileId => dispatch(downloadFile(fileId)) }
+ onRemove = { fileId => dispatch(removeFile(fileId)) }
+ showRemoveButton = { isUploadEnabled } />
</li>
))
}
diff --git a/react/features/file-sharing/middleware.web.ts b/react/features/file-sharing/middleware.web.ts
index 0d2d4773a4..9e6acb250b 100644
--- a/react/features/file-sharing/middleware.web.ts
+++ b/react/features/file-sharing/middleware.web.ts
@@ -6,12 +6,21 @@ import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
import { getLocalParticipant, getParticipantDisplayName } from '../base/participants/functions';
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
-import { ChatTabs } from '../chat/constants';
+import { addMessage, editMessage } from '../chat/actions.any';
+import { ChatTabs, MESSAGE_TYPE_LOCAL, MESSAGE_TYPE_REMOTE } from '../chat/constants';
import { showErrorNotification, showNotification, showSuccessNotification } from '../notifications/actions';
import { NOTIFICATION_TIMEOUT_TYPE, NOTIFICATION_TYPE } from '../notifications/constants';
import { I_AM_VISITOR_MODE } from '../visitors/actionTypes';
-import { DOWNLOAD_FILE, REMOVE_FILE, UPLOAD_FILES, _FILE_LIST_RECEIVED, _FILE_REMOVED } from './actionTypes';
+import {
+ ADD_FILE,
+ DOWNLOAD_FILE,
+ REMOVE_FILE,
+ UPDATE_FILE_UPLOAD_PROGRESS,
+ UPLOAD_FILES,
+ _FILE_LIST_RECEIVED,
+ _FILE_REMOVED
+} from './actionTypes';
import { addFile, removeFile, updateFileProgress } from './actions';
import { getFileExtension } from './functions.any';
import logger from './logger';
@@ -110,6 +119,44 @@ MiddlewareRegistry.register(store => next => action => {
return next(action);
}
+ case UPDATE_FILE_UPLOAD_PROGRESS:
+ case ADD_FILE: {
+ const result = next(action);
+ const state = store.getState();
+ const { files } = state['features/file-sharing'];
+ const file = action.type === ADD_FILE ? action.file as IFileMetadata : files.get(action.fileId);
+
+ if (!file) {
+ return result;
+ }
+
+ const localParticipant = getLocalParticipant(state);
+ const isLocalFile = localParticipant?.id === file.authorParticipantId;
+
+ // Only dispatch chat message for fully uploaded files (progress === 100).
+ // Files that are still uploading have progress < 100, so we skip creating the message.
+ // Once upload completes, for the local participant the file is broadcast with progress: 100 and the message
+ // is created. Remote participants receive the file metadata only once the file is successfully uploaded and
+ // the progress field will be undefined.
+ if (file.progress === 100 || !isLocalFile) {
+ store.dispatch(addMessage({
+ displayName: file.authorParticipantName,
+ fileMetadata: file,
+ hasRead: isLocalFile,
+ isReaction: false,
+ lobbyChat: false,
+ message: '', // Empty message as the file metadata contains all info
+ messageId: file.fileId,
+ messageType: isLocalFile ? MESSAGE_TYPE_LOCAL : MESSAGE_TYPE_REMOTE,
+ participantId: file.authorParticipantId,
+ privateMessage: false,
+ timestamp: file.timestamp
+ }));
+ }
+
+ return result;
+ }
+
case REMOVE_FILE: {
const state = store.getState();
const conference = getCurrentConference(state);
@@ -196,6 +243,27 @@ MiddlewareRegistry.register(store => next => action => {
return next(action);
}
+
+ case _FILE_REMOVED: {
+ const result = next(action);
+ const state = store.getState();
+ const { messages } = state['features/chat'];
+
+ // Find the message corresponding to this file and mark it as deleted.
+ const fileMessage = messages.find(msg => msg.messageId === action.fileId);
+
+ if (fileMessage?.fileMetadata) {
+ // Replace the file metadata with just the isDeleted flag to avoid keeping unnecessary data.
+ store.dispatch(editMessage({
+ ...fileMessage,
+ fileMetadata: {
+ isDeleted: true
+ } as any
+ }));
+ }
+
+ return result;
+ }
}
return next(action);
diff --git a/react/features/file-sharing/types.ts b/react/features/file-sharing/types.ts
index 1775f59e31..ef963f2574 100644
--- a/react/features/file-sharing/types.ts
+++ b/react/features/file-sharing/types.ts
@@ -7,6 +7,7 @@ export interface IFileMetadata {
fileName: string;
fileSize: number;
fileType: string;
+ isDeleted?: boolean;
progress?: number;
timestamp: number;
}