Skip to content

Commit

Permalink
Send related emoji along with Sticker, fix SendMessage types
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Oct 5, 2021
1 parent 3c91dce commit bd38008
Show file tree
Hide file tree
Showing 35 changed files with 522 additions and 376 deletions.
13 changes: 10 additions & 3 deletions app/attachments.ts
Expand Up @@ -168,14 +168,16 @@ export const createDoesExist = (

export const copyIntoAttachmentsDirectory = (
root: string
): ((sourcePath: string) => Promise<string>) => {
): ((sourcePath: string) => Promise<{ path: string; size: number }>) => {
if (!isString(root)) {
throw new TypeError("'root' must be a path");
}

const userDataPath = getApp().getPath('userData');

return async (sourcePath: string): Promise<string> => {
return async (
sourcePath: string
): Promise<{ path: string; size: number }> => {
if (!isString(sourcePath)) {
throw new TypeError('sourcePath must be a string');
}
Expand All @@ -196,7 +198,12 @@ export const copyIntoAttachmentsDirectory = (

await fse.ensureFile(normalized);
await fse.copy(sourcePath, normalized);
return relativePath;
const { size } = await fse.stat(normalized);

return {
path: relativePath,
size,
};
};
};

Expand Down
1 change: 1 addition & 0 deletions protos/SignalService.proto
Expand Up @@ -220,6 +220,7 @@ message DataMessage {
optional bytes packKey = 2;
optional uint32 stickerId = 3;
optional AttachmentPointer data = 4;
optional string emoji = 5;
}

message Reaction {
Expand Down
8 changes: 5 additions & 3 deletions test/app/attachments_test.js
@@ -1,4 +1,4 @@
// Copyright 2018-2020 Signal Messenger, LLC
// Copyright 2018-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

const fs = require('fs');
Expand Down Expand Up @@ -222,21 +222,23 @@ describe('Attachments', () => {
});
});

it('returns a function that copies the source path into the attachments directory', async function thisNeeded() {
it('returns a function that copies the source path into the attachments directory and returns its path and size', async function thisNeeded() {
const attachmentsPath = await this.getFakeAttachmentsDirectory();
const someOtherPath = path.join(app.getPath('userData'), 'somethingElse');
await fse.outputFile(someOtherPath, 'hello world');
this.filesToRemove.push(someOtherPath);

const copier = Attachments.copyIntoAttachmentsDirectory(attachmentsPath);
const relativePath = await copier(someOtherPath);
const { path: relativePath, size } = await copier(someOtherPath);

const absolutePath = path.join(attachmentsPath, relativePath);
assert.notEqual(someOtherPath, absolutePath);
assert.strictEqual(
await fs.promises.readFile(absolutePath, 'utf8'),
'hello world'
);

assert.strictEqual(size, 'hello world'.length);
});
});

Expand Down
18 changes: 10 additions & 8 deletions ts/components/CaptionEditor.stories.tsx
Expand Up @@ -12,17 +12,19 @@ import { AUDIO_MP3, IMAGE_JPEG, VIDEO_MP4 } from '../types/MIME';
import { setupI18n } from '../util/setupI18n';
import enMessages from '../../_locales/en/messages.json';

import { fakeAttachment } from '../test-both/helpers/fakeAttachment';

const i18n = setupI18n('en', enMessages);

const stories = storiesOf('Components/Caption Editor', module);

const createProps = (overrideProps: Partial<Props> = {}): Props => ({
attachment: {
attachment: fakeAttachment({
contentType: IMAGE_JPEG,
fileName: '',
url: '',
...overrideProps.attachment,
},
}),
caption: text('caption', overrideProps.caption || ''),
close: action('close'),
i18n,
Expand Down Expand Up @@ -50,11 +52,11 @@ stories.add('Image with Caption', () => {

stories.add('Video', () => {
const props = createProps({
attachment: {
attachment: fakeAttachment({
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
},
}),
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
});

Expand All @@ -63,11 +65,11 @@ stories.add('Video', () => {

stories.add('Video with Caption', () => {
const props = createProps({
attachment: {
attachment: fakeAttachment({
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
},
}),
caption:
'This is the user-provided caption. We show it overlaid on the image. If it is really long, then it wraps, but it does not get too close to the edges of the image.',
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
Expand All @@ -78,11 +80,11 @@ stories.add('Video with Caption', () => {

stories.add('Unsupported Attachment Type', () => {
const props = createProps({
attachment: {
attachment: fakeAttachment({
contentType: AUDIO_MP3,
fileName: 'incompetech-com-Agnus-Dei-X.mp3',
url: '/fixtures/incompetech-com-Agnus-Dei-X.mp3',
},
}),
url: '/fixtures/incompetech-com-Agnus-Dei-X.mp3',
});

Expand Down
8 changes: 6 additions & 2 deletions ts/components/CompositionArea.stories.tsx
Expand Up @@ -12,6 +12,9 @@ import { CompositionArea, Props } from './CompositionArea';
import { setupI18n } from '../util/setupI18n';
import enMessages from '../../_locales/en/messages.json';

import { fakeAttachment } from '../test-both/helpers/fakeAttachment';
import { landscapeGreenUrl } from '../storybook/Fixtures';

const i18n = setupI18n('en', enMessages);

const story = storiesOf('Components/CompositionArea', module);
Expand Down Expand Up @@ -154,9 +157,10 @@ story.add('SMS-only', () => {
story.add('Attachments', () => {
const props = createProps({
draftAttachments: [
{
fakeAttachment({
contentType: IMAGE_JPEG,
},
url: landscapeGreenUrl,
}),
],
});

Expand Down
1 change: 1 addition & 0 deletions ts/components/ForwardMessageModal.stories.tsx
Expand Up @@ -23,6 +23,7 @@ const createAttachment = (
fileName: text('attachment fileName', props.fileName || ''),
screenshot: props.screenshot,
url: text('attachment url', props.url || ''),
size: 3433,
});

const story = storiesOf('Components/ForwardMessageModal', module);
Expand Down
18 changes: 10 additions & 8 deletions ts/components/Lightbox.stories.tsx
Expand Up @@ -19,6 +19,8 @@ import {
stringToMIMEType,
} from '../types/MIME';

import { fakeAttachment } from '../test-both/helpers/fakeAttachment';

const i18n = setupI18n('en', enMessages);

const story = storiesOf('Components/Lightbox', module);
Expand All @@ -29,12 +31,12 @@ function createMediaItem(
overrideProps: OverridePropsMediaItemType
): MediaItemType {
return {
attachment: {
attachment: fakeAttachment({
caption: overrideProps.caption || '',
contentType: IMAGE_JPEG,
fileName: overrideProps.objectURL,
url: overrideProps.objectURL,
},
}),
contentType: IMAGE_JPEG,
index: 0,
message: {
Expand Down Expand Up @@ -63,13 +65,13 @@ story.add('Multimedia', () => {
const props = createProps({
media: [
{
attachment: {
attachment: fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
caption:
'Still from The Lighthouse, starring Robert Pattinson and Willem Defoe.',
},
}),
contentType: IMAGE_JPEG,
index: 0,
message: {
Expand All @@ -83,11 +85,11 @@ story.add('Multimedia', () => {
objectURL: '/fixtures/tina-rolf-269345-unsplash.jpg',
},
{
attachment: {
attachment: fakeAttachment({
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
},
}),
contentType: VIDEO_MP4,
index: 1,
message: {
Expand Down Expand Up @@ -122,11 +124,11 @@ story.add('Missing Media', () => {
const props = createProps({
media: [
{
attachment: {
attachment: fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
},
}),
contentType: IMAGE_JPEG,
index: 0,
message: {
Expand Down
38 changes: 20 additions & 18 deletions ts/components/conversation/AttachmentList.stories.tsx
Expand Up @@ -17,6 +17,8 @@ import {
import { setupI18n } from '../../util/setupI18n';
import enMessages from '../../../_locales/en/messages.json';

import { fakeAttachment } from '../../test-both/helpers/fakeAttachment';

const i18n = setupI18n('en', enMessages);

const story = storiesOf('Components/Conversation/AttachmentList', module);
Expand All @@ -33,11 +35,11 @@ const createProps = (overrideProps: Partial<Props> = {}): Props => ({
story.add('One File', () => {
const props = createProps({
attachments: [
{
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
},
}),
],
});
return <AttachmentList {...props} />;
Expand All @@ -46,12 +48,12 @@ story.add('One File', () => {
story.add('Multiple Visual Attachments', () => {
const props = createProps({
attachments: [
{
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
},
{
}),
fakeAttachment({
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
Expand All @@ -62,12 +64,12 @@ story.add('Multiple Visual Attachments', () => {
contentType: IMAGE_JPEG,
path: 'originalpath',
},
},
{
}),
fakeAttachment({
contentType: IMAGE_GIF,
fileName: 'giphy-GVNv0UpeYm17e',
url: '/fixtures/giphy-GVNvOUpeYmI7e.gif',
},
}),
],
});

Expand All @@ -77,22 +79,22 @@ story.add('Multiple Visual Attachments', () => {
story.add('Multiple with Non-Visual Types', () => {
const props = createProps({
attachments: [
{
fakeAttachment({
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
},
{
}),
fakeAttachment({
contentType: stringToMIMEType('text/plain'),
fileName: 'lorem-ipsum.txt',
url: '/fixtures/lorem-ipsum.txt',
},
{
}),
fakeAttachment({
contentType: AUDIO_MP3,
fileName: 'incompetech-com-Agnus-Dei-X.mp3',
url: '/fixtures/incompetech-com-Agnus-Dei-X.mp3',
},
{
}),
fakeAttachment({
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
Expand All @@ -103,12 +105,12 @@ story.add('Multiple with Non-Visual Types', () => {
contentType: IMAGE_JPEG,
path: 'originalpath',
},
},
{
}),
fakeAttachment({
contentType: IMAGE_GIF,
fileName: 'giphy-GVNv0UpeYm17e',
url: '/fixtures/giphy-GVNvOUpeYmI7e.gif',
},
}),
],
});

Expand Down
10 changes: 6 additions & 4 deletions ts/components/conversation/ContactDetail.stories.tsx
Expand Up @@ -13,6 +13,8 @@ import { setupI18n } from '../../util/setupI18n';
import enMessages from '../../../_locales/en/messages.json';
import { IMAGE_GIF } from '../../types/MIME';

import { fakeAttachment } from '../../test-both/helpers/fakeAttachment';

const i18n = setupI18n('en', enMessages);

const story = storiesOf('Components/Conversation/ContactDetail', module);
Expand Down Expand Up @@ -72,10 +74,10 @@ const fullContact = {
},
],
avatar: {
avatar: {
avatar: fakeAttachment({
path: '/fixtures/giphy-GVNvOUpeYmI7e.gif',
contentType: IMAGE_GIF,
},
}),
isProfile: true,
},
email: [
Expand Down Expand Up @@ -209,10 +211,10 @@ story.add('Loading Avatar', () => {
const props = createProps({
contact: {
avatar: {
avatar: {
avatar: fakeAttachment({
contentType: IMAGE_GIF,
pending: true,
},
}),
isProfile: true,
},
},
Expand Down

0 comments on commit bd38008

Please sign in to comment.