| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // Copyright 2020 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | import * as React from 'react'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { boolean, text } from '@storybook/addon-knobs'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { Props } from './MessageBody'; | 
					
						
							|  |  |  | import { MessageBody } from './MessageBody'; | 
					
						
							| 
									
										
										
										
											2021-09-17 20:30:08 -04:00
										 |  |  | import { setupI18n } from '../../util/setupI18n'; | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | import enMessages from '../../../_locales/en/messages.json'; | 
					
						
							| 
									
										
										
										
											2020-09-14 12:51:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | const i18n = setupI18n('en', enMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | export default { | 
					
						
							|  |  |  |   title: 'Components/Conversation/MessageBody', | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const createProps = (overrideProps: Partial<Props> = {}): Props => ({ | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |   bodyRanges: overrideProps.bodyRanges, | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  |   disableJumbomoji: boolean( | 
					
						
							|  |  |  |     'disableJumbomoji', | 
					
						
							|  |  |  |     overrideProps.disableJumbomoji || false | 
					
						
							|  |  |  |   ), | 
					
						
							|  |  |  |   disableLinks: boolean('disableLinks', overrideProps.disableLinks || false), | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |   direction: 'incoming', | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  |   i18n, | 
					
						
							|  |  |  |   text: text('text', overrideProps.text || ''), | 
					
						
							| 
									
										
										
										
											2022-05-23 16:07:41 -07:00
										 |  |  |   textAttachment: overrideProps.textAttachment || { | 
					
						
							|  |  |  |     pending: boolean('textPending', false), | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function LinksEnabled(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     text: 'Check out https://www.signal.org', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <MessageBody {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function LinksDisabled(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     disableLinks: true, | 
					
						
							|  |  |  |     text: 'Check out https://www.signal.org', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <MessageBody {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function EmojiSizeBasedOnCount(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  |   const props = createProps(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							|  |  |  |       <MessageBody {...props} text="😹" /> | 
					
						
							|  |  |  |       <br /> | 
					
						
							|  |  |  |       <MessageBody {...props} text="😹😹😹" /> | 
					
						
							|  |  |  |       <br /> | 
					
						
							|  |  |  |       <MessageBody {...props} text="😹😹😹😹😹" /> | 
					
						
							|  |  |  |       <br /> | 
					
						
							|  |  |  |       <MessageBody {...props} text="😹😹😹😹😹😹😹" /> | 
					
						
							|  |  |  |       <br /> | 
					
						
							|  |  |  |       <MessageBody {...props} text="😹😹😹😹😹😹😹😹😹" /> | 
					
						
							|  |  |  |     </> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function JumbomojiEnabled(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     text: '😹', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <MessageBody {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function JumbomojiDisabled(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     disableJumbomoji: true, | 
					
						
							|  |  |  |     text: '😹', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <MessageBody {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function JumbomojiDisabledByText(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     text: 'not a jumbo kitty 😹', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <MessageBody {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | JumbomojiDisabledByText.story = { | 
					
						
							|  |  |  |   name: 'Jumbomoji Disabled by Text', | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function TextPending(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     text: 'Check out https://www.signal.org', | 
					
						
							| 
									
										
										
										
											2022-05-23 16:07:41 -07:00
										 |  |  |     textAttachment: { | 
					
						
							|  |  |  |       pending: true, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2020-08-26 17:07:26 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <MessageBody {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function Mention(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     bodyRanges: [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         start: 5, | 
					
						
							|  |  |  |         length: 1, | 
					
						
							|  |  |  |         mentionUuid: 'tuv', | 
					
						
							|  |  |  |         replacementText: 'Bender B Rodriguez 🤖', | 
					
						
							| 
									
										
										
										
											2022-11-09 20:59:36 -08:00
										 |  |  |         conversationID: 'x', | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |       }, | 
					
						
							|  |  |  |     ], | 
					
						
							| 
									
										
										
										
											2021-11-11 16:43:05 -06:00
										 |  |  |     text: 'Like \uFFFC once said: My story is a lot like yours, only more interesting because it involves robots', | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <MessageBody {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | Mention.story = { | 
					
						
							|  |  |  |   name: '@Mention', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function MultipleMentions(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |   const props = createProps({ | 
					
						
							| 
									
										
										
										
											2021-03-19 16:37:06 -04:00
										 |  |  |     // These are intentionally in a mixed order to test how we deal with that
 | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |     bodyRanges: [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         start: 2, | 
					
						
							|  |  |  |         length: 1, | 
					
						
							|  |  |  |         mentionUuid: 'def', | 
					
						
							|  |  |  |         replacementText: 'Philip J Fry', | 
					
						
							| 
									
										
										
										
											2022-11-09 20:59:36 -08:00
										 |  |  |         conversationID: 'x', | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-03-19 16:37:06 -04:00
										 |  |  |       { | 
					
						
							|  |  |  |         start: 4, | 
					
						
							|  |  |  |         length: 1, | 
					
						
							|  |  |  |         mentionUuid: 'abc', | 
					
						
							|  |  |  |         replacementText: 'Professor Farnsworth', | 
					
						
							| 
									
										
										
										
											2022-11-09 20:59:36 -08:00
										 |  |  |         conversationID: 'x', | 
					
						
							| 
									
										
										
										
											2021-03-19 16:37:06 -04:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |       { | 
					
						
							|  |  |  |         start: 0, | 
					
						
							|  |  |  |         length: 1, | 
					
						
							|  |  |  |         mentionUuid: 'xyz', | 
					
						
							|  |  |  |         replacementText: 'Yancy Fry', | 
					
						
							| 
									
										
										
										
											2022-11-09 20:59:36 -08:00
										 |  |  |         conversationID: 'x', | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |       }, | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |     text: '\uFFFC \uFFFC \uFFFC', | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <MessageBody {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | MultipleMentions.story = { | 
					
						
							|  |  |  |   name: 'Multiple @Mentions', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function ComplexMessageBody(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     bodyRanges: [ | 
					
						
							| 
									
										
										
										
											2021-03-19 16:37:06 -04:00
										 |  |  |       // These are intentionally in a mixed order to test how we deal with that
 | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |       { | 
					
						
							|  |  |  |         start: 78, | 
					
						
							|  |  |  |         length: 1, | 
					
						
							|  |  |  |         mentionUuid: 'wer', | 
					
						
							|  |  |  |         replacementText: 'Acid Burn', | 
					
						
							| 
									
										
										
										
											2022-11-09 20:59:36 -08:00
										 |  |  |         conversationID: 'x', | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-03-19 16:37:06 -04:00
										 |  |  |       { | 
					
						
							|  |  |  |         start: 80, | 
					
						
							|  |  |  |         length: 1, | 
					
						
							|  |  |  |         mentionUuid: 'xox', | 
					
						
							|  |  |  |         replacementText: 'Cereal Killer', | 
					
						
							| 
									
										
										
										
											2022-11-09 20:59:36 -08:00
										 |  |  |         conversationID: 'x', | 
					
						
							| 
									
										
										
										
											2021-03-19 16:37:06 -04:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |       { | 
					
						
							|  |  |  |         start: 4, | 
					
						
							|  |  |  |         length: 1, | 
					
						
							|  |  |  |         mentionUuid: 'ldo', | 
					
						
							|  |  |  |         replacementText: 'Zero Cool', | 
					
						
							| 
									
										
										
										
											2022-11-09 20:59:36 -08:00
										 |  |  |         conversationID: 'x', | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |       }, | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  |     direction: 'outgoing', | 
					
						
							| 
									
										
										
										
											2021-11-11 16:43:05 -06:00
										 |  |  |     text: 'Hey \uFFFC\nCheck out https://www.signal.org I think you will really like it 😍\n\ncc \uFFFC \uFFFC', | 
					
						
							| 
									
										
										
										
											2020-09-16 18:42:48 -04:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <MessageBody {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ComplexMessageBody.story = { | 
					
						
							|  |  |  |   name: 'Complex MessageBody', | 
					
						
							|  |  |  | }; |