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: make sure we scale image before trying to compress it #2887

Merged
merged 7 commits into from
Mar 27, 2024
Merged
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
1 change: 0 additions & 1 deletion .yarnrc

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"auto-bind": "^4.0.0",
"backbone": "1.3.3",
"blob-util": "2.0.2",
"blueimp-load-image": "5.14.0",
"blueimp-load-image": "^5.16.0",
"buffer-crc32": "0.2.13",
"bunyan": "https://github.com/Bilb/node-bunyan",
"bytebuffer": "^5.0.1",
Expand Down Expand Up @@ -138,7 +138,7 @@
"@commitlint/types": "^17.4.4",
"@electron/notarize": "^2.1.0",
"@types/backbone": "1.4.2",
"@types/blueimp-load-image": "5.14.4",
"@types/blueimp-load-image": "^5.16.2",
"@types/buffer-crc32": "^0.2.0",
"@types/bunyan": "^1.8.8",
"@types/bytebuffer": "^5.0.41",
Expand All @@ -165,7 +165,7 @@
"@types/rimraf": "2.0.2",
"@types/semver": "5.5.0",
"@types/sinon": "9.0.4",
"@types/styled-components": "^5.1.4",
"@types/styled-components": "5.1.1",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "7.1.0",
"@typescript-eslint/parser": "7.1.0",
Expand Down
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 @@ -21,7 +21,7 @@ import {
getShouldHighlightMessage,
} from '../../../../state/selectors/conversations';
import { useSelectedIsPrivate } from '../../../../state/selectors/selectedConversation';
import { canDisplayImage } from '../../../../types/Attachment';
import { canDisplayImagePreview } from '../../../../types/Attachment';
import { MessageAttachment } from './MessageAttachment';
import { MessageAvatar } from './MessageAvatar';
import { MessageHighlighter } from './MessageHighlighter';
Expand Down Expand Up @@ -154,7 +154,8 @@ export const MessageContent = (props: Props) => {

const toolTipTitle = moment(serverTimestamp || timestamp).format('llll');

const isDetailViewAndSupportsAttachmentCarousel = isDetailView && canDisplayImage(attachments);
const isDetailViewAndSupportsAttachmentCarousel =
isDetailView && canDisplayImagePreview(attachments);
yougotwill marked this conversation as resolved.
Show resolved Hide resolved

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 { useIsDetailMessageView } from '../../../../contexts/isDetailViewContext';
import { useMessageReactsPropsById } from '../../../../hooks/useParamSelector';
Expand Down Expand Up @@ -66,7 +66,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 @@ -86,7 +86,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 @@ -120,7 +120,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 @@ -29,7 +29,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 @@ -222,7 +222,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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isString } from 'lodash';
import React from 'react';
import { useSelector } from 'react-redux';
import { AutoSizer, Index, List, ListRowProps } from 'react-virtualized';
import styled from 'styled-components';
import styled, { CSSProperties } from 'styled-components';
import {
DirectContactsByNameType,
getDirectContactsByName,
Expand Down Expand Up @@ -51,10 +51,10 @@ const renderRow = (props: ListRowProps) => {
}

if (isString(item)) {
return <ContactRowBreak style={style} key={key} char={item} />;
return <ContactRowBreak style={style as CSSProperties} key={key} char={item} />;
}

return <ContactRow style={style} key={key} {...item} />;
return <ContactRow style={style as CSSProperties} key={key} {...item} />;
};

const unknownSection = 'unknown';
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
8 changes: 4 additions & 4 deletions ts/components/search/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isString } from 'lodash';
import React from 'react';
import styled, { CSSProperties } from 'styled-components';
import { useSelector } from 'react-redux';
import { AutoSizer, List } from 'react-virtualized';
import { isString } from 'lodash';
import styled, { CSSProperties } from 'styled-components';

import { ConversationListItem } from '../leftpane/conversation-list-item/ConversationListItem';
import { MessageSearchResult } from './MessageSearchResults';
Expand Down Expand Up @@ -65,14 +65,14 @@ const VirtualizedList = () => {
return null;
}
if (isString(row)) {
return <SectionHeader title={row} style={style} key={key} />;
return <SectionHeader title={row} style={style as CSSProperties} key={key} />;
}
if (isContact(row)) {
return (
<ConversationListItem conversationId={row.contactConvoId} style={style} key={key} />
);
}
return <MessageSearchResult style={style} key={key} {...row} />;
return <MessageSearchResult style={style as CSSProperties} key={key} {...row} />;
}}
width={width}
autoHeight={false}
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
Loading
Loading