| 
									
										
										
										
											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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 14:23:10 -06:00
										 |  |  | import React, { useEffect, useState } from 'react'; | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { Props as AvatarProps } from '../Avatar'; | 
					
						
							| 
									
										
										
										
											2022-12-09 13:37:45 -07:00
										 |  |  | import { Avatar, AvatarSize, AvatarBlur } from '../Avatar'; | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  | import { ContactName } from './ContactName'; | 
					
						
							| 
									
										
										
										
											2021-01-25 20:01:19 -05:00
										 |  |  | import { About } from './About'; | 
					
						
							| 
									
										
										
										
											2021-06-01 17:24:28 -07:00
										 |  |  | import { GroupDescription } from './GroupDescription'; | 
					
						
							| 
									
										
										
										
											2021-04-16 10:51:26 -05:00
										 |  |  | import { SharedGroupNames } from '../SharedGroupNames'; | 
					
						
							| 
									
										
										
										
											2021-11-02 18:01:13 -05:00
										 |  |  | import type { LocalizerType, ThemeType } from '../../types/Util'; | 
					
						
							| 
									
										
										
										
											2022-07-21 20:44:35 -04:00
										 |  |  | import type { HasStories } from '../../types/Stories'; | 
					
						
							| 
									
										
										
										
											2022-08-22 13:44:23 -04:00
										 |  |  | import type { ViewUserStoriesActionCreatorType } from '../../state/ducks/stories'; | 
					
						
							|  |  |  | import { StoryViewModeType } from '../../types/Stories'; | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  | import { ConfirmationDialog } from '../ConfirmationDialog'; | 
					
						
							|  |  |  | import { Button, ButtonSize, ButtonVariant } from '../Button'; | 
					
						
							| 
									
										
										
										
											2021-04-30 14:40:25 -05:00
										 |  |  | import { shouldBlurAvatar } from '../../util/shouldBlurAvatar'; | 
					
						
							| 
									
										
										
										
											2021-09-21 16:45:25 -04:00
										 |  |  | import { openLinkInWebBrowser } from '../../util/openLinkInWebBrowser'; | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | export type Props = { | 
					
						
							| 
									
										
										
										
											2021-01-25 20:01:19 -05:00
										 |  |  |   about?: string; | 
					
						
							| 
									
										
										
										
											2021-04-30 14:40:25 -05:00
										 |  |  |   acceptedMessageRequest?: boolean; | 
					
						
							| 
									
										
										
										
											2021-06-01 17:24:28 -07:00
										 |  |  |   groupDescription?: string; | 
					
						
							| 
									
										
										
										
											2022-07-21 20:44:35 -04:00
										 |  |  |   hasStories?: HasStories; | 
					
						
							|  |  |  |   id: string; | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   i18n: LocalizerType; | 
					
						
							| 
									
										
										
										
											2021-05-07 17:21:10 -05:00
										 |  |  |   isMe: boolean; | 
					
						
							| 
									
										
										
										
											2022-11-08 21:38:19 -05:00
										 |  |  |   isSignalConversation?: boolean; | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   membersCount?: number; | 
					
						
							| 
									
										
										
										
											2022-09-28 10:27:52 -06:00
										 |  |  |   name?: string; | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |   phoneNumber?: string; | 
					
						
							| 
									
										
										
										
											2022-12-21 16:07:02 -08:00
										 |  |  |   sharedGroupNames?: ReadonlyArray<string>; | 
					
						
							| 
									
										
										
										
											2022-12-20 19:25:10 -08:00
										 |  |  |   unblurAvatar: (conversationId: string) => void; | 
					
						
							| 
									
										
										
										
											2021-04-30 14:40:25 -05:00
										 |  |  |   unblurredAvatarPath?: string; | 
					
						
							| 
									
										
										
										
											2022-12-20 19:25:10 -08:00
										 |  |  |   updateSharedGroups: (conversationId: string) => unknown; | 
					
						
							| 
									
										
										
										
											2021-11-02 18:01:13 -05:00
										 |  |  |   theme: ThemeType; | 
					
						
							| 
									
										
										
										
											2022-08-22 13:44:23 -04:00
										 |  |  |   viewUserStories: ViewUserStoriesActionCreatorType; | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  | } & Omit<AvatarProps, 'onClick' | 'size' | 'noteToSelf'>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const renderMembershipRow = ({ | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |   acceptedMessageRequest, | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   conversationType, | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |   i18n, | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   isMe, | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |   onClickMessageRequestWarning, | 
					
						
							|  |  |  |   phoneNumber, | 
					
						
							|  |  |  |   sharedGroupNames, | 
					
						
							| 
									
										
										
										
											2021-04-01 11:27:17 -05:00
										 |  |  | }: Pick< | 
					
						
							|  |  |  |   Props, | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |   | 'acceptedMessageRequest' | 
					
						
							|  |  |  |   | 'conversationType' | 
					
						
							|  |  |  |   | 'i18n' | 
					
						
							|  |  |  |   | 'isMe' | 
					
						
							|  |  |  |   | 'phoneNumber' | 
					
						
							|  |  |  | > & | 
					
						
							|  |  |  |   Required<Pick<Props, 'sharedGroupNames'>> & { | 
					
						
							|  |  |  |     onClickMessageRequestWarning: () => void; | 
					
						
							|  |  |  |   }) => { | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   const className = 'module-conversation-hero__membership'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 11:27:17 -05:00
										 |  |  |   if (conversationType !== 'direct') { | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   if (isMe) { | 
					
						
							|  |  |  |     return <div className={className}>{i18n('noteToSelfHero')}</div>; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 11:27:17 -05:00
										 |  |  |   if (sharedGroupNames.length > 0) { | 
					
						
							| 
									
										
										
										
											2021-04-16 10:51:26 -05:00
										 |  |  |     return ( | 
					
						
							|  |  |  |       <div className={className}> | 
					
						
							|  |  |  |         <SharedGroupNames | 
					
						
							|  |  |  |           i18n={i18n} | 
					
						
							|  |  |  |           nameClassName={`${className}__name`} | 
					
						
							|  |  |  |           sharedGroupNames={sharedGroupNames} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |   if (acceptedMessageRequest) { | 
					
						
							|  |  |  |     if (phoneNumber) { | 
					
						
							|  |  |  |       return null; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-04-01 11:27:17 -05:00
										 |  |  |     return <div className={className}>{i18n('no-groups-in-common')}</div>; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <div className="module-conversation-hero__message-request-warning"> | 
					
						
							|  |  |  |       <div className="module-conversation-hero__message-request-warning__message"> | 
					
						
							|  |  |  |         {i18n('no-groups-in-common-warning')} | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       <Button | 
					
						
							|  |  |  |         onClick={onClickMessageRequestWarning} | 
					
						
							|  |  |  |         size={ButtonSize.Small} | 
					
						
							|  |  |  |         variant={ButtonVariant.SecondaryAffirmative} | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         {i18n('MessageRequestWarning__learn-more')} | 
					
						
							|  |  |  |       </Button> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function ConversationHero({ | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   i18n, | 
					
						
							| 
									
										
										
										
											2021-01-25 20:01:19 -05:00
										 |  |  |   about, | 
					
						
							| 
									
										
										
										
											2021-04-30 14:40:25 -05:00
										 |  |  |   acceptedMessageRequest, | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   avatarPath, | 
					
						
							| 
									
										
										
										
											2021-11-02 18:01:13 -05:00
										 |  |  |   badge, | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   color, | 
					
						
							|  |  |  |   conversationType, | 
					
						
							| 
									
										
										
										
											2021-06-01 17:24:28 -07:00
										 |  |  |   groupDescription, | 
					
						
							| 
									
										
										
										
											2022-07-21 20:44:35 -04:00
										 |  |  |   hasStories, | 
					
						
							|  |  |  |   id, | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   isMe, | 
					
						
							| 
									
										
										
										
											2022-11-08 21:38:19 -05:00
										 |  |  |   isSignalConversation, | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   membersCount, | 
					
						
							| 
									
										
										
										
											2020-08-04 18:13:19 -07:00
										 |  |  |   sharedGroupNames = [], | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   name, | 
					
						
							|  |  |  |   phoneNumber, | 
					
						
							|  |  |  |   profileName, | 
					
						
							| 
									
										
										
										
											2021-11-02 18:01:13 -05:00
										 |  |  |   theme, | 
					
						
							| 
									
										
										
										
											2020-07-23 18:35:32 -07:00
										 |  |  |   title, | 
					
						
							| 
									
										
										
										
											2021-04-30 14:40:25 -05:00
										 |  |  |   unblurAvatar, | 
					
						
							|  |  |  |   unblurredAvatarPath, | 
					
						
							| 
									
										
										
										
											2020-08-06 17:50:54 -07:00
										 |  |  |   updateSharedGroups, | 
					
						
							| 
									
										
										
										
											2022-07-21 20:44:35 -04:00
										 |  |  |   viewUserStories, | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | }: Props): JSX.Element { | 
					
						
							| 
									
										
										
										
											2021-11-11 16:43:05 -06:00
										 |  |  |   const [isShowingMessageRequestWarning, setIsShowingMessageRequestWarning] = | 
					
						
							|  |  |  |     useState(false); | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |   const closeMessageRequestWarning = () => { | 
					
						
							|  |  |  |     setIsShowingMessageRequestWarning(false); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2020-08-06 17:50:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     // Kick off the expensive hydration of the current sharedGroupNames
 | 
					
						
							| 
									
										
										
										
											2022-12-20 19:25:10 -08:00
										 |  |  |     updateSharedGroups(id); | 
					
						
							|  |  |  |   }, [id, updateSharedGroups]); | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-21 20:44:35 -04:00
										 |  |  |   let avatarBlur: AvatarBlur = AvatarBlur.NoBlur; | 
					
						
							| 
									
										
										
										
											2021-04-30 14:40:25 -05:00
										 |  |  |   let avatarOnClick: undefined | (() => void); | 
					
						
							|  |  |  |   if ( | 
					
						
							|  |  |  |     shouldBlurAvatar({ | 
					
						
							|  |  |  |       acceptedMessageRequest, | 
					
						
							|  |  |  |       avatarPath, | 
					
						
							|  |  |  |       isMe, | 
					
						
							|  |  |  |       sharedGroupNames, | 
					
						
							|  |  |  |       unblurredAvatarPath, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   ) { | 
					
						
							|  |  |  |     avatarBlur = AvatarBlur.BlurPictureWithClickToView; | 
					
						
							| 
									
										
										
										
											2022-12-20 19:25:10 -08:00
										 |  |  |     avatarOnClick = () => unblurAvatar(id); | 
					
						
							| 
									
										
										
										
											2022-07-21 20:44:35 -04:00
										 |  |  |   } else if (hasStories) { | 
					
						
							|  |  |  |     avatarOnClick = () => { | 
					
						
							| 
									
										
										
										
											2022-08-22 13:44:23 -04:00
										 |  |  |       viewUserStories({ | 
					
						
							|  |  |  |         conversationId: id, | 
					
						
							|  |  |  |         storyViewMode: StoryViewModeType.User, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-07-21 20:44:35 -04:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-04-30 14:40:25 -05:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-23 18:35:32 -07:00
										 |  |  |   const phoneNumberOnly = Boolean( | 
					
						
							|  |  |  |     !name && !profileName && conversationType === 'direct' | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 12:51:27 -07:00
										 |  |  |   /* eslint-disable no-nested-ternary */ | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |     <> | 
					
						
							| 
									
										
										
										
											2021-08-19 11:36:09 -05:00
										 |  |  |       <div className="module-conversation-hero"> | 
					
						
							|  |  |  |         <Avatar | 
					
						
							|  |  |  |           acceptedMessageRequest={acceptedMessageRequest} | 
					
						
							|  |  |  |           avatarPath={avatarPath} | 
					
						
							| 
									
										
										
										
											2021-11-02 18:01:13 -05:00
										 |  |  |           badge={badge} | 
					
						
							| 
									
										
										
										
											2021-08-19 11:36:09 -05:00
										 |  |  |           blur={avatarBlur} | 
					
						
							|  |  |  |           className="module-conversation-hero__avatar" | 
					
						
							|  |  |  |           color={color} | 
					
						
							|  |  |  |           conversationType={conversationType} | 
					
						
							|  |  |  |           i18n={i18n} | 
					
						
							|  |  |  |           isMe={isMe} | 
					
						
							|  |  |  |           noteToSelf={isMe} | 
					
						
							|  |  |  |           onClick={avatarOnClick} | 
					
						
							|  |  |  |           profileName={profileName} | 
					
						
							|  |  |  |           sharedGroupNames={sharedGroupNames} | 
					
						
							| 
									
										
										
										
											2022-12-09 13:37:45 -07:00
										 |  |  |           size={AvatarSize.EIGHTY} | 
					
						
							| 
									
										
										
										
											2022-10-04 15:39:29 -06:00
										 |  |  |           // user may have stories, but we don't show that on Note to Self conversation
 | 
					
						
							|  |  |  |           storyRing={isMe ? undefined : hasStories} | 
					
						
							| 
									
										
										
										
											2021-11-02 18:01:13 -05:00
										 |  |  |           theme={theme} | 
					
						
							| 
									
										
										
										
											2021-08-19 11:36:09 -05:00
										 |  |  |           title={title} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |         <h1 className="module-conversation-hero__profile-name"> | 
					
						
							| 
									
										
										
										
											2022-11-08 21:38:19 -05:00
										 |  |  |           {isMe ? ( | 
					
						
							|  |  |  |             i18n('noteToSelf') | 
					
						
							|  |  |  |           ) : ( | 
					
						
							|  |  |  |             <ContactName | 
					
						
							|  |  |  |               isSignalConversation={isSignalConversation} | 
					
						
							|  |  |  |               title={title} | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           )} | 
					
						
							| 
									
										
										
										
											2021-08-19 11:36:09 -05:00
										 |  |  |         </h1> | 
					
						
							|  |  |  |         {about && !isMe && ( | 
					
						
							|  |  |  |           <div className="module-about__container"> | 
					
						
							|  |  |  |             <About text={about} /> | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |         )} | 
					
						
							| 
									
										
										
										
											2021-08-19 11:36:09 -05:00
										 |  |  |         {!isMe ? ( | 
					
						
							|  |  |  |           <div className="module-conversation-hero__with"> | 
					
						
							|  |  |  |             {groupDescription ? ( | 
					
						
							|  |  |  |               <GroupDescription | 
					
						
							|  |  |  |                 i18n={i18n} | 
					
						
							|  |  |  |                 title={title} | 
					
						
							|  |  |  |                 text={groupDescription} | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2022-10-25 16:57:16 -07:00
										 |  |  |             ) : membersCount != null ? ( | 
					
						
							|  |  |  |               i18n('icu:ConversationHero--members', { count: membersCount }) | 
					
						
							| 
									
										
										
										
											2021-08-19 11:36:09 -05:00
										 |  |  |             ) : phoneNumberOnly ? null : ( | 
					
						
							|  |  |  |               phoneNumber | 
					
						
							|  |  |  |             )} | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         ) : null} | 
					
						
							| 
									
										
										
										
											2022-11-08 21:38:19 -05:00
										 |  |  |         {!isSignalConversation && | 
					
						
							|  |  |  |           renderMembershipRow({ | 
					
						
							|  |  |  |             acceptedMessageRequest, | 
					
						
							|  |  |  |             conversationType, | 
					
						
							|  |  |  |             i18n, | 
					
						
							|  |  |  |             isMe, | 
					
						
							|  |  |  |             onClickMessageRequestWarning() { | 
					
						
							|  |  |  |               setIsShowingMessageRequestWarning(true); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             phoneNumber, | 
					
						
							|  |  |  |             sharedGroupNames, | 
					
						
							|  |  |  |           })} | 
					
						
							|  |  |  |         {!isSignalConversation && ( | 
					
						
							|  |  |  |           <div className="module-conversation-hero__linkNotification"> | 
					
						
							|  |  |  |             {i18n('messageHistoryUnsynced')} | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         )} | 
					
						
							| 
									
										
										
										
											2021-08-19 11:36:09 -05:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |       {isShowingMessageRequestWarning && ( | 
					
						
							|  |  |  |         <ConfirmationDialog | 
					
						
							| 
									
										
										
										
											2022-09-27 13:24:21 -07:00
										 |  |  |           dialogName="ConversationHere.messageRequestWarning" | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |           i18n={i18n} | 
					
						
							|  |  |  |           onClose={closeMessageRequestWarning} | 
					
						
							|  |  |  |           actions={[ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               text: i18n('MessageRequestWarning__dialog__learn-even-more'), | 
					
						
							|  |  |  |               action: () => { | 
					
						
							| 
									
										
										
										
											2021-09-21 16:45:25 -04:00
										 |  |  |                 openLinkInWebBrowser( | 
					
						
							|  |  |  |                   'https://support.signal.org/hc/articles/360007459591' | 
					
						
							|  |  |  |                 ); | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |                 closeMessageRequestWarning(); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           ]} | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           {i18n('MessageRequestWarning__dialog__details')} | 
					
						
							|  |  |  |         </ConfirmationDialog> | 
					
						
							| 
									
										
										
										
											2021-01-25 20:01:19 -05:00
										 |  |  |       )} | 
					
						
							| 
									
										
										
										
											2021-04-30 17:58:57 -05:00
										 |  |  |     </> | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   ); | 
					
						
							| 
									
										
										
										
											2020-09-14 12:51:27 -07:00
										 |  |  |   /* eslint-enable no-nested-ternary */ | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } |