feat(app): delete attachments from the media viewer (#2039)

This commit is contained in:
Hampus authored and GitHub committed 2026-08-27 13:26:18 +02:00
1 parent 88d85919f1
commit 509562e6da
11 files changed
+92 -11

No files matched your search

@@ -208,9 +208,10 @@ export const AttachmentGridItem: FC<AttachmentGridItemProps> = observer(
messageId: message?.id,
message,
sourceChannel: messageViewContext?.channel,
allowAttachmentDelete: !isPreview && snapshotIndex === undefined,
});
},
[attachment, message, messageViewContext?.channel, mediaAttachments, shouldBlur],
[attachment, message, messageViewContext?.channel, mediaAttachments, shouldBlur, isPreview, snapshotIndex],
);
const openInBrowser = useOpenInBrowserOnMiddleClick(attachment.url ?? attachment.proxy_url ?? '', !shouldBlur);
const handleFavoriteClick = useCallback(
@@ -181,6 +181,7 @@ const useImagePreview = ({
message,
sourceChannel,
providerName,
allowAttachmentDelete = false,
}: {
proxyUrl: string;
embedUrl: string;
@@ -195,6 +196,7 @@ const useImagePreview = ({
message?: Message;
sourceChannel?: Channel | null;
providerName?: string;
allowAttachmentDelete?: boolean;
}): {viewerItem: MediaViewerItem; openPreview: (event: React.MouseEvent | React.KeyboardEvent) => void} => {
const viewerItem = useMemo<MediaViewerItem>(
() => ({
@@ -223,9 +225,10 @@ const useImagePreview = ({
messageId,
message,
sourceChannel,
allowAttachmentDelete,
});
},
[viewerItem, channelId, messageId, message, sourceChannel],
[viewerItem, channelId, messageId, message, sourceChannel, allowAttachmentDelete],
);
return {viewerItem, openPreview};
};
@@ -461,6 +464,7 @@ export const EmbedGifv: FC<
message,
sourceChannel: messageViewContext?.channel,
providerName,
allowAttachmentDelete: !isPreview && snapshotIndex === undefined,
});
const handleDeleteClick = useDeleteAttachment(message, attachmentId);
const handleDownloadClick = useCallback(
@@ -795,6 +799,7 @@ export const EmbedGif: FC<
contentHash,
message,
sourceChannel: messageViewContext?.channel,
allowAttachmentDelete: !isPreview && snapshotIndex === undefined,
});
const {scheduleViewerWarm, cancelViewerWarm} = useMediaViewerHoverWarm(viewerItem, {
allowAnimated: gifAutoPlay,
@@ -104,6 +104,7 @@ interface ImagePreviewHandlerProps {
message?: Message;
animated?: boolean;
mediaAttachments?: ReadonlyArray<MessageAttachment>;
allowAttachmentDelete?: boolean;
onViewerWarmEnter?: () => void;
onViewerWarmLeave?: () => void;
children: React.ReactNode;
@@ -143,6 +144,7 @@ const ImagePreviewHandler: FC<ImagePreviewHandlerProps> = observer(
message,
animated,
mediaAttachments = NO_MEDIA_ATTACHMENTS,
allowAttachmentDelete = false,
onViewerWarmEnter,
onViewerWarmLeave,
children,
@@ -176,6 +178,7 @@ const ImagePreviewHandler: FC<ImagePreviewHandlerProps> = observer(
messageId,
message,
sourceChannel: messageViewContext?.channel,
allowAttachmentDelete,
});
} else {
MediaViewerCommands.openMediaViewer(
@@ -187,6 +190,7 @@ const ImagePreviewHandler: FC<ImagePreviewHandlerProps> = observer(
naturalHeight,
type: 'image' as const,
contentHash,
attachmentId,
embedIndex,
expiresAt: undefined,
expired: undefined,
@@ -199,6 +203,7 @@ const ImagePreviewHandler: FC<ImagePreviewHandlerProps> = observer(
messageId,
message,
sourceChannel: messageViewContext?.channel,
allowAttachmentDelete,
},
);
}
@@ -217,6 +222,7 @@ const ImagePreviewHandler: FC<ImagePreviewHandlerProps> = observer(
message,
messageViewContext?.channel,
mediaAttachments,
allowAttachmentDelete,
],
);
const openInBrowser = useOpenInBrowserOnMiddleClick(originalSrc || src);
@@ -381,6 +387,7 @@ export const EmbedImage: FC<EmbedImageProps> = observer(
[originalSrc, src],
);
const handleDeleteClick = useDeleteAttachment(message, attachmentId);
const allowAttachmentDelete = !isPreview && snapshotIndex === undefined;
const [mediaSheetOpen, setMediaSheetOpen] = useState(false);
const handleContextMenu = useCallback(
(e: React.MouseEvent) => {
@@ -524,6 +531,7 @@ export const EmbedImage: FC<EmbedImageProps> = observer(
attachmentId={attachmentId}
message={message}
mediaAttachments={mediaAttachments}
allowAttachmentDelete={allowAttachmentDelete}
animated={animated}
onViewerWarmEnter={scheduleViewerWarm}
onViewerWarmLeave={cancelViewerWarm}
@@ -272,6 +272,7 @@ const EmbedVideo: FC<EmbedVideoProps> = observer(
[src],
);
const handleDeleteClick = useDeleteAttachment(message, attachmentId);
const allowAttachmentDelete = !isPreview && snapshotIndex === undefined;
const handleContextMenu = useCallback(
(e: React.MouseEvent) => {
if (!message) return;
@@ -396,6 +397,7 @@ const EmbedVideo: FC<EmbedVideoProps> = observer(
messageId,
message,
sourceChannel: messageViewContext?.channel,
allowAttachmentDelete,
});
} else {
MediaViewerCommands.openMediaViewer(
@@ -407,12 +409,13 @@ const EmbedVideo: FC<EmbedVideoProps> = observer(
naturalHeight: viewerVideoDimensions.height,
type: 'video' as const,
contentHash,
attachmentId,
embedIndex,
duration,
},
],
0,
{channelId, messageId, message, sourceChannel: messageViewContext?.channel},
{channelId, messageId, message, sourceChannel: messageViewContext?.channel, allowAttachmentDelete},
);
}
}, [
@@ -420,6 +423,7 @@ const EmbedVideo: FC<EmbedVideoProps> = observer(
messageId,
message,
messageViewContext?.channel,
allowAttachmentDelete,
mediaAttachments,
attachmentId,
effectiveSrc,
@@ -451,6 +455,7 @@ const EmbedVideo: FC<EmbedVideoProps> = observer(
messageId,
message,
sourceChannel: messageViewContext?.channel,
allowAttachmentDelete,
});
} else {
MediaViewerCommands.openMediaViewer(
@@ -462,13 +467,14 @@ const EmbedVideo: FC<EmbedVideoProps> = observer(
naturalHeight: viewerVideoDimensions.height,
type: 'video' as const,
contentHash,
attachmentId,
embedIndex,
duration,
initialTime: currentTime,
},
],
0,
{channelId, messageId, message, sourceChannel: messageViewContext?.channel},
{channelId, messageId, message, sourceChannel: messageViewContext?.channel, allowAttachmentDelete},
);
}
setIsPlayingInline(false);
@@ -477,6 +483,7 @@ const EmbedVideo: FC<EmbedVideoProps> = observer(
messageId,
message,
messageViewContext?.channel,
allowAttachmentDelete,
mediaAttachments,
attachmentId,
effectiveSrc,