Update types: attachments may not have url
property
This commit is contained in:
parent
aeab3f8d16
commit
f41ffda3e0
5 changed files with 19 additions and 16 deletions
|
@ -186,8 +186,6 @@ story.add('Blurhash', () => {
|
||||||
const props = {
|
const props = {
|
||||||
...defaultProps,
|
...defaultProps,
|
||||||
blurHash: 'thisisafakeblurhashthatwasmadeup',
|
blurHash: 'thisisafakeblurhashthatwasmadeup',
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
url: undefined as any,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return <Image {...props} />;
|
return <Image {...props} />;
|
||||||
|
@ -198,8 +196,6 @@ story.add('undefined blurHash (light)', () => {
|
||||||
const props = {
|
const props = {
|
||||||
...defaultProps,
|
...defaultProps,
|
||||||
blurHash: undefined,
|
blurHash: undefined,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
url: undefined as any,
|
|
||||||
theme: ThemeType.light,
|
theme: ThemeType.light,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -211,8 +207,6 @@ story.add('undefined blurHash (dark)', () => {
|
||||||
const props = {
|
const props = {
|
||||||
...defaultProps,
|
...defaultProps,
|
||||||
blurHash: undefined,
|
blurHash: undefined,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
url: undefined as any,
|
|
||||||
theme: ThemeType.dark,
|
theme: ThemeType.dark,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -225,8 +219,6 @@ story.add('Missing Image', () => {
|
||||||
...defaultProps,
|
...defaultProps,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
attachment: undefined as any,
|
attachment: undefined as any,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
url: undefined as any,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return <Image {...props} />;
|
return <Image {...props} />;
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { AttachmentType, hasNotDownloaded } from '../../types/Attachment';
|
||||||
export type Props = {
|
export type Props = {
|
||||||
alt: string;
|
alt: string;
|
||||||
attachment: AttachmentType;
|
attachment: AttachmentType;
|
||||||
url: string;
|
url?: string;
|
||||||
|
|
||||||
height?: number;
|
height?: number;
|
||||||
width?: number;
|
width?: number;
|
||||||
|
|
|
@ -759,8 +759,6 @@ story.add('Audio with Not Downloaded Attachment', () => {
|
||||||
{
|
{
|
||||||
contentType: AUDIO_MP3,
|
contentType: AUDIO_MP3,
|
||||||
fileName: 'incompetech-com-Agnus-Dei-X.mp3',
|
fileName: 'incompetech-com-Agnus-Dei-X.mp3',
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
url: undefined as any,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
status: 'sent',
|
status: 'sent',
|
||||||
|
@ -775,8 +773,6 @@ story.add('Audio with Pending Attachment', () => {
|
||||||
{
|
{
|
||||||
contentType: AUDIO_MP3,
|
contentType: AUDIO_MP3,
|
||||||
fileName: 'incompetech-com-Agnus-Dei-X.mp3',
|
fileName: 'incompetech-com-Agnus-Dei-X.mp3',
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
url: undefined as any,
|
|
||||||
pending: true,
|
pending: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -256,6 +256,13 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
|
if (!attachment.url) {
|
||||||
|
throw new Error(
|
||||||
|
'Expected attachment url in the MessageAudio with ' +
|
||||||
|
`state: ${state}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const { peaks: newPeaks, duration: newDuration } = await loadAudio({
|
const { peaks: newPeaks, duration: newDuration } = await loadAudio({
|
||||||
audioContext,
|
audioContext,
|
||||||
waveformCache,
|
waveformCache,
|
||||||
|
@ -374,6 +381,12 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
|
||||||
audio.pause();
|
audio.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!attachment.url) {
|
||||||
|
throw new Error(
|
||||||
|
'Expected attachment url in the MessageAudio with ' +
|
||||||
|
`state: ${state}`
|
||||||
|
);
|
||||||
|
}
|
||||||
audio.src = attachment.url;
|
audio.src = attachment.url;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,7 +28,7 @@ export type AttachmentType = {
|
||||||
/** Not included in protobuf, needs to be pulled from flags */
|
/** Not included in protobuf, needs to be pulled from flags */
|
||||||
isVoiceMessage?: boolean;
|
isVoiceMessage?: boolean;
|
||||||
/** For messages not already on disk, this will be a data url */
|
/** For messages not already on disk, this will be a data url */
|
||||||
url: string;
|
url?: string;
|
||||||
size?: number;
|
size?: number;
|
||||||
fileSize?: string;
|
fileSize?: string;
|
||||||
pending?: boolean;
|
pending?: boolean;
|
||||||
|
@ -107,7 +107,9 @@ export function canDisplayImage(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getThumbnailUrl(attachment: AttachmentType): string {
|
export function getThumbnailUrl(
|
||||||
|
attachment: AttachmentType
|
||||||
|
): string | undefined {
|
||||||
if (attachment.thumbnail) {
|
if (attachment.thumbnail) {
|
||||||
return attachment.thumbnail.url;
|
return attachment.thumbnail.url;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +117,7 @@ export function getThumbnailUrl(attachment: AttachmentType): string {
|
||||||
return getUrl(attachment);
|
return getUrl(attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUrl(attachment: AttachmentType): string {
|
export function getUrl(attachment: AttachmentType): string | undefined {
|
||||||
if (attachment.screenshot) {
|
if (attachment.screenshot) {
|
||||||
return attachment.screenshot.url;
|
return attachment.screenshot.url;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue