Skip to content

Commit

Permalink
fix: canDisplayImage needs check to be done on the thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Mar 20, 2024
1 parent 629b58e commit 095a9d3
Show file tree
Hide file tree
Showing 15 changed files with 1,244 additions and 1,087 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import {
AttachmentType,
AttachmentTypeWithPath,
canDisplayImage,
canDisplayImagePreview,
getExtensionForDisplay,
hasImage,
hasVideoScreenshot,
Expand Down Expand Up @@ -131,7 +131,7 @@ export const MessageAttachment = (props: Props) => {
}

const firstAttachment = attachments[0];
const displayImage = canDisplayImage(attachments);
const displayImage = canDisplayImagePreview(attachments);

if (!isTrustedForAttachmentDownload) {
return <ClickToTrustSender messageId={messageId} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
getShouldHighlightMessage,
} from '../../../../state/selectors/conversations';
import { useSelectedIsPrivate } from '../../../../state/selectors/selectedConversation';
import { canDisplayImage } from '../../../../types/Attachment';
import { canDisplayImagePreview } from '../../../../types/Attachment';
import { ScrollToLoadedMessageContext } from '../../SessionMessagesListContainer';
import { MessageAttachment } from './MessageAttachment';
import { MessageAvatar } from './MessageAvatar';
Expand Down Expand Up @@ -154,7 +154,7 @@ export const MessageContent = (props: Props) => {
const toolTipTitle = moment(serverTimestamp || timestamp).format('llll');

const isDetailViewAndSupportsAttachmentCarousel =
props.isDetailView && canDisplayImage(attachments);
props.isDetailView && canDisplayImagePreview(attachments);

return (
<StyledMessageContent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement } from 'react';
import React from 'react';
import styled from 'styled-components';

import { isEmpty } from 'lodash';
Expand Down Expand Up @@ -160,7 +160,7 @@ const ExpiresInItem = ({ expirationTimestamp }: { expirationTimestamp?: number |
);
};

export const MessageReactBar = ({ action, additionalAction, messageId }: Props): ReactElement => {
export const MessageReactBar = ({ action, additionalAction, messageId }: Props) => {
const recentReactions = getRecentReactions();
const expirationTimestamp = useIsRenderedExpiresInItem(messageId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isEmpty, isEqual } from 'lodash';
import React, { ReactElement, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { useMessageReactsPropsById } from '../../../../hooks/useParamSelector';
import { MessageRenderingProps } from '../../../../models/messageType';
Expand Down Expand Up @@ -65,7 +65,7 @@ const StyledReadLess = styled.span`

type ReactionsProps = Omit<ReactionProps, 'emoji'>;

const Reactions = (props: ReactionsProps): ReactElement => {
const Reactions = (props: ReactionsProps) => {
const { messageId, reactions, inModal } = props;
return (
<StyledMessageReactions
Expand All @@ -85,7 +85,7 @@ interface ExpandReactionsProps extends ReactionsProps {
handleExpand: () => void;
}

const CompressedReactions = (props: ExpandReactionsProps): ReactElement => {
const CompressedReactions = (props: ExpandReactionsProps) => {
const { messageId, reactions, inModal, handleExpand } = props;
return (
<StyledMessageReactions
Expand Down Expand Up @@ -119,7 +119,7 @@ const CompressedReactions = (props: ExpandReactionsProps): ReactElement => {
);
};

const ExpandedReactions = (props: ExpandReactionsProps): ReactElement => {
const ExpandedReactions = (props: ExpandReactionsProps) => {
const { handleExpand } = props;
return (
<Flex container={true} flexDirection={'column'} alignItems={'center'} margin="4px 0 0">
Expand Down
4 changes: 2 additions & 2 deletions ts/components/conversation/message/reactions/Reaction.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement, useRef, useState } from 'react';
import React, { useRef, useState } from 'react';
import { useMouse } from 'react-use';
import styled from 'styled-components';
import { useRightOverlayMode } from '../../../../hooks/useUI';
Expand Down Expand Up @@ -62,7 +62,7 @@ export type ReactionProps = {
handlePopupClick?: () => void;
};

export const Reaction = (props: ReactionProps): ReactElement => {
export const Reaction = (props: ReactionProps) => {
const {
emoji,
messageId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { ReactElement, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components';
import { Data } from '../../../../data/data';
import { findAndFormatContact } from '../../../../models/message';
import { PubKey } from '../../../../session/types/PubKey';
import { isDarkTheme } from '../../../../state/selectors/theme';
import { nativeEmojiData } from '../../../../util/emoji';
import { findAndFormatContact } from '../../../../models/message';

export type TipPosition = 'center' | 'left' | 'right';

Expand Down Expand Up @@ -142,7 +142,7 @@ type Props = {
onClick: (...args: Array<any>) => void;
};

export const ReactionPopup = (props: Props): ReactElement => {
export const ReactionPopup = (props: Props) => {
const { messageId, emoji, count, senders, tooltipPosition = 'center', onClick } = props;

const [contacts, setContacts] = useState<Array<string>>([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
useMessageTimestamp,
} from '../../../../../state/selectors';
import { useSelectedConversationKey } from '../../../../../state/selectors/selectedConversation';
import { canDisplayImage } from '../../../../../types/Attachment';
import { canDisplayImagePreview } from '../../../../../types/Attachment';
import { isAudio } from '../../../../../types/MIME';
import {
getAudioDuration,
Expand Down Expand Up @@ -219,7 +219,7 @@ export const OverlayMessageInfo = () => {
const { errors, attachments } = messageInfo;

const hasAttachments = attachments && attachments.length > 0;
const supportsAttachmentCarousel = canDisplayImage(attachments);
const supportsAttachmentCarousel = canDisplayImagePreview(attachments);
const hasErrors = errors && errors.length > 0;

const handleChangeAttachment = (changeDirection: 1 | -1) => {
Expand Down
9 changes: 5 additions & 4 deletions ts/components/dialog/EditProfileDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useDispatch } from 'react-redux';
// eslint-disable-next-line import/no-named-default
import { ChangeEvent, MouseEvent, default as React, ReactElement, useState } from 'react';
import { ChangeEvent, MouseEvent, default as React, useState } from 'react';
import { QRCode } from 'react-qr-svg';
import styled from 'styled-components';
import { Avatar, AvatarSize } from '../avatar/Avatar';
Expand Down Expand Up @@ -69,7 +69,7 @@ type ProfileAvatarProps = {
ourId: string;
};

export const ProfileAvatar = (props: ProfileAvatarProps): ReactElement => {
export const ProfileAvatar = (props: ProfileAvatarProps) => {
const { newAvatarObjectUrl, avatarPath, profileName, ourId } = props;
return (
<Avatar
Expand All @@ -86,7 +86,7 @@ type ProfileHeaderProps = ProfileAvatarProps & {
setMode: (mode: ProfileDialogModes) => void;
};

const ProfileHeader = (props: ProfileHeaderProps): ReactElement => {
const ProfileHeader = (props: ProfileHeaderProps) => {
const { avatarPath, profileName, ourId, onClick, setMode } = props;

return (
Expand Down Expand Up @@ -114,7 +114,8 @@ const ProfileHeader = (props: ProfileHeaderProps): ReactElement => {
};

type ProfileDialogModes = 'default' | 'edit' | 'qr';
export const EditProfileDialog = (): ReactElement => {

export const EditProfileDialog = () => {
const dispatch = useDispatch();

const _profileName = useOurConversationUsername() || '';
Expand Down
6 changes: 3 additions & 3 deletions ts/components/dialog/ReactClearAllModal.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { ReactElement, useState } from 'react';
import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import styled from 'styled-components';
import { useMessageReactsPropsById } from '../../hooks/useParamSelector';
import { clearSogsReactionByServerId } from '../../session/apis/open_group_api/sogsv3/sogsV3ClearReaction';
import { getConversationController } from '../../session/conversations';
import { updateReactClearAllModal } from '../../state/ducks/modalDialog';
import { SessionWrapperModal } from '../SessionWrapperModal';
import { Flex } from '../basic/Flex';
import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton';
import { SessionSpinner } from '../basic/SessionSpinner';
import { SessionWrapperModal } from '../SessionWrapperModal';

type Props = {
reaction: string;
Expand Down Expand Up @@ -46,7 +46,7 @@ const StyledReactClearAllContainer = styled(Flex)`
}
`;

export const ReactClearAllModal = (props: Props): ReactElement => {
export const ReactClearAllModal = (props: Props) => {
const { reaction, messageId } = props;

const [clearingInProgress, setClearingInProgress] = useState(false);
Expand Down
8 changes: 4 additions & 4 deletions ts/components/dialog/ReactListModal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { isEmpty, isEqual } from 'lodash';
import React, { ReactElement, useEffect, useMemo, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';
import { useDispatch } from 'react-redux';
import styled from 'styled-components';
import { Data } from '../../data/data';
import { useMessageReactsPropsById } from '../../hooks/useParamSelector';
import { findAndFormatContact } from '../../models/message';
import { isUsAnySogsFromCache } from '../../session/apis/open_group_api/sogsv3/knownBlindedkeys';
import { UserUtils } from '../../session/utils';
import {
Expand All @@ -18,15 +19,14 @@ import {
import { SortedReactionList } from '../../types/Reaction';
import { nativeEmojiData } from '../../util/emoji';
import { Reactions } from '../../util/reactions';
import { SessionWrapperModal } from '../SessionWrapperModal';
import { Avatar, AvatarSize } from '../avatar/Avatar';
import { Flex } from '../basic/Flex';
import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton';
import { SessionHtmlRenderer } from '../basic/SessionHTMLRenderer';
import { ContactName } from '../conversation/ContactName';
import { MessageReactions } from '../conversation/message/message-content/MessageReactions';
import { SessionIconButton } from '../icon';
import { SessionWrapperModal } from '../SessionWrapperModal';
import { findAndFormatContact } from '../../models/message';

const StyledReactListContainer = styled(Flex)`
width: 376px;
Expand Down Expand Up @@ -218,7 +218,7 @@ const handleSenders = (senders: Array<string>, me: string) => {
return updatedSenders;
};

export const ReactListModal = (props: Props): ReactElement => {
export const ReactListModal = (props: Props) => {
const { reaction, messageId } = props;

const dispatch = useDispatch();
Expand Down
2 changes: 1 addition & 1 deletion ts/components/registration/AccentText.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

export const AccentText: React.FC = () => (
export const AccentText = () => (
<div className="session-content-accent-text">
<div className="session-content-accent-text title">{window.i18n('beginYourSession')}</div>
</div>
Expand Down
10 changes: 6 additions & 4 deletions ts/session/utils/Attachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import _ from 'lodash';

import { Attachment } from '../../types/Attachment';

import { encryptAttachment } from '../../util/crypto/attachmentsEncrypter';
import { uploadFileToFsWithOnionV4 } from '../apis/file_server_api/FileServerApi';
import { addAttachmentPadding } from '../crypto/BufferPadding';
import {
AttachmentPointer,
AttachmentPointerWithUrl,
PreviewWithAttachmentUrl,
Quote,
QuotedAttachmentWithUrl,
} from '../messages/outgoing/visibleMessage/VisibleMessage';
import { addAttachmentPadding } from '../crypto/BufferPadding';
import { encryptAttachment } from '../../util/crypto/attachmentsEncrypter';
import { uploadFileToFsWithOnionV4 } from '../apis/file_server_api/FileServerApi';

interface UploadParams {
attachment: Attachment;
Expand Down Expand Up @@ -107,7 +107,9 @@ export async function uploadLinkPreviewToFileServer(
): Promise<PreviewWithAttachmentUrl | undefined> {
// some links do not have an image associated, and it makes the whole message fail to send
if (!preview?.image) {
window.log.warn('tried to upload file to FileServer without image.. skipping');
if (!preview) {
window.log.warn('tried to upload file to FileServer without image.. skipping');
}
return preview as any;
}
const image = await uploadToFileServer({
Expand Down
6 changes: 4 additions & 2 deletions ts/types/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ export function isAudio(attachments?: Array<AttachmentType>) {
);
}

export function canDisplayImage(attachments?: Array<AttachmentType>) {
export function canDisplayImagePreview(attachments?: Array<AttachmentType>) {
// Note: when we display an image we usually display the preview.
// The preview is usually downscaled
const { height, width } =
attachments && attachments[0] ? attachments[0] : { height: 0, width: 0 };
attachments && attachments[0]?.thumbnail ? attachments[0].thumbnail : { height: 0, width: 0 };

return Boolean(
height &&
Expand Down
15 changes: 13 additions & 2 deletions ts/util/attachmentsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,24 @@ export async function autoScale<T extends { contentType: string; blob: Blob }>(
blob.size <= maxSize &&
!makeSquare
) {
if (DEBUG_ATTACHMENTS_SCALE) {
window.log.info('canvasScaled used right away as width, height and size are fine', {
canvasScaledWidth: canvasScaled.width,
canvasScaledHeight: canvasScaled.height,
maxWidth,
maxHeight,
blobsize: blob.size,
maxSize,
makeSquare,
});
}
// the canvas has a size of whatever was given by the caller of autoscale().
// so we have to return those measures as the loaded file has now those measures.
return {
...attachment,
blob,
contentType: attachment.contentType,
width: canvasScaled.width,
height: canvasScaled.height,
blob,
};
}
if (DEBUG_ATTACHMENTS_SCALE) {
Expand Down
Loading

0 comments on commit 095a9d3

Please sign in to comment.