Fix video forwarding

This commit is contained in:
Josh Perez 2021-12-02 20:05:32 -05:00 committed by GitHub
parent 97d9069876
commit 13de35bea2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 44 deletions

View file

@ -8,7 +8,7 @@ import { action } from '@storybook/addon-actions';
import { text } from '@storybook/addon-knobs'; import { text } from '@storybook/addon-knobs';
import enMessages from '../../_locales/en/messages.json'; import enMessages from '../../_locales/en/messages.json';
import type { AttachmentDraftType } from '../types/Attachment'; import type { AttachmentType } from '../types/Attachment';
import type { PropsType } from './ForwardMessageModal'; import type { PropsType } from './ForwardMessageModal';
import { ForwardMessageModal } from './ForwardMessageModal'; import { ForwardMessageModal } from './ForwardMessageModal';
import { IMAGE_JPEG, VIDEO_MP4, stringToMIMEType } from '../types/MIME'; import { IMAGE_JPEG, VIDEO_MP4, stringToMIMEType } from '../types/MIME';
@ -16,9 +16,9 @@ import { getDefaultConversation } from '../test-both/helpers/getDefaultConversat
import { setupI18n } from '../util/setupI18n'; import { setupI18n } from '../util/setupI18n';
import { StorybookThemeContext } from '../../.storybook/StorybookThemeContext'; import { StorybookThemeContext } from '../../.storybook/StorybookThemeContext';
const createDraftAttachment = ( const createAttachment = (
props: Partial<AttachmentDraftType> = {} props: Partial<AttachmentType> = {}
): AttachmentDraftType => ({ ): AttachmentType => ({
pending: false, pending: false,
path: 'fileName.jpg', path: 'fileName.jpg',
contentType: stringToMIMEType( contentType: stringToMIMEType(
@ -83,7 +83,7 @@ story.add('link preview', () => {
date: Date.now(), date: Date.now(),
domain: 'https://www.signal.org', domain: 'https://www.signal.org',
url: 'signal.org', url: 'signal.org',
image: createDraftAttachment({ image: createAttachment({
url: '/fixtures/kitten-4-112-112.jpg', url: '/fixtures/kitten-4-112-112.jpg',
contentType: IMAGE_JPEG, contentType: IMAGE_JPEG,
}), }),
@ -101,15 +101,15 @@ story.add('media attachments', () => {
<ForwardMessageModal <ForwardMessageModal
{...useProps({ {...useProps({
attachments: [ attachments: [
createDraftAttachment({ createAttachment({
pending: true, pending: true,
}), }),
createDraftAttachment({ createAttachment({
contentType: IMAGE_JPEG, contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg', fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg', url: '/fixtures/tina-rolf-269345-unsplash.jpg',
}), }),
createDraftAttachment({ createAttachment({
contentType: VIDEO_MP4, contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4', fileName: 'pixabay-Soap-Bubble-7141.mp4',
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4', url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',

View file

@ -16,7 +16,7 @@ import { animated } from '@react-spring/web';
import classNames from 'classnames'; import classNames from 'classnames';
import { AttachmentList } from './conversation/AttachmentList'; import { AttachmentList } from './conversation/AttachmentList';
import type { AttachmentDraftType } from '../types/Attachment'; import type { AttachmentType } from '../types/Attachment';
import { Button } from './Button'; import { Button } from './Button';
import type { InputApi } from './CompositionInput'; import type { InputApi } from './CompositionInput';
import { CompositionInput } from './CompositionInput'; import { CompositionInput } from './CompositionInput';
@ -39,12 +39,12 @@ import { filterAndSortConversationsByRecent } from '../util/filterAndSortConvers
import { useAnimated } from '../hooks/useAnimated'; import { useAnimated } from '../hooks/useAnimated';
export type DataPropsType = { export type DataPropsType = {
attachments?: Array<AttachmentDraftType>; attachments?: Array<AttachmentType>;
candidateConversations: ReadonlyArray<ConversationType>; candidateConversations: ReadonlyArray<ConversationType>;
doForwardMessage: ( doForwardMessage: (
selectedContacts: Array<string>, selectedContacts: Array<string>,
messageBody?: string, messageBody?: string,
attachments?: Array<AttachmentDraftType>, attachments?: Array<AttachmentType>,
linkPreview?: LinkPreviewType linkPreview?: LinkPreviewType
) => void; ) => void;
getPreferredBadge: PreferredBadgeSelectorType; getPreferredBadge: PreferredBadgeSelectorType;
@ -102,7 +102,7 @@ export const ForwardMessageModal: FunctionComponent<PropsType> = ({
filterAndSortConversationsByRecent(candidateConversations, '') filterAndSortConversationsByRecent(candidateConversations, '')
); );
const [attachmentsToForward, setAttachmentsToForward] = useState< const [attachmentsToForward, setAttachmentsToForward] = useState<
Array<AttachmentDraftType> Array<AttachmentType>
>(attachments || []); >(attachments || []);
const [isEditingMessage, setIsEditingMessage] = useState(false); const [isEditingMessage, setIsEditingMessage] = useState(false);
const [messageBodyText, setMessageBodyText] = useState(messageBody || ''); const [messageBodyText, setMessageBodyText] = useState(messageBody || '');
@ -325,7 +325,7 @@ export const ForwardMessageModal: FunctionComponent<PropsType> = ({
<AttachmentList <AttachmentList
attachments={attachmentsToForward} attachments={attachmentsToForward}
i18n={i18n} i18n={i18n}
onCloseAttachment={(attachment: AttachmentDraftType) => { onCloseAttachment={(attachment: AttachmentType) => {
const newAttachments = attachmentsToForward.filter( const newAttachments = attachmentsToForward.filter(
currentAttachment => currentAttachment !== attachment currentAttachment => currentAttachment !== attachment
); );

View file

@ -6,6 +6,7 @@ import * as React from 'react';
import { action } from '@storybook/addon-actions'; import { action } from '@storybook/addon-actions';
import { storiesOf } from '@storybook/react'; import { storiesOf } from '@storybook/react';
import type { AttachmentDraftType } from '../../types/Attachment';
import type { Props } from './AttachmentList'; import type { Props } from './AttachmentList';
import { AttachmentList } from './AttachmentList'; import { AttachmentList } from './AttachmentList';
import { import {
@ -24,7 +25,9 @@ const i18n = setupI18n('en', enMessages);
const story = storiesOf('Components/Conversation/AttachmentList', module); const story = storiesOf('Components/Conversation/AttachmentList', module);
const createProps = (overrideProps: Partial<Props> = {}): Props => ({ const createProps = (
overrideProps: Partial<Props<AttachmentDraftType>> = {}
): Props<AttachmentDraftType> => ({
attachments: overrideProps.attachments || [], attachments: overrideProps.attachments || [],
i18n, i18n,
onAddAttachment: action('onAddAttachment'), onAddAttachment: action('onAddAttachment'),

View file

@ -7,7 +7,10 @@ import { Image } from './Image';
import { StagedGenericAttachment } from './StagedGenericAttachment'; import { StagedGenericAttachment } from './StagedGenericAttachment';
import { StagedPlaceholderAttachment } from './StagedPlaceholderAttachment'; import { StagedPlaceholderAttachment } from './StagedPlaceholderAttachment';
import type { LocalizerType } from '../../types/Util'; import type { LocalizerType } from '../../types/Util';
import type { AttachmentDraftType } from '../../types/Attachment'; import type {
AttachmentType,
AttachmentDraftType,
} from '../../types/Attachment';
import { import {
areAllAttachmentsVisual, areAllAttachmentsVisual,
canDisplayImage, canDisplayImage,
@ -15,14 +18,14 @@ import {
isVideoAttachment, isVideoAttachment,
} from '../../types/Attachment'; } from '../../types/Attachment';
export type Props = Readonly<{ export type Props<T extends AttachmentType | AttachmentDraftType> = Readonly<{
attachments: ReadonlyArray<AttachmentDraftType>; attachments: ReadonlyArray<T>;
canEditImages?: boolean; canEditImages?: boolean;
i18n: LocalizerType; i18n: LocalizerType;
onAddAttachment?: () => void; onAddAttachment?: () => void;
onClickAttachment?: (attachment: AttachmentDraftType) => void; onClickAttachment?: (attachment: T) => void;
onClose?: () => void; onClose?: () => void;
onCloseAttachment: (attachment: AttachmentDraftType) => void; onCloseAttachment: (attachment: T) => void;
}>; }>;
const IMAGE_WIDTH = 120; const IMAGE_WIDTH = 120;
@ -32,15 +35,21 @@ const IMAGE_HEIGHT = 120;
const BLANK_VIDEO_THUMBNAIL = const BLANK_VIDEO_THUMBNAIL =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR42mNiAAAABgADm78GJQAAAABJRU5ErkJggg=='; 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR42mNiAAAABgADm78GJQAAAABJRU5ErkJggg==';
function getUrl(attachment: AttachmentDraftType): string | undefined { function getUrl(
attachment: AttachmentType | AttachmentDraftType
): string | undefined {
if (attachment.pending) { if (attachment.pending) {
return undefined; return undefined;
} }
if ('screenshot' in attachment) {
return attachment.screenshot?.url || attachment.url;
}
return attachment.url; return attachment.url;
} }
export const AttachmentList = ({ export const AttachmentList = <T extends AttachmentType | AttachmentDraftType>({
attachments, attachments,
canEditImages, canEditImages,
i18n, i18n,
@ -48,7 +57,7 @@ export const AttachmentList = ({
onClickAttachment, onClickAttachment,
onCloseAttachment, onCloseAttachment,
onClose, onClose,
}: Props): JSX.Element | null => { }: Props<T>): JSX.Element | null => {
if (!attachments.length) { if (!attachments.length) {
return null; return null;
} }

View file

@ -14,14 +14,14 @@ import { getLinkPreview } from '../selectors/linkPreviews';
import { getIntl, getTheme } from '../selectors/user'; import { getIntl, getTheme } from '../selectors/user';
import { getEmojiSkinTone } from '../selectors/items'; import { getEmojiSkinTone } from '../selectors/items';
import { selectRecentEmojis } from '../selectors/emojis'; import { selectRecentEmojis } from '../selectors/emojis';
import type { AttachmentDraftType } from '../../types/Attachment'; import type { AttachmentType } from '../../types/Attachment';
export type SmartForwardMessageModalProps = { export type SmartForwardMessageModalProps = {
attachments?: Array<AttachmentDraftType>; attachments?: Array<AttachmentType>;
doForwardMessage: ( doForwardMessage: (
selectedContacts: Array<string>, selectedContacts: Array<string>,
messageBody?: string, messageBody?: string,
attachments?: Array<AttachmentDraftType>, attachments?: Array<AttachmentType>,
linkPreview?: LinkPreviewType linkPreview?: LinkPreviewType
) => void; ) => void;
isSticker: boolean; isSticker: boolean;

View file

@ -7,7 +7,7 @@ import { batch as batchDispatch } from 'react-redux';
import { debounce, flatten, omit, throttle } from 'lodash'; import { debounce, flatten, omit, throttle } from 'lodash';
import { render } from 'mustache'; import { render } from 'mustache';
import type { AttachmentDraftType, AttachmentType } from '../types/Attachment'; import type { AttachmentType } from '../types/Attachment';
import { isGIF } from '../types/Attachment'; import { isGIF } from '../types/Attachment';
import * as Attachment from '../types/Attachment'; import * as Attachment from '../types/Attachment';
import type { StickerPackType as StickerPackDBType } from '../sql/Interface'; import type { StickerPackType as StickerPackDBType } from '../sql/Interface';
@ -1265,31 +1265,16 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
} }
const attachments = getAttachmentsForMessage(message.attributes); const attachments = getAttachmentsForMessage(message.attributes);
const draftAttachments = attachments
.map((item: AttachmentType): AttachmentDraftType | null => {
const { path } = item;
if (!path) {
return null;
}
return {
...item,
path,
pending: false as const,
screenshotPath: item.screenshot?.path,
};
})
.filter(isNotNil);
this.forwardMessageModal = new Whisper.ReactWrapperView({ this.forwardMessageModal = new Whisper.ReactWrapperView({
JSX: window.Signal.State.Roots.createForwardMessageModal( JSX: window.Signal.State.Roots.createForwardMessageModal(
window.reduxStore, window.reduxStore,
{ {
attachments: draftAttachments, attachments,
doForwardMessage: async ( doForwardMessage: async (
conversationIds: Array<string>, conversationIds: Array<string>,
messageBody?: string, messageBody?: string,
includedAttachments?: Array<AttachmentDraftType>, includedAttachments?: Array<AttachmentType>,
linkPreview?: LinkPreviewType linkPreview?: LinkPreviewType
) => { ) => {
try { try {
@ -1338,7 +1323,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
message: MessageModel, message: MessageModel,
conversationIds: Array<string>, conversationIds: Array<string>,
messageBody?: string, messageBody?: string,
attachments?: Array<AttachmentDraftType>, attachments?: Array<AttachmentType>,
linkPreview?: LinkPreviewType linkPreview?: LinkPreviewType
): Promise<boolean> { ): Promise<boolean> {
log.info(`maybeForwardMessage/${message.idForLogging()}: Starting...`); log.info(`maybeForwardMessage/${message.idForLogging()}: Starting...`);