import React from 'react'; import { Icon, Icons, config, toRem } from 'folds'; import { MatrixEvent, MsgType } from 'matrix-js-sdk'; import { useMatrixClient } from '../../hooks/useMatrixClient'; import { useMediaAuthentication } from '../../hooks/useMediaAuthentication'; import { useDecryptedMediaUrl } from '../../hooks/useDecryptedMediaUrl'; import { getThumbMxc } from '../../utils/mediaThumb'; import { MessageEvent } from '../../../types/matrix/room'; const SIZE = 36; /** Whether a reply quote for this event should carry a thumbnail. */ export const hasReplyMedia = (mEvent: MatrixEvent | null | undefined): boolean => { if (!mEvent || mEvent.isRedacted()) return false; if (mEvent.getType() === MessageEvent.Sticker) return true; const msgtype = mEvent.getContent().msgtype; return msgtype === MsgType.Image || msgtype === MsgType.Video; }; /** * [Gitea #151] 36 px thumbnail in a reply quote for an image/video/sticker. * Uses the event's own thumbnail (decrypting it for E2EE media), never the * full-size file. */ export function ReplyMediaThumb({ mEvent }: { mEvent: MatrixEvent }) { const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); const content = mEvent.getContent(); const isVideo = content.msgtype === MsgType.Video; const thumbMxc = getThumbMxc(mEvent); const info = content.info as Record | undefined; const encInfo = content.file ? ((info?.thumbnail_file as typeof content.file | undefined) ?? content.file) : undefined; const mimeType = (info?.thumbnail_info as { mimetype?: string } | undefined)?.mimetype ?? (info?.mimetype as string | undefined); const media = useDecryptedMediaUrl(mx, thumbMxc, encInfo, useAuthentication, mimeType); return ( {media.status === 'ok' ? ( ) : ( )} {isVideo && media.status === 'ok' && ( )} ); }