Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion app/containers/message/Components/Attachments/Quote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getMessageFromAttachment } from '../../utils';
const isQuoteAttachment = (file?: IAttachment): boolean => {
if (!file) return false;

if (file.image_url || file.audio_url || file.video_url || file.collapsed) {
if (!file.color && !file.text && (file.image_url || file.audio_url || file.video_url || file.collapsed)) {
return false;
}

Expand Down
22 changes: 21 additions & 1 deletion app/containers/message/hooks/useMediaAutoDownload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ const getFileProperty = (file: IAttachment, fileType: MediaTypes, property: 'url
}
};

const getOriginalURL = (file: IAttachment): string | null => {
if (file.image_url) {
return file.image_url;
}
if (file.video_url) {
return file.video_url;
}
if (file.audio_url) {
return file.audio_url;
}
return null;
};

export const useMediaAutoDownload = ({
file,
author,
Expand All @@ -48,7 +61,14 @@ export const useMediaAutoDownload = ({
const { id, baseUrl, user } = useContext(MessageContext);
const [status, setStatus] = useState<TDownloadState>('to-download');
const [currentFile, setCurrentFile] = useFile(file, id);
const url = formatAttachmentUrl(file.title_link || getFileProperty(currentFile, fileType, 'url'), user.id, user.token, baseUrl);
const originalUrl = getOriginalURL(file);
const url = formatAttachmentUrl(
file.title_link || getFileProperty(currentFile, fileType, 'url'),
user.id,
user.token,
baseUrl,
originalUrl
);
const isEncrypted = currentFile.e2e === 'pending';

useEffect(() => {
Expand Down
12 changes: 11 additions & 1 deletion app/lib/methods/helpers/formatAttachmentUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ function setParamInUrl({ url, token, userId }: { url: string; token: string; use
return urlObj.toString();
}

export const formatAttachmentUrl = (attachmentUrl: string | undefined, userId: string, token: string, server: string): string => {
export const formatAttachmentUrl = (
attachmentUrl: string | undefined,
userId: string,
token: string,
server: string,
_originalUrl?: string | null
): string => {
const protectFiles = store.getState().settings.FileUpload_ProtectFiles;

if ((attachmentUrl && isImageBase64(attachmentUrl)) || attachmentUrl?.startsWith('file://')) {
return attachmentUrl;
}
if (attachmentUrl && attachmentUrl.startsWith('http')) {
if (_originalUrl && !_originalUrl.startsWith(server)) {
return _originalUrl;
}
Comment thread
OtavioStasiak marked this conversation as resolved.
Resolved

if (attachmentUrl.includes('rc_token')) {
return encodeURI(attachmentUrl);
}
Expand Down
Loading