| 
									
										
										
										
											2023-01-03 11:55:46 -08:00
										 |  |  | // Copyright 2020 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  | import * as React from 'react'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { action } from '@storybook/addon-actions'; | 
					
						
							|  |  |  | import { number } from '@storybook/addon-knobs'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { PropsData as MessageDataPropsType } from './Message'; | 
					
						
							| 
									
										
										
										
											2022-03-23 13:23:28 -07:00
										 |  |  | import { TextDirection } from './Message'; | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { Props } from './MessageDetail'; | 
					
						
							|  |  |  | import { MessageDetail } from './MessageDetail'; | 
					
						
							| 
									
										
										
										
											2021-07-19 17:44:49 -05:00
										 |  |  | import { SendStatus } from '../../messages/MessageSendState'; | 
					
						
							| 
									
										
										
										
											2021-08-12 13:15:55 -05:00
										 |  |  | import { ReadStatus } from '../../messages/MessageReadStatus'; | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  | import { getDefaultConversation } from '../../test-both/helpers/getDefaultConversation'; | 
					
						
							| 
									
										
										
										
											2021-09-17 20:30:08 -04:00
										 |  |  | import { setupI18n } from '../../util/setupI18n'; | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  | import enMessages from '../../../_locales/en/messages.json'; | 
					
						
							| 
									
										
										
										
											2021-11-15 16:53:42 -06:00
										 |  |  | import { getFakeBadge } from '../../test-both/helpers/getFakeBadge'; | 
					
						
							|  |  |  | import { ThemeType } from '../../types/Util'; | 
					
						
							| 
									
										
										
										
											2020-09-14 12:51:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  | const i18n = setupI18n('en', enMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | export default { | 
					
						
							|  |  |  |   title: 'Components/Conversation/MessageDetail', | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-24 17:06:12 -05:00
										 |  |  | const defaultMessage: MessageDataPropsType = { | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |   author: getDefaultConversation({ | 
					
						
							| 
									
										
										
										
											2021-04-27 14:55:21 -05:00
										 |  |  |     id: 'some-id', | 
					
						
							|  |  |  |     title: 'Max', | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |   }), | 
					
						
							| 
									
										
										
										
											2020-09-29 15:55:56 -07:00
										 |  |  |   canDeleteForEveryone: true, | 
					
						
							| 
									
										
										
										
											2021-05-28 12:15:17 -04:00
										 |  |  |   conversationColor: 'crimson', | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   conversationId: 'my-convo', | 
					
						
							| 
									
										
										
										
											2022-05-11 13:59:58 -07:00
										 |  |  |   conversationTitle: 'Conversation Title', | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   conversationType: 'direct', | 
					
						
							|  |  |  |   direction: 'incoming', | 
					
						
							|  |  |  |   id: 'my-message', | 
					
						
							| 
									
										
										
										
											2021-06-29 12:58:29 -07:00
										 |  |  |   renderingContext: 'storybook', | 
					
						
							| 
									
										
										
										
											2022-12-19 14:33:55 -08:00
										 |  |  |   renderMenu: undefined, | 
					
						
							| 
									
										
										
										
											2021-02-02 11:09:53 -06:00
										 |  |  |   isBlocked: false, | 
					
						
							|  |  |  |   isMessageRequestAccepted: true, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   previews: [], | 
					
						
							| 
									
										
										
										
											2021-08-12 13:15:55 -05:00
										 |  |  |   readStatus: ReadStatus.Read, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   status: 'sent', | 
					
						
							|  |  |  |   text: 'A message from Max', | 
					
						
							| 
									
										
										
										
											2022-03-23 13:23:28 -07:00
										 |  |  |   textDirection: TextDirection.Default, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   timestamp: Date.now(), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const createProps = (overrideProps: Partial<Props> = {}): Props => ({ | 
					
						
							|  |  |  |   contacts: overrideProps.contacts || [ | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |       ...getDefaultConversation({ | 
					
						
							|  |  |  |         title: 'Just Max', | 
					
						
							|  |  |  |       }), | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |       isOutgoingKeyError: false, | 
					
						
							|  |  |  |       isUnidentifiedDelivery: false, | 
					
						
							| 
									
										
										
										
											2021-07-19 17:44:49 -05:00
										 |  |  |       status: SendStatus.Delivered, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07: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 17:06:12 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-16 09:53:41 -06:00
										 |  |  |   getPreferredBadge: () => getFakeBadge(), | 
					
						
							| 
									
										
										
										
											2021-03-24 17:06:12 -05:00
										 |  |  |   i18n, | 
					
						
							|  |  |  |   interactionMode: 'keyboard', | 
					
						
							| 
									
										
										
										
											2021-11-15 16:53:42 -06:00
										 |  |  |   theme: ThemeType.light, | 
					
						
							| 
									
										
										
										
											2021-03-24 17:06:12 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-09 00:53:19 -05:00
										 |  |  |   toggleSafetyNumberModal: action('toggleSafetyNumberModal'), | 
					
						
							| 
									
										
										
										
											2021-06-15 17:44:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  |   checkForAccount: action('checkForAccount'), | 
					
						
							|  |  |  |   clearSelectedMessage: action('clearSelectedMessage'), | 
					
						
							| 
									
										
										
										
											2022-12-09 21:02:22 -05:00
										 |  |  |   showLightboxForViewOnceMedia: action('showLightboxForViewOnceMedia'), | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  |   doubleCheckMissingQuoteReference: action('doubleCheckMissingQuoteReference'), | 
					
						
							| 
									
										
										
										
											2021-03-24 17:06:12 -05:00
										 |  |  |   kickOffAttachmentDownload: action('kickOffAttachmentDownload'), | 
					
						
							|  |  |  |   markAttachmentAsCorrupted: action('markAttachmentAsCorrupted'), | 
					
						
							| 
									
										
										
										
											2022-12-14 11:05:32 -08:00
										 |  |  |   showConversation: action('showConversation'), | 
					
						
							| 
									
										
										
										
											2022-05-11 13:59:58 -07:00
										 |  |  |   openGiftBadge: action('openGiftBadge'), | 
					
						
							| 
									
										
										
										
											2021-03-24 17:06:12 -05:00
										 |  |  |   renderAudioAttachment: () => <div>*AudioAttachment*</div>, | 
					
						
							| 
									
										
										
										
											2022-12-14 13:12:04 -05:00
										 |  |  |   saveAttachment: action('saveAttachment'), | 
					
						
							| 
									
										
										
										
											2022-12-14 20:10:09 -05:00
										 |  |  |   pushPanelForConversation: action('pushPanelForConversation'), | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  |   showContactModal: action('showContactModal'), | 
					
						
							|  |  |  |   showExpiredIncomingTapToViewToast: action( | 
					
						
							|  |  |  |     'showExpiredIncomingTapToViewToast' | 
					
						
							|  |  |  |   ), | 
					
						
							|  |  |  |   showExpiredOutgoingTapToViewToast: action( | 
					
						
							|  |  |  |     'showExpiredOutgoingTapToViewToast' | 
					
						
							|  |  |  |   ), | 
					
						
							| 
									
										
										
										
											2022-12-09 21:02:22 -05:00
										 |  |  |   showLightbox: action('showLightbox'), | 
					
						
							| 
									
										
										
										
											2022-04-11 17:26:09 -07:00
										 |  |  |   startConversation: action('startConversation'), | 
					
						
							| 
									
										
										
										
											2022-07-06 15:06:20 -04:00
										 |  |  |   viewStory: action('viewStory'), | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function DeliveredIncoming(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2021-07-20 14:56:50 -05:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     contacts: [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ...getDefaultConversation({ | 
					
						
							|  |  |  |           color: 'forest', | 
					
						
							|  |  |  |           title: 'Max', | 
					
						
							|  |  |  |         }), | 
					
						
							|  |  |  |         status: undefined, | 
					
						
							|  |  |  |         isOutgoingKeyError: false, | 
					
						
							|  |  |  |         isUnidentifiedDelivery: false, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   return <MessageDetail {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function DeliveredOutgoing(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     message: { | 
					
						
							|  |  |  |       ...defaultMessage, | 
					
						
							|  |  |  |       direction: 'outgoing', | 
					
						
							|  |  |  |       text: 'A message to Max', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return <MessageDetail {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function MessageStatuses(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     contacts: [ | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |         ...getDefaultConversation({ | 
					
						
							|  |  |  |           title: 'Max', | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |         isOutgoingKeyError: false, | 
					
						
							|  |  |  |         isUnidentifiedDelivery: false, | 
					
						
							| 
									
										
										
										
											2021-07-19 17:44:49 -05:00
										 |  |  |         status: SendStatus.Sent, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |         ...getDefaultConversation({ | 
					
						
							|  |  |  |           title: 'Sally', | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |         isOutgoingKeyError: false, | 
					
						
							|  |  |  |         isUnidentifiedDelivery: false, | 
					
						
							| 
									
										
										
										
											2021-07-19 17:44:49 -05:00
										 |  |  |         status: SendStatus.Pending, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |         ...getDefaultConversation({ | 
					
						
							|  |  |  |           title: 'Terry', | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |         isOutgoingKeyError: false, | 
					
						
							|  |  |  |         isUnidentifiedDelivery: false, | 
					
						
							| 
									
										
										
										
											2021-07-19 17:44:49 -05:00
										 |  |  |         status: SendStatus.Failed, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |         ...getDefaultConversation({ | 
					
						
							|  |  |  |           title: 'Theo', | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |         isOutgoingKeyError: false, | 
					
						
							|  |  |  |         isUnidentifiedDelivery: false, | 
					
						
							| 
									
										
										
										
											2021-07-19 17:44:49 -05:00
										 |  |  |         status: SendStatus.Delivered, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |         ...getDefaultConversation({ | 
					
						
							|  |  |  |           title: 'Nikki', | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |         isOutgoingKeyError: false, | 
					
						
							|  |  |  |         isUnidentifiedDelivery: false, | 
					
						
							| 
									
										
										
										
											2021-07-19 17:44:49 -05:00
										 |  |  |         status: SendStatus.Read, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |       }, | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |     message: { | 
					
						
							|  |  |  |       ...defaultMessage, | 
					
						
							|  |  |  |       conversationType: 'group', | 
					
						
							|  |  |  |       text: 'A message to you all!', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return <MessageDetail {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function NotDelivered(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     message: { | 
					
						
							|  |  |  |       ...defaultMessage, | 
					
						
							|  |  |  |       direction: 'outgoing', | 
					
						
							|  |  |  |       text: 'A message to Max', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-09-14 12:51:27 -07:00
										 |  |  |   // eslint-disable-next-line @typescript-eslint/no-explicit-any
 | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   props.receivedAt = undefined as any; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <MessageDetail {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function NoContacts(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     contacts: [], | 
					
						
							|  |  |  |     message: { | 
					
						
							|  |  |  |       ...defaultMessage, | 
					
						
							|  |  |  |       direction: 'outgoing', | 
					
						
							|  |  |  |       text: 'Is anybody there?', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return <MessageDetail {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function AllErrors(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     errors: [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         name: 'Another Error', | 
					
						
							|  |  |  |         message: 'Wow, that went bad.', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |     message: { | 
					
						
							|  |  |  |       ...defaultMessage, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     contacts: [ | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |         ...getDefaultConversation({ | 
					
						
							|  |  |  |           title: 'Max', | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |         isOutgoingKeyError: true, | 
					
						
							|  |  |  |         isUnidentifiedDelivery: false, | 
					
						
							| 
									
										
										
										
											2021-07-19 17:44:49 -05:00
										 |  |  |         status: SendStatus.Failed, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |         ...getDefaultConversation({ | 
					
						
							|  |  |  |           title: 'Sally', | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |         errors: [ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             name: 'Big Error', | 
					
						
							|  |  |  |             message: 'Stuff happened, in a bad way.', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         isOutgoingKeyError: false, | 
					
						
							|  |  |  |         isUnidentifiedDelivery: true, | 
					
						
							| 
									
										
										
										
											2021-07-19 17:44:49 -05:00
										 |  |  |         status: SendStatus.Failed, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |         ...getDefaultConversation({ | 
					
						
							|  |  |  |           title: 'Terry', | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |         isOutgoingKeyError: true, | 
					
						
							|  |  |  |         isUnidentifiedDelivery: true, | 
					
						
							| 
									
										
										
										
											2021-07-19 17:44:49 -05:00
										 |  |  |         status: SendStatus.Failed, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:10:35 -07:00
										 |  |  |       }, | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return <MessageDetail {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } |