From f704708524b9cd2e015b25882aa439d9e335d849 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 19 Mar 2021 15:16:43 +1100 Subject: [PATCH] fix bug with extension not being send if we don't have contenttype set --- AUDRICTOCLEAN.txt | 39 ------------------------- js/modules/types/attachment.js | 1 - ts/components/session/ActionsPanel.tsx | 5 +++- ts/models/message.ts | 3 +- ts/test/types/Attachment_test.ts | 40 ++++++++++++++++++++++++++ ts/types/Attachment.ts | 13 +++++++-- 6 files changed, 57 insertions(+), 44 deletions(-) delete mode 100644 AUDRICTOCLEAN.txt diff --git a/AUDRICTOCLEAN.txt b/AUDRICTOCLEAN.txt deleted file mode 100644 index 765fd7239..000000000 --- a/AUDRICTOCLEAN.txt +++ /dev/null @@ -1,39 +0,0 @@ -indexeddb - - -remove from db - * 'sentSessionsTimestamp' - * 'processedSessionsTimestamp' - * 'sessions' - * 'preKeys' - * 'signedPreKeys' - * senderkeys - -getContact() -remove what is is Storage / user.js -remove on the UI ts files the calls to conversationModel. everything should be on the props -conversationModel - .get() - -getOurNumber -primaryDevicePubKey -getRecipients() does not make asny sense right - -ReadSyncs -SyncMessage -sendSyncMessage needs to be rewritten -sendSyncMessageOnly to fix - - -indexedDB -initializeAttachmentMetadata=> -run_migration - - - -### Bug fixes on update of models -* quote of attachment does not share preview -* setting disappearing timer for isMe does not trigger the message -* expiration timer set from user1 second device is not synced to his other devices for a private chat -* add a way for users to know when the messageQueue is reconnected (loading bar or something) -* handled better reconnection \ No newline at end of file diff --git a/js/modules/types/attachment.js b/js/modules/types/attachment.js index e43412066..946514bb8 100644 --- a/js/modules/types/attachment.js +++ b/js/modules/types/attachment.js @@ -214,7 +214,6 @@ exports.deleteData = deleteOnDisk => { exports.isVoiceMessage = AttachmentTS.isVoiceMessage; exports.save = AttachmentTS.save; exports.getFileExtension = AttachmentTS.getFileExtension; -exports.getSuggestedFilenameSending = AttachmentTS.getSuggestedFilenameSending; exports.arrayBufferFromFile = AttachmentTS.arrayBufferFromFile; const THUMBNAIL_SIZE = 150; diff --git a/ts/components/session/ActionsPanel.tsx b/ts/components/session/ActionsPanel.tsx index 0ad7e0797..8780f2f24 100644 --- a/ts/components/session/ActionsPanel.tsx +++ b/ts/components/session/ActionsPanel.tsx @@ -102,11 +102,14 @@ const Section = (props: { type: SectionType; avatarPath?: string }) => { iconType = SessionIconType.Moon; } + const unreadToShow = + type === SectionType.Message ? unreadMessageCount : undefined; + return ( { public propsForTimerNotification: any; @@ -800,7 +801,7 @@ export class MessageModel extends Backbone.Model { const filenameOverridenAttachments = finalAttachments.map( (attachment: any) => ({ ...attachment, - fileName: window.Signal.Types.Attachment.getSuggestedFilenameSending({ + fileName: getSuggestedFilenameSending({ attachment, timestamp: Date.now(), }), diff --git a/ts/test/types/Attachment_test.ts b/ts/test/types/Attachment_test.ts index 3e3d188f0..f3a521c8d 100644 --- a/ts/test/types/Attachment_test.ts +++ b/ts/test/types/Attachment_test.ts @@ -54,6 +54,46 @@ describe('Attachment', () => { const expected = 'session-attachment_003.mov'; assert.strictEqual(actual, expected); }); + it('should generate a filename with an extension if contentType is not setup', () => { + const attachment: Attachment.AttachmentType = { + fileName: 'funny-cat.ini', + url: 'funny-cat.ini', + contentType: '', + }; + const actual = Attachment.getSuggestedFilename({ + attachment, + index: 3, + }); + const expected = 'session-attachment_003.ini'; + assert.strictEqual(actual, expected); + }); + + it('should generate a filename with an extension if contentType is text/plain', () => { + const attachment: Attachment.AttachmentType = { + fileName: 'funny-cat.txt', + url: 'funny-cat.txt', + contentType: 'text/plain', + }; + const actual = Attachment.getSuggestedFilename({ + attachment, + index: 3, + }); + const expected = 'session-attachment_003.txt'; + assert.strictEqual(actual, expected); + }); + it('should generate a filename with an extension if contentType is json', () => { + const attachment: Attachment.AttachmentType = { + fileName: 'funny-cat.json', + url: 'funny-cat.json', + contentType: '', + }; + const actual = Attachment.getSuggestedFilename({ + attachment, + index: 3, + }); + const expected = 'session-attachment_003.json'; + assert.strictEqual(actual, expected); + }); }); context('for attachment without filename', () => { it('should generate a filename based on timestamp', () => { diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index 76b99c5a2..9a2b1cd32 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -396,8 +396,17 @@ export const getSuggestedFilenameSending = ({ export const getFileExtension = ( attachment: AttachmentType ): string | undefined => { - if (!attachment.contentType) { - return; + // we override textplain to the extension of the file + if (!attachment.contentType || attachment.contentType === 'text/plain') { + if (attachment.fileName?.length) { + const dotLastIndex = attachment.fileName.lastIndexOf('.'); + if (dotLastIndex !== -1) { + return attachment.fileName.substring(dotLastIndex + 1); + } else { + return undefined; + } + } + return undefined; } switch (attachment.contentType) {