do not overwrite attachment name on sending side

Relates #1593
This commit is contained in:
Audric Ackermann 2021-05-27 14:41:42 +10:00
parent b15eeb00cd
commit 81553aed57
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
2 changed files with 3 additions and 28 deletions

View file

@ -19,7 +19,6 @@ import {
import autoBind from 'auto-bind';
import { saveMessage } from '../../ts/data/data';
import { ConversationModel, ConversationTypeEnum } from './conversation';
import { getSuggestedFilenameSending } from '../types/Attachment';
import { actions as conversationActions } from '../state/ducks/conversations';
import { VisibleMessage } from '../session/messages/outgoing/visibleMessage/VisibleMessage';
import { buildSyncMessage } from '../session/utils/syncUtils';
@ -742,15 +741,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
(this.get('attachments') || []).map(window.Signal.Migrations.loadAttachmentData)
);
const body = this.get('body');
const finalAttachments = attachmentsWithData;
const filenameOverridenAttachments = finalAttachments.map((attachment: any) => ({
...attachment,
fileName: getSuggestedFilenameSending({
attachment,
timestamp: Date.now(),
}),
}));
const finalAttachments = attachmentsWithData as Array<any>;
const quoteWithData = await window.Signal.Migrations.loadQuoteData(this.get('quote'));
const previewWithData = await window.Signal.Migrations.loadPreviewData(this.get('preview'));
@ -765,7 +756,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
// we want to go for the v1, if this is an OpenGroupV1 or not an open group at all
if (conversation?.isOpenGroupV2()) {
const openGroupV2 = conversation.toOpenGroupV2();
attachmentPromise = uploadAttachmentsV2(filenameOverridenAttachments, openGroupV2);
attachmentPromise = uploadAttachmentsV2(finalAttachments, openGroupV2);
linkPreviewPromise = uploadLinkPreviewsV2(previewWithData, openGroupV2);
quotePromise = uploadQuoteThumbnailsV2(openGroupV2, quoteWithData);
} else {
@ -774,7 +765,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
const openGroupV1 = conversation?.isOpenGroupV1() ? conversation?.toOpenGroupV1() : undefined;
attachmentPromise = AttachmentFsV2Utils.uploadAttachmentsToFsV2(
filenameOverridenAttachments,
finalAttachments,
openGroupV1
);
linkPreviewPromise = AttachmentFsV2Utils.uploadLinkPreviewsToFsV2(

View file

@ -346,22 +346,6 @@ export const getSuggestedFilename = ({
return `${prefix}${suffix}${indexSuffix}${extension}`;
};
// Used for overriden the sent filename of an attachment, but keeping the file extension the same
export const getSuggestedFilenameSending = ({
attachment,
timestamp,
}: {
attachment: AttachmentType;
timestamp?: number | Date;
}): string => {
const prefix = 'session-attachment';
const suffix = timestamp ? moment(timestamp).format('-YYYY-MM-DD-HHmmss') : '';
const fileType = getFileExtension(attachment);
const extension = fileType ? `.${fileType}` : '';
return `${prefix}${suffix}${extension}`;
};
export const getFileExtension = (attachment: AttachmentType): string | undefined => {
// we override textplain to the extension of the file
// for contenttype starting with application, the mimetype is probably wrong so just use the extension of the file instead