fix: load attachments in the messages list

pull/3170/head
yougotwill 9 months ago
parent b1616d4e13
commit 24b3feb39e

@ -62,25 +62,28 @@ export const Image = (props: Props) => {
width: _width, width: _width,
} = props; } = props;
const onErrorUrlFilterering = useCallback(() => {
if (url && onError) {
onError();
}
}, [url, onError]);
const disableDrag = useDisableDrag(); const disableDrag = useDisableDrag();
const { caption } = attachment || { caption: null }; const { caption } = attachment || { caption: null };
let { pending } = attachment || { pending: true }; let { pending } = attachment || { pending: true };
if (!url) { if (!url) {
// force pending to true if the url is undefined, so we show a loader while decrypting the attachemtn // force pending to true if the url is undefined, so we show a loader while decrypting the attachemtn
pending = true; pending = true;
} }
const canClick = onClick && !pending; const canClick = onClick && !pending;
const role = canClick ? 'button' : undefined; const role = canClick ? 'button' : undefined;
const { loading, urlToLoad } = useEncryptedFileFetch(url || '', attachment.contentType, false); const { loading, urlToLoad } = useEncryptedFileFetch(url || '', attachment.contentType, false);
// data will be url if loading is finished and '' if not // data will be url if loading is finished and '' if not
const srcData = !loading ? urlToLoad : ''; const srcData = !loading ? urlToLoad : '';
const onErrorUrlFilterering = useCallback(() => {
if (!loading && !pending && !url && onError) {
onError();
}
}, [loading, pending, url, onError]);
const width = isNumber(_width) ? `${_width}px` : _width; const width = isNumber(_width) ? `${_width}px` : _width;
const height = isNumber(_height) ? `${_height}px` : _height; const height = isNumber(_height) ? `${_height}px` : _height;

@ -31,6 +31,7 @@ import { AudioPlayerWithEncryptedFile } from '../../H5AudioPlayer';
import { ImageGrid } from '../../ImageGrid'; import { ImageGrid } from '../../ImageGrid';
import { ClickToTrustSender } from './ClickToTrustSender'; import { ClickToTrustSender } from './ClickToTrustSender';
import { MessageHighlighter } from './MessageHighlighter'; import { MessageHighlighter } from './MessageHighlighter';
import { useIsDetailMessageView } from '../../../../contexts/isDetailViewContext';
export type MessageAttachmentSelectorProps = Pick< export type MessageAttachmentSelectorProps = Pick<
MessageRenderingProps, MessageRenderingProps,
@ -67,6 +68,7 @@ const StyledGenericAttachmentContainer = styled(MessageHighlighter)<{ selected:
export const MessageAttachment = (props: Props) => { export const MessageAttachment = (props: Props) => {
const { messageId, imageBroken, handleImageError, highlight = false } = props; const { messageId, imageBroken, handleImageError, highlight = false } = props;
const isDetailView = useIsDetailMessageView();
const dispatch = useDispatch(); const dispatch = useDispatch();
const attachmentProps = useSelector((state: StateType) => const attachmentProps = useSelector((state: StateType) =>
@ -140,6 +142,10 @@ export const MessageAttachment = (props: Props) => {
((isImage(attachments) && hasImage(attachments)) || ((isImage(attachments) && hasImage(attachments)) ||
(isVideo(attachments) && hasVideoScreenshot(attachments))) (isVideo(attachments) && hasVideoScreenshot(attachments)))
) { ) {
// we use the carousel in the detail view
if (isDetailView) {
return null;
}
return ( return (
<MessageHighlighter highlight={highlight}> <MessageHighlighter highlight={highlight}>
<StyledImageGridContainer messageDirection={direction}> <StyledImageGridContainer messageDirection={direction}>

@ -154,8 +154,9 @@ export const MessageContent = (props: Props) => {
const toolTipTitle = moment(serverTimestamp || timestamp).format('llll'); const toolTipTitle = moment(serverTimestamp || timestamp).format('llll');
const isDetailViewAndSupportsAttachmentCarousel = window.log.debug(
isDetailView && canDisplayImagePreview(attachments); `WIP: [MessageAttachment] ${props.messageId} timestamp ${timestamp} imageBroken ${imageBroken} display ${canDisplayImagePreview(attachments)} attachments.contentType ${attachments?.[0].contentType || 'none'}`
);
return ( return (
<StyledMessageContent <StyledMessageContent
@ -204,14 +205,14 @@ export const MessageContent = (props: Props) => {
<MessageText messageId={props.messageId} /> <MessageText messageId={props.messageId} />
</StyledMessageOpaqueContent> </StyledMessageOpaqueContent>
)} )}
{!isDeleted && isDetailViewAndSupportsAttachmentCarousel && !imageBroken ? null : ( {!isDeleted ? (
<MessageAttachment <MessageAttachment
messageId={props.messageId} messageId={props.messageId}
imageBroken={imageBroken} imageBroken={imageBroken}
handleImageError={handleImageError} handleImageError={handleImageError}
highlight={highlight} highlight={highlight}
/> />
)} ) : null}
</IsMessageVisibleContext.Provider> </IsMessageVisibleContext.Provider>
</InView> </InView>
</StyledMessageContent> </StyledMessageContent>

Loading…
Cancel
Save