Don't use original filenames when saving multi-attachment messages

This commit is contained in:
Scott Nonnenberg 2022-08-08 12:04:47 -07:00 committed by GitHub
parent fde917c983
commit 46428b5af6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 3 deletions

View file

@ -62,7 +62,7 @@ describe('Attachment', () => {
});
});
context('for attachment with index', () => {
it('should use filename if provided', () => {
it('should use filename if it is provided', () => {
const attachment: Attachment.AttachmentType = fakeAttachment({
fileName: 'funny-cat.mov',
data: Bytes.fromString('foo'),
@ -74,12 +74,47 @@ describe('Attachment', () => {
const actual = Attachment.getSuggestedFilename({
attachment,
timestamp,
index: 3,
});
const expected = 'funny-cat.mov';
assert.strictEqual(actual, expected);
});
it('should use filename if it is provided and index is 1', () => {
const attachment: Attachment.AttachmentType = fakeAttachment({
fileName: 'funny-cat.mov',
data: Bytes.fromString('foo'),
contentType: MIME.VIDEO_QUICKTIME,
});
const timestamp = new Date(
DAY + new Date(DAY).getTimezoneOffset() * 60 * 1000
);
const actual = Attachment.getSuggestedFilename({
attachment,
timestamp,
index: 1,
});
const expected = 'funny-cat.mov';
assert.strictEqual(actual, expected);
});
it('should use filename if it is provided and index is >1', () => {
const attachment: Attachment.AttachmentType = fakeAttachment({
fileName: 'funny-cat.mov',
data: Bytes.fromString('foo'),
contentType: MIME.VIDEO_QUICKTIME,
});
const timestamp = new Date(
DAY + new Date(DAY).getTimezoneOffset() * 60 * 1000
);
const actual = Attachment.getSuggestedFilename({
attachment,
timestamp,
index: 2,
});
const expected = 'signal-1970-01-02-000000_002.mov';
assert.strictEqual(actual, expected);
});
it('should use provided index if > 1 and filename not provided', () => {
const attachment: Attachment.AttachmentType = fakeAttachment({
data: Bytes.fromString('foo'),

View file

@ -1001,7 +1001,7 @@ export const getSuggestedFilename = ({
index?: number;
}): string => {
const { fileName } = attachment;
if (fileName) {
if (fileName && (!isNumber(index) || index === 1)) {
return fileName;
}