2021-03-24 22:06:12 +00:00
|
|
|
// Copyright 2020-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-08-27 18:10:35 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
import { number } from '@storybook/addon-knobs';
|
|
|
|
import { storiesOf } from '@storybook/react';
|
|
|
|
|
2021-03-24 22:06:12 +00:00
|
|
|
import { PropsData as MessageDataPropsType } from './Message';
|
2020-08-27 18:10:35 +00:00
|
|
|
import { MessageDetail, Props } from './MessageDetail';
|
2021-05-07 22:21:10 +00:00
|
|
|
import { getDefaultConversation } from '../../test-both/helpers/getDefaultConversation';
|
2020-08-27 18:10:35 +00:00
|
|
|
import { setup as setupI18n } from '../../../js/modules/i18n';
|
|
|
|
import enMessages from '../../../_locales/en/messages.json';
|
2020-09-14 19:51:27 +00:00
|
|
|
|
2020-08-27 18:10:35 +00:00
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
const story = storiesOf('Components/Conversation/MessageDetail', module);
|
|
|
|
|
2021-03-24 22:06:12 +00:00
|
|
|
const defaultMessage: MessageDataPropsType = {
|
2021-05-07 22:21:10 +00:00
|
|
|
author: getDefaultConversation({
|
2021-04-27 19:55:21 +00:00
|
|
|
id: 'some-id',
|
|
|
|
title: 'Max',
|
2021-05-07 22:21:10 +00:00
|
|
|
}),
|
2020-08-27 18:10:35 +00:00
|
|
|
canReply: true,
|
2020-09-29 22:55:56 +00:00
|
|
|
canDeleteForEveryone: true,
|
2020-10-16 18:31:57 +00:00
|
|
|
canDownload: true,
|
2021-05-28 16:15:17 +00:00
|
|
|
conversationColor: 'crimson',
|
2020-08-27 18:10:35 +00:00
|
|
|
conversationId: 'my-convo',
|
|
|
|
conversationType: 'direct',
|
|
|
|
direction: 'incoming',
|
|
|
|
id: 'my-message',
|
2021-06-29 19:58:29 +00:00
|
|
|
renderingContext: 'storybook',
|
2021-02-02 17:09:53 +00:00
|
|
|
isBlocked: false,
|
|
|
|
isMessageRequestAccepted: true,
|
2020-08-27 18:10:35 +00:00
|
|
|
previews: [],
|
|
|
|
status: 'sent',
|
|
|
|
text: 'A message from Max',
|
|
|
|
timestamp: Date.now(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
|
|
|
|
contacts: overrideProps.contacts || [
|
|
|
|
{
|
2021-05-07 22:21:10 +00:00
|
|
|
...getDefaultConversation({
|
2021-05-28 16:15:17 +00:00
|
|
|
color: 'indigo',
|
2021-05-07 22:21:10 +00:00
|
|
|
title: 'Just Max',
|
|
|
|
}),
|
2020-08-27 18:10:35 +00:00
|
|
|
isOutgoingKeyError: false,
|
|
|
|
isUnidentifiedDelivery: false,
|
2021-07-12 23:51:45 +00:00
|
|
|
status: 'delivered',
|
2020-08-27 18:10:35 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
errors: overrideProps.errors || [],
|
|
|
|
message: overrideProps.message || defaultMessage,
|
|
|
|
receivedAt: number('receivedAt', overrideProps.receivedAt || Date.now()),
|
|
|
|
sentAt: number('sentAt', overrideProps.sentAt || Date.now()),
|
2021-03-24 22:06:12 +00:00
|
|
|
|
|
|
|
i18n,
|
|
|
|
interactionMode: 'keyboard',
|
|
|
|
|
2021-06-16 00:44:14 +00:00
|
|
|
sendAnyway: action('onSendAnyway'),
|
|
|
|
showSafetyNumber: action('onShowSafetyNumber'),
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
checkForAccount: action('checkForAccount'),
|
|
|
|
clearSelectedMessage: action('clearSelectedMessage'),
|
2021-03-24 22:06:12 +00:00
|
|
|
deleteMessage: action('deleteMessage'),
|
|
|
|
deleteMessageForEveryone: action('deleteMessageForEveryone'),
|
2021-06-17 17:15:10 +00:00
|
|
|
displayTapToViewMessage: action('displayTapToViewMessage'),
|
|
|
|
downloadAttachment: action('downloadAttachment'),
|
|
|
|
doubleCheckMissingQuoteReference: action('doubleCheckMissingQuoteReference'),
|
2021-03-24 22:06:12 +00:00
|
|
|
kickOffAttachmentDownload: action('kickOffAttachmentDownload'),
|
|
|
|
markAttachmentAsCorrupted: action('markAttachmentAsCorrupted'),
|
2021-06-17 17:15:10 +00:00
|
|
|
openConversation: action('openConversation'),
|
|
|
|
openLink: action('openLink'),
|
|
|
|
reactToMessage: action('reactToMessage'),
|
2021-03-24 22:06:12 +00:00
|
|
|
renderAudioAttachment: () => <div>*AudioAttachment*</div>,
|
|
|
|
renderEmojiPicker: () => <div />,
|
2021-06-17 17:15:10 +00:00
|
|
|
replyToMessage: action('replyToMessage'),
|
|
|
|
retrySend: action('retrySend'),
|
|
|
|
showContactDetail: action('showContactDetail'),
|
|
|
|
showContactModal: action('showContactModal'),
|
|
|
|
showExpiredIncomingTapToViewToast: action(
|
|
|
|
'showExpiredIncomingTapToViewToast'
|
|
|
|
),
|
|
|
|
showExpiredOutgoingTapToViewToast: action(
|
|
|
|
'showExpiredOutgoingTapToViewToast'
|
|
|
|
),
|
|
|
|
showForwardMessageModal: action('showForwardMessageModal'),
|
|
|
|
showVisualAttachment: action('showVisualAttachment'),
|
2020-08-27 18:10:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Delivered Incoming', () => {
|
|
|
|
const props = createProps({});
|
|
|
|
return <MessageDetail {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Delivered Outgoing', () => {
|
|
|
|
const props = createProps({
|
|
|
|
message: {
|
|
|
|
...defaultMessage,
|
|
|
|
direction: 'outgoing',
|
|
|
|
text: 'A message to Max',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return <MessageDetail {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Message Statuses', () => {
|
|
|
|
const props = createProps({
|
|
|
|
contacts: [
|
|
|
|
{
|
2021-05-07 22:21:10 +00:00
|
|
|
...getDefaultConversation({
|
2021-05-28 16:15:17 +00:00
|
|
|
color: 'forest',
|
2021-05-07 22:21:10 +00:00
|
|
|
title: 'Max',
|
|
|
|
}),
|
2020-08-27 18:10:35 +00:00
|
|
|
isOutgoingKeyError: false,
|
|
|
|
isUnidentifiedDelivery: false,
|
2021-07-12 23:51:45 +00:00
|
|
|
status: 'sent',
|
2020-08-27 18:10:35 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-07 22:21:10 +00:00
|
|
|
...getDefaultConversation({
|
|
|
|
color: 'blue',
|
|
|
|
title: 'Sally',
|
|
|
|
}),
|
2020-08-27 18:10:35 +00:00
|
|
|
isOutgoingKeyError: false,
|
|
|
|
isUnidentifiedDelivery: false,
|
2021-07-12 23:51:45 +00:00
|
|
|
status: 'sending',
|
2020-08-27 18:10:35 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-07 22:21:10 +00:00
|
|
|
...getDefaultConversation({
|
2021-05-28 16:15:17 +00:00
|
|
|
color: 'burlap',
|
2021-05-07 22:21:10 +00:00
|
|
|
title: 'Terry',
|
|
|
|
}),
|
2020-08-27 18:10:35 +00:00
|
|
|
isOutgoingKeyError: false,
|
|
|
|
isUnidentifiedDelivery: false,
|
2021-07-12 23:51:45 +00:00
|
|
|
status: 'partial-sent',
|
2020-08-27 18:10:35 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-07 22:21:10 +00:00
|
|
|
...getDefaultConversation({
|
2021-05-28 16:15:17 +00:00
|
|
|
color: 'wintergreen',
|
2021-05-07 22:21:10 +00:00
|
|
|
title: 'Theo',
|
|
|
|
}),
|
2020-08-27 18:10:35 +00:00
|
|
|
isOutgoingKeyError: false,
|
|
|
|
isUnidentifiedDelivery: false,
|
2021-07-12 23:51:45 +00:00
|
|
|
status: 'delivered',
|
2020-08-27 18:10:35 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-07 22:21:10 +00:00
|
|
|
...getDefaultConversation({
|
2021-05-28 16:15:17 +00:00
|
|
|
color: 'steel',
|
2021-05-07 22:21:10 +00:00
|
|
|
title: 'Nikki',
|
|
|
|
}),
|
2020-08-27 18:10:35 +00:00
|
|
|
isOutgoingKeyError: false,
|
|
|
|
isUnidentifiedDelivery: false,
|
2021-07-12 23:51:45 +00:00
|
|
|
status: 'read',
|
2020-08-27 18:10:35 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
message: {
|
|
|
|
...defaultMessage,
|
|
|
|
conversationType: 'group',
|
|
|
|
text: 'A message to you all!',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return <MessageDetail {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Not Delivered', () => {
|
|
|
|
const props = createProps({
|
|
|
|
message: {
|
|
|
|
...defaultMessage,
|
|
|
|
direction: 'outgoing',
|
|
|
|
text: 'A message to Max',
|
|
|
|
},
|
|
|
|
});
|
2020-09-14 19:51:27 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2020-08-27 18:10:35 +00:00
|
|
|
props.receivedAt = undefined as any;
|
|
|
|
|
|
|
|
return <MessageDetail {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('No Contacts', () => {
|
|
|
|
const props = createProps({
|
|
|
|
contacts: [],
|
|
|
|
message: {
|
|
|
|
...defaultMessage,
|
|
|
|
direction: 'outgoing',
|
|
|
|
text: 'Is anybody there?',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return <MessageDetail {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('All Errors', () => {
|
|
|
|
const props = createProps({
|
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
name: 'Another Error',
|
|
|
|
message: 'Wow, that went bad.',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
message: {
|
|
|
|
...defaultMessage,
|
|
|
|
},
|
|
|
|
contacts: [
|
|
|
|
{
|
2021-05-07 22:21:10 +00:00
|
|
|
...getDefaultConversation({
|
2021-05-28 16:15:17 +00:00
|
|
|
color: 'forest',
|
2021-05-07 22:21:10 +00:00
|
|
|
title: 'Max',
|
|
|
|
}),
|
2020-08-27 18:10:35 +00:00
|
|
|
isOutgoingKeyError: true,
|
|
|
|
isUnidentifiedDelivery: false,
|
2021-07-12 23:51:45 +00:00
|
|
|
status: 'error',
|
2020-08-27 18:10:35 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-07 22:21:10 +00:00
|
|
|
...getDefaultConversation({
|
|
|
|
color: 'blue',
|
|
|
|
title: 'Sally',
|
|
|
|
}),
|
2020-08-27 18:10:35 +00:00
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
name: 'Big Error',
|
|
|
|
message: 'Stuff happened, in a bad way.',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
isOutgoingKeyError: false,
|
|
|
|
isUnidentifiedDelivery: true,
|
2021-07-12 23:51:45 +00:00
|
|
|
status: 'error',
|
2020-08-27 18:10:35 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-07 22:21:10 +00:00
|
|
|
...getDefaultConversation({
|
2021-05-28 16:15:17 +00:00
|
|
|
color: 'taupe',
|
2021-05-07 22:21:10 +00:00
|
|
|
title: 'Terry',
|
|
|
|
}),
|
2020-08-27 18:10:35 +00:00
|
|
|
isOutgoingKeyError: true,
|
|
|
|
isUnidentifiedDelivery: true,
|
2021-07-12 23:51:45 +00:00
|
|
|
status: 'error',
|
2020-08-27 18:10:35 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
return <MessageDetail {...props} />;
|
|
|
|
});
|