| 
									
										
										
										
											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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-12 09:29:31 -07:00
										 |  |  | import React, { useMemo } from 'react'; | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  | import { useSelector } from 'react-redux'; | 
					
						
							| 
									
										
										
										
											2020-10-30 12:52:21 -05:00
										 |  |  | import { pick } from 'lodash'; | 
					
						
							| 
									
										
										
										
											2022-07-21 20:44:35 -04:00
										 |  |  | import type { ConversationType } from '../ducks/conversations'; | 
					
						
							|  |  |  | import type { StateType } from '../reducer'; | 
					
						
							| 
									
										
										
										
											2020-11-19 10:37:56 -06:00
										 |  |  | import { | 
					
						
							|  |  |  |   ConversationHeader, | 
					
						
							|  |  |  |   OutgoingCallButtonStyle, | 
					
						
							|  |  |  | } from '../../components/conversation/ConversationHeader'; | 
					
						
							| 
									
										
										
										
											2021-11-02 18:01:13 -05:00
										 |  |  | import { getPreferredBadgeSelector } from '../selectors/badges'; | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |   getConversationByServiceIdSelector, | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  |   getConversationSelector, | 
					
						
							| 
									
										
										
										
											2023-07-26 18:23:32 -04:00
										 |  |  |   getHasPanelOpen, | 
					
						
							| 
									
										
										
										
											2024-01-04 12:15:46 -08:00
										 |  |  |   getSelectedMessageIds, | 
					
						
							| 
									
										
										
										
											2021-06-17 10:15:10 -07:00
										 |  |  |   isMissingRequiredProfileSharing, | 
					
						
							|  |  |  | } from '../selectors/conversations'; | 
					
						
							| 
									
										
										
										
											2020-11-13 13:57:55 -06:00
										 |  |  | import { CallMode } from '../../types/Calling'; | 
					
						
							| 
									
										
										
										
											2023-07-19 01:57:38 +02:00
										 |  |  | import { getActiveCall, useCallingActions } from '../ducks/calling'; | 
					
						
							|  |  |  | import { isAnybodyElseInGroupCall } from '../ducks/callingHelpers'; | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  | import { | 
					
						
							|  |  |  |   getConversationCallMode, | 
					
						
							|  |  |  |   useConversationsActions, | 
					
						
							|  |  |  | } from '../ducks/conversations'; | 
					
						
							| 
									
										
										
										
											2023-03-07 21:15:25 -05:00
										 |  |  | import { getHasStoriesSelector } from '../selectors/stories2'; | 
					
						
							| 
									
										
										
										
											2020-11-20 11:19:28 -06:00
										 |  |  | import { getOwn } from '../../util/getOwn'; | 
					
						
							| 
									
										
										
										
											2022-07-21 20:44:35 -04:00
										 |  |  | import { getUserACI, getIntl, getTheme } from '../selectors/user'; | 
					
						
							| 
									
										
										
										
											2021-05-25 15:30:57 -07:00
										 |  |  | import { isConversationSMSOnly } from '../../util/isConversationSMSOnly'; | 
					
						
							| 
									
										
										
										
											2022-07-21 20:44:35 -04:00
										 |  |  | import { missingCaseError } from '../../util/missingCaseError'; | 
					
						
							| 
									
										
										
										
											2022-02-23 10:48:40 -08:00
										 |  |  | import { strictAssert } from '../../util/assert'; | 
					
						
							| 
									
										
										
										
											2022-11-08 21:38:19 -05:00
										 |  |  | import { isSignalConversation } from '../../util/isSignalConversation'; | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  | import { useSearchActions } from '../ducks/search'; | 
					
						
							|  |  |  | import { useStoriesActions } from '../ducks/stories'; | 
					
						
							| 
									
										
										
										
											2023-06-29 11:40:00 -07:00
										 |  |  | import { getCannotLeaveBecauseYouAreLastAdmin } from '../../components/conversation/conversation-details/ConversationDetails'; | 
					
						
							|  |  |  | import { getGroupMemberships } from '../../util/getGroupMemberships'; | 
					
						
							| 
									
										
										
										
											2024-02-22 13:19:50 -08:00
										 |  |  | import { isGroupOrAdhocCallState } from '../../util/isGroupOrAdhocCall'; | 
					
						
							| 
									
										
										
										
											2024-03-12 09:29:31 -07:00
										 |  |  | import { useContactNameData } from '../../components/conversation/ContactName'; | 
					
						
							|  |  |  | import { getAddedByForOurPendingInvitation } from '../../util/getAddedByForOurPendingInvitation'; | 
					
						
							| 
									
										
										
										
											2020-10-30 12:52:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 12:07:05 -06:00
										 |  |  | export type OwnProps = { | 
					
						
							| 
									
										
										
										
											2020-10-30 12:52:21 -05:00
										 |  |  |   id: string; | 
					
						
							| 
									
										
										
										
											2021-01-14 12:07:05 -06:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-10-30 12:52:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 10:37:56 -06:00
										 |  |  | const getOutgoingCallButtonStyle = ( | 
					
						
							|  |  |  |   conversation: ConversationType, | 
					
						
							|  |  |  |   state: StateType | 
					
						
							|  |  |  | ): OutgoingCallButtonStyle => { | 
					
						
							| 
									
										
										
										
											2020-11-20 11:19:28 -06:00
										 |  |  |   const { calling } = state; | 
					
						
							| 
									
										
										
										
											2023-08-10 18:43:33 +02:00
										 |  |  |   const ourAci = getUserACI(state); | 
					
						
							|  |  |  |   strictAssert(ourAci, 'getOutgoingCallButtonStyle missing our uuid'); | 
					
						
							| 
									
										
										
										
											2020-11-20 11:19:28 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (getActiveCall(calling)) { | 
					
						
							| 
									
										
										
										
											2020-11-19 10:37:56 -06:00
										 |  |  |     return OutgoingCallButtonStyle.None; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const conversationCallMode = getConversationCallMode(conversation); | 
					
						
							|  |  |  |   switch (conversationCallMode) { | 
					
						
							| 
									
										
										
										
											2023-08-16 17:11:09 -07:00
										 |  |  |     case null: | 
					
						
							| 
									
										
										
										
											2020-11-19 10:37:56 -06:00
										 |  |  |       return OutgoingCallButtonStyle.None; | 
					
						
							|  |  |  |     case CallMode.Direct: | 
					
						
							|  |  |  |       return OutgoingCallButtonStyle.Both; | 
					
						
							| 
									
										
										
										
											2024-02-22 13:19:50 -08:00
										 |  |  |     case CallMode.Group: | 
					
						
							|  |  |  |     case CallMode.Adhoc: { | 
					
						
							| 
									
										
										
										
											2020-11-20 11:19:28 -06:00
										 |  |  |       const call = getOwn(calling.callsByConversation, conversation.id); | 
					
						
							|  |  |  |       if ( | 
					
						
							| 
									
										
										
										
											2024-02-22 13:19:50 -08:00
										 |  |  |         isGroupOrAdhocCallState(call) && | 
					
						
							| 
									
										
										
										
											2023-08-10 18:43:33 +02:00
										 |  |  |         isAnybodyElseInGroupCall(call.peekInfo, ourAci) | 
					
						
							| 
									
										
										
										
											2020-11-20 11:19:28 -06:00
										 |  |  |       ) { | 
					
						
							|  |  |  |         return OutgoingCallButtonStyle.Join; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-11-19 10:37:56 -06:00
										 |  |  |       return OutgoingCallButtonStyle.JustVideo; | 
					
						
							| 
									
										
										
										
											2020-11-20 11:19:28 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-19 10:37:56 -06:00
										 |  |  |     default: | 
					
						
							|  |  |  |       throw missingCaseError(conversationCallMode); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  | export function SmartConversationHeader({ id }: OwnProps): JSX.Element { | 
					
						
							|  |  |  |   const conversationSelector = useSelector(getConversationSelector); | 
					
						
							|  |  |  |   const conversation = conversationSelector(id); | 
					
						
							| 
									
										
										
										
											2020-10-30 12:52:21 -05:00
										 |  |  |   if (!conversation) { | 
					
						
							|  |  |  |     throw new Error('Could not find conversation'); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-06-29 11:40:00 -07:00
										 |  |  |   const isAdmin = Boolean(conversation.areWeAdmin); | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |   const hasStoriesSelector = useSelector(getHasStoriesSelector); | 
					
						
							|  |  |  |   const hasStories = hasStoriesSelector(id); | 
					
						
							| 
									
										
										
										
											2020-10-30 12:52:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |   const badgeSelector = useSelector(getPreferredBadgeSelector); | 
					
						
							|  |  |  |   const badge = badgeSelector(conversation.badges); | 
					
						
							|  |  |  |   const i18n = useSelector(getIntl); | 
					
						
							| 
									
										
										
										
											2023-07-26 18:23:32 -04:00
										 |  |  |   const hasPanelShowing = useSelector<StateType, boolean>(getHasPanelOpen); | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |   const outgoingCallButtonStyle = useSelector< | 
					
						
							|  |  |  |     StateType, | 
					
						
							|  |  |  |     OutgoingCallButtonStyle | 
					
						
							|  |  |  |   >(state => getOutgoingCallButtonStyle(conversation, state)); | 
					
						
							|  |  |  |   const theme = useSelector(getTheme); | 
					
						
							| 
									
										
										
										
											2020-10-30 12:52:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |   const { | 
					
						
							|  |  |  |     destroyMessages, | 
					
						
							| 
									
										
										
										
											2023-06-29 11:40:00 -07:00
										 |  |  |     leaveGroup, | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |     onArchive, | 
					
						
							|  |  |  |     onMarkUnread, | 
					
						
							|  |  |  |     onMoveToInbox, | 
					
						
							|  |  |  |     popPanelForConversation, | 
					
						
							|  |  |  |     pushPanelForConversation, | 
					
						
							|  |  |  |     setDisappearingMessages, | 
					
						
							|  |  |  |     setMuteExpiration, | 
					
						
							|  |  |  |     setPinned, | 
					
						
							|  |  |  |     toggleSelectMode, | 
					
						
							| 
									
										
										
										
											2024-03-12 09:29:31 -07:00
										 |  |  |     acceptConversation, | 
					
						
							|  |  |  |     blockAndReportSpam, | 
					
						
							|  |  |  |     blockConversation, | 
					
						
							|  |  |  |     reportSpam, | 
					
						
							|  |  |  |     deleteConversation, | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |   } = useConversationsActions(); | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     onOutgoingAudioCallInConversation, | 
					
						
							|  |  |  |     onOutgoingVideoCallInConversation, | 
					
						
							|  |  |  |   } = useCallingActions(); | 
					
						
							|  |  |  |   const { searchInConversation } = useSearchActions(); | 
					
						
							|  |  |  |   const { viewUserStories } = useStoriesActions(); | 
					
						
							| 
									
										
										
										
											2020-10-30 12:52:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |   const conversationByServiceIdSelector = useSelector( | 
					
						
							|  |  |  |     getConversationByServiceIdSelector | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2023-06-29 11:40:00 -07:00
										 |  |  |   const groupMemberships = getGroupMemberships( | 
					
						
							|  |  |  |     conversation, | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |     conversationByServiceIdSelector | 
					
						
							| 
									
										
										
										
											2023-06-29 11:40:00 -07:00
										 |  |  |   ); | 
					
						
							|  |  |  |   const cannotLeaveBecauseYouAreLastAdmin = | 
					
						
							|  |  |  |     getCannotLeaveBecauseYouAreLastAdmin(groupMemberships.memberships, isAdmin); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-04 12:15:46 -08:00
										 |  |  |   const selectedMessageIds = useSelector(getSelectedMessageIds); | 
					
						
							|  |  |  |   const isSelectMode = selectedMessageIds != null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-12 09:29:31 -07:00
										 |  |  |   const addedBy = useMemo(() => { | 
					
						
							|  |  |  |     if (conversation.type === 'group') { | 
					
						
							|  |  |  |       return getAddedByForOurPendingInvitation(conversation); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   }, [conversation]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const addedByName = useContactNameData(addedBy); | 
					
						
							|  |  |  |   const conversationName = useContactNameData(conversation); | 
					
						
							|  |  |  |   strictAssert(conversationName, 'conversationName is required'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <ConversationHeader | 
					
						
							|  |  |  |       {...pick(conversation, [ | 
					
						
							|  |  |  |         'acceptedMessageRequest', | 
					
						
							|  |  |  |         'announcementsOnly', | 
					
						
							|  |  |  |         'areWeAdmin', | 
					
						
							|  |  |  |         'avatarPath', | 
					
						
							|  |  |  |         'canChangeTimer', | 
					
						
							|  |  |  |         'color', | 
					
						
							|  |  |  |         'expireTimer', | 
					
						
							|  |  |  |         'groupVersion', | 
					
						
							|  |  |  |         'isArchived', | 
					
						
							|  |  |  |         'isMe', | 
					
						
							|  |  |  |         'isPinned', | 
					
						
							|  |  |  |         'isVerified', | 
					
						
							|  |  |  |         'left', | 
					
						
							|  |  |  |         'markedUnread', | 
					
						
							|  |  |  |         'muteExpiresAt', | 
					
						
							|  |  |  |         'name', | 
					
						
							|  |  |  |         'phoneNumber', | 
					
						
							|  |  |  |         'profileName', | 
					
						
							|  |  |  |         'sharedGroupNames', | 
					
						
							|  |  |  |         'title', | 
					
						
							|  |  |  |         'type', | 
					
						
							|  |  |  |         'unblurredAvatarPath', | 
					
						
							|  |  |  |       ])} | 
					
						
							|  |  |  |       badge={badge} | 
					
						
							| 
									
										
										
										
											2023-06-29 11:40:00 -07:00
										 |  |  |       cannotLeaveBecauseYouAreLastAdmin={cannotLeaveBecauseYouAreLastAdmin} | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |       destroyMessages={destroyMessages} | 
					
						
							| 
									
										
										
										
											2023-07-10 18:44:32 -04:00
										 |  |  |       hasPanelShowing={hasPanelShowing} | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |       hasStories={hasStories} | 
					
						
							|  |  |  |       i18n={i18n} | 
					
						
							|  |  |  |       id={id} | 
					
						
							|  |  |  |       isMissingMandatoryProfileSharing={isMissingRequiredProfileSharing( | 
					
						
							|  |  |  |         conversation | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  |       isSignalConversation={isSignalConversation(conversation)} | 
					
						
							|  |  |  |       isSMSOnly={isConversationSMSOnly(conversation)} | 
					
						
							| 
									
										
										
										
											2023-06-29 11:40:00 -07:00
										 |  |  |       leaveGroup={leaveGroup} | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |       onArchive={onArchive} | 
					
						
							|  |  |  |       onMarkUnread={onMarkUnread} | 
					
						
							|  |  |  |       onMoveToInbox={onMoveToInbox} | 
					
						
							|  |  |  |       onOutgoingAudioCallInConversation={onOutgoingAudioCallInConversation} | 
					
						
							|  |  |  |       onOutgoingVideoCallInConversation={onOutgoingVideoCallInConversation} | 
					
						
							|  |  |  |       outgoingCallButtonStyle={outgoingCallButtonStyle} | 
					
						
							|  |  |  |       popPanelForConversation={popPanelForConversation} | 
					
						
							|  |  |  |       pushPanelForConversation={pushPanelForConversation} | 
					
						
							|  |  |  |       searchInConversation={searchInConversation} | 
					
						
							|  |  |  |       setDisappearingMessages={setDisappearingMessages} | 
					
						
							|  |  |  |       setMuteExpiration={setMuteExpiration} | 
					
						
							|  |  |  |       setPinned={setPinned} | 
					
						
							|  |  |  |       theme={theme} | 
					
						
							| 
									
										
										
										
											2024-01-04 12:15:46 -08:00
										 |  |  |       isSelectMode={isSelectMode} | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |       toggleSelectMode={toggleSelectMode} | 
					
						
							|  |  |  |       viewUserStories={viewUserStories} | 
					
						
							| 
									
										
										
										
											2024-03-12 09:29:31 -07:00
										 |  |  |       // MessageRequestActionsConfirmation
 | 
					
						
							|  |  |  |       addedByName={addedByName} | 
					
						
							|  |  |  |       conversationId={id} | 
					
						
							|  |  |  |       conversationType={conversation.type} | 
					
						
							|  |  |  |       conversationName={conversationName} | 
					
						
							|  |  |  |       isBlocked={conversation.isBlocked ?? false} | 
					
						
							|  |  |  |       isReported={conversation.isReported ?? false} | 
					
						
							|  |  |  |       acceptConversation={acceptConversation} | 
					
						
							|  |  |  |       blockAndReportSpam={blockAndReportSpam} | 
					
						
							|  |  |  |       blockConversation={blockConversation} | 
					
						
							|  |  |  |       reportSpam={reportSpam} | 
					
						
							|  |  |  |       deleteConversation={deleteConversation} | 
					
						
							| 
									
										
										
										
											2023-06-27 14:38:20 -04:00
										 |  |  |     /> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } |