2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-03-19 13:46:09 +00:00
|
|
|
import React, { memo, useCallback, useMemo } from 'react';
|
2023-06-27 18:38:20 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
2024-03-19 13:46:09 +00:00
|
|
|
import { useContactNameData } from '../../components/conversation/ContactName';
|
2020-11-19 16:37:56 +00:00
|
|
|
import {
|
|
|
|
ConversationHeader,
|
|
|
|
OutgoingCallButtonStyle,
|
|
|
|
} from '../../components/conversation/ConversationHeader';
|
2024-03-19 13:46:09 +00:00
|
|
|
import { getCannotLeaveBecauseYouAreLastAdmin } from '../../components/conversation/conversation-details/ConversationDetails';
|
|
|
|
import { useMinimalConversation } from '../../hooks/useMinimalConversation';
|
2024-08-06 19:29:13 +00:00
|
|
|
import { CallMode } from '../../types/CallDisposition';
|
2024-03-19 13:46:09 +00:00
|
|
|
import { PanelType } from '../../types/Panels';
|
|
|
|
import { StoryViewModeType } from '../../types/Stories';
|
|
|
|
import { strictAssert } from '../../util/assert';
|
|
|
|
import { getAddedByForOurPendingInvitation } from '../../util/getAddedByForOurPendingInvitation';
|
|
|
|
import { getGroupMemberships } from '../../util/getGroupMemberships';
|
|
|
|
import { isConversationSMSOnly } from '../../util/isConversationSMSOnly';
|
|
|
|
import { isGroupOrAdhocCallState } from '../../util/isGroupOrAdhocCall';
|
|
|
|
import { isSignalConversation } from '../../util/isSignalConversation';
|
|
|
|
import { missingCaseError } from '../../util/missingCaseError';
|
2024-03-15 14:38:26 +00:00
|
|
|
import { useCallingActions } from '../ducks/calling';
|
2023-07-18 23:57:38 +00:00
|
|
|
import { isAnybodyElseInGroupCall } from '../ducks/callingHelpers';
|
2024-03-19 13:46:09 +00:00
|
|
|
import type { ConversationType } from '../ducks/conversations';
|
2023-06-27 18:38:20 +00:00
|
|
|
import {
|
|
|
|
getConversationCallMode,
|
|
|
|
useConversationsActions,
|
|
|
|
} from '../ducks/conversations';
|
|
|
|
import { useSearchActions } from '../ducks/search';
|
|
|
|
import { useStoriesActions } from '../ducks/stories';
|
2024-03-19 13:46:09 +00:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2024-03-15 14:38:26 +00:00
|
|
|
import { getActiveCallState, getCallSelector } from '../selectors/calling';
|
2024-03-19 13:46:09 +00:00
|
|
|
import {
|
|
|
|
getConversationByServiceIdSelector,
|
|
|
|
getConversationSelector,
|
|
|
|
getHasPanelOpen,
|
|
|
|
isMissingRequiredProfileSharing as getIsMissingRequiredProfileSharing,
|
|
|
|
getSelectedMessageIds,
|
|
|
|
} from '../selectors/conversations';
|
|
|
|
import { getHasStoriesSelector } from '../selectors/stories2';
|
|
|
|
import { getIntl, getTheme, getUserACI } from '../selectors/user';
|
2024-05-28 15:56:00 +00:00
|
|
|
import { useItemsActions } from '../ducks/items';
|
2024-06-17 19:24:39 +00:00
|
|
|
import { getLocalDeleteWarningShown } from '../selectors/items';
|
|
|
|
import { getDeleteSyncSendEnabled } from '../selectors/items-extra';
|
2020-10-30 17:52:21 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type OwnProps = {
|
2020-10-30 17:52:21 +00:00
|
|
|
id: string;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-10-30 17:52:21 +00:00
|
|
|
|
2024-03-15 14:38:26 +00:00
|
|
|
const useOutgoingCallButtonStyle = (
|
|
|
|
conversation: ConversationType
|
2020-11-19 16:37:56 +00:00
|
|
|
): OutgoingCallButtonStyle => {
|
2024-03-15 14:38:26 +00:00
|
|
|
const ourAci = useSelector(getUserACI);
|
|
|
|
const activeCall = useSelector(getActiveCallState);
|
|
|
|
const callSelector = useSelector(getCallSelector);
|
|
|
|
strictAssert(ourAci, 'useOutgoingCallButtonStyle missing our uuid');
|
2020-11-20 17:19:28 +00:00
|
|
|
|
2024-08-26 20:48:41 +00:00
|
|
|
if (activeCall?.conversationId === conversation.id) {
|
2020-11-19 16:37:56 +00:00
|
|
|
return OutgoingCallButtonStyle.None;
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversationCallMode = getConversationCallMode(conversation);
|
|
|
|
switch (conversationCallMode) {
|
2023-08-17 00:11:09 +00:00
|
|
|
case null:
|
2020-11-19 16:37:56 +00:00
|
|
|
return OutgoingCallButtonStyle.None;
|
|
|
|
case CallMode.Direct:
|
|
|
|
return OutgoingCallButtonStyle.Both;
|
2024-02-22 21:19:50 +00:00
|
|
|
case CallMode.Group:
|
|
|
|
case CallMode.Adhoc: {
|
2024-03-15 14:38:26 +00:00
|
|
|
const call = callSelector(conversation.id);
|
2020-11-20 17:19:28 +00:00
|
|
|
if (
|
2024-02-22 21:19:50 +00:00
|
|
|
isGroupOrAdhocCallState(call) &&
|
2023-08-10 16:43:33 +00:00
|
|
|
isAnybodyElseInGroupCall(call.peekInfo, ourAci)
|
2020-11-20 17:19:28 +00:00
|
|
|
) {
|
|
|
|
return OutgoingCallButtonStyle.Join;
|
|
|
|
}
|
2020-11-19 16:37:56 +00:00
|
|
|
return OutgoingCallButtonStyle.JustVideo;
|
2020-11-20 17:19:28 +00:00
|
|
|
}
|
2020-11-19 16:37:56 +00:00
|
|
|
default:
|
|
|
|
throw missingCaseError(conversationCallMode);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartConversationHeader = memo(function SmartConversationHeader({
|
|
|
|
id,
|
|
|
|
}: OwnProps) {
|
2023-06-27 18:38:20 +00:00
|
|
|
const conversationSelector = useSelector(getConversationSelector);
|
|
|
|
const conversation = conversationSelector(id);
|
2020-10-30 17:52:21 +00:00
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('Could not find conversation');
|
|
|
|
}
|
2023-06-29 18:40:00 +00:00
|
|
|
const isAdmin = Boolean(conversation.areWeAdmin);
|
2023-06-27 18:38:20 +00:00
|
|
|
const hasStoriesSelector = useSelector(getHasStoriesSelector);
|
|
|
|
const hasStories = hasStoriesSelector(id);
|
2020-10-30 17:52:21 +00:00
|
|
|
|
2023-06-27 18:38:20 +00:00
|
|
|
const badgeSelector = useSelector(getPreferredBadgeSelector);
|
|
|
|
const badge = badgeSelector(conversation.badges);
|
|
|
|
const i18n = useSelector(getIntl);
|
2024-03-13 20:44:13 +00:00
|
|
|
const hasPanelShowing = useSelector(getHasPanelOpen);
|
2024-03-15 14:38:26 +00:00
|
|
|
const outgoingCallButtonStyle = useOutgoingCallButtonStyle(conversation);
|
2023-06-27 18:38:20 +00:00
|
|
|
const theme = useSelector(getTheme);
|
2024-08-26 20:48:41 +00:00
|
|
|
const activeCall = useSelector(getActiveCallState);
|
|
|
|
const hasActiveCall = Boolean(activeCall);
|
2020-10-30 17:52:21 +00:00
|
|
|
|
2023-06-27 18:38:20 +00:00
|
|
|
const {
|
|
|
|
destroyMessages,
|
2023-06-29 18:40:00 +00:00
|
|
|
leaveGroup,
|
2023-06-27 18:38:20 +00:00
|
|
|
onArchive,
|
|
|
|
onMarkUnread,
|
|
|
|
onMoveToInbox,
|
|
|
|
pushPanelForConversation,
|
|
|
|
setDisappearingMessages,
|
|
|
|
setMuteExpiration,
|
|
|
|
setPinned,
|
|
|
|
toggleSelectMode,
|
2024-03-12 16:29:31 +00:00
|
|
|
acceptConversation,
|
|
|
|
blockAndReportSpam,
|
|
|
|
blockConversation,
|
|
|
|
reportSpam,
|
|
|
|
deleteConversation,
|
2023-06-27 18:38:20 +00:00
|
|
|
} = useConversationsActions();
|
|
|
|
const {
|
|
|
|
onOutgoingAudioCallInConversation,
|
|
|
|
onOutgoingVideoCallInConversation,
|
|
|
|
} = useCallingActions();
|
|
|
|
const { searchInConversation } = useSearchActions();
|
|
|
|
const { viewUserStories } = useStoriesActions();
|
2020-10-30 17:52:21 +00:00
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const conversationByServiceIdSelector = useSelector(
|
|
|
|
getConversationByServiceIdSelector
|
|
|
|
);
|
2023-06-29 18:40:00 +00:00
|
|
|
const groupMemberships = getGroupMemberships(
|
|
|
|
conversation,
|
2023-08-16 20:54:39 +00:00
|
|
|
conversationByServiceIdSelector
|
2023-06-29 18:40:00 +00:00
|
|
|
);
|
|
|
|
const cannotLeaveBecauseYouAreLastAdmin =
|
|
|
|
getCannotLeaveBecauseYouAreLastAdmin(groupMemberships.memberships, isAdmin);
|
|
|
|
|
2024-01-04 20:15:46 +00:00
|
|
|
const selectedMessageIds = useSelector(getSelectedMessageIds);
|
|
|
|
const isSelectMode = selectedMessageIds != null;
|
|
|
|
|
2024-03-12 16:29:31 +00: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');
|
|
|
|
|
2024-05-28 15:56:00 +00:00
|
|
|
const isDeleteSyncSendEnabled = useSelector(getDeleteSyncSendEnabled);
|
2024-03-19 13:46:09 +00:00
|
|
|
const isMissingMandatoryProfileSharing =
|
|
|
|
getIsMissingRequiredProfileSharing(conversation);
|
|
|
|
|
|
|
|
const onConversationAccept = useCallback(() => {
|
|
|
|
acceptConversation(conversation.id);
|
|
|
|
}, [acceptConversation, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationArchive = useCallback(() => {
|
|
|
|
onArchive(conversation.id);
|
|
|
|
}, [onArchive, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationBlock = useCallback(() => {
|
|
|
|
blockConversation(conversation.id);
|
|
|
|
}, [blockConversation, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationBlockAndReportSpam = useCallback(() => {
|
|
|
|
blockAndReportSpam(conversation.id);
|
|
|
|
}, [blockAndReportSpam, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationDelete = useCallback(() => {
|
|
|
|
deleteConversation(conversation.id);
|
|
|
|
}, [deleteConversation, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationDeleteMessages = useCallback(() => {
|
|
|
|
destroyMessages(conversation.id);
|
|
|
|
}, [destroyMessages, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationDisappearingMessagesChange = useCallback(
|
|
|
|
seconds => {
|
|
|
|
setDisappearingMessages(conversation.id, seconds);
|
|
|
|
},
|
|
|
|
[setDisappearingMessages, conversation.id]
|
|
|
|
);
|
|
|
|
|
|
|
|
const onConversationLeaveGroup = useCallback(() => {
|
|
|
|
leaveGroup(conversation.id);
|
|
|
|
}, [leaveGroup, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationMarkUnread = useCallback(() => {
|
|
|
|
onMarkUnread(conversation.id);
|
|
|
|
}, [onMarkUnread, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationMuteExpirationChange = useCallback(
|
|
|
|
seconds => {
|
|
|
|
setMuteExpiration(conversation.id, seconds);
|
|
|
|
},
|
|
|
|
[setMuteExpiration, conversation.id]
|
|
|
|
);
|
|
|
|
|
|
|
|
const onConversationPin = useCallback(() => {
|
|
|
|
setPinned(conversation.id, true);
|
|
|
|
}, [setPinned, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationReportSpam = useCallback(() => {
|
|
|
|
reportSpam(conversation.id);
|
|
|
|
}, [reportSpam, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationUnarchive = useCallback(() => {
|
|
|
|
onMoveToInbox(conversation.id);
|
|
|
|
}, [onMoveToInbox, conversation.id]);
|
|
|
|
|
|
|
|
const onConversationUnpin = useCallback(() => {
|
|
|
|
setPinned(conversation.id, false);
|
|
|
|
}, [setPinned, conversation.id]);
|
|
|
|
|
|
|
|
const onOutgoingAudioCall = useCallback(() => {
|
|
|
|
onOutgoingAudioCallInConversation(conversation.id);
|
|
|
|
}, [onOutgoingAudioCallInConversation, conversation.id]);
|
|
|
|
|
|
|
|
const onOutgoingVideoCall = useCallback(() => {
|
|
|
|
onOutgoingVideoCallInConversation(conversation.id);
|
|
|
|
}, [onOutgoingVideoCallInConversation, conversation.id]);
|
|
|
|
|
|
|
|
const onSearchInConversation = useCallback(() => {
|
|
|
|
searchInConversation(conversation.id);
|
|
|
|
}, [searchInConversation, conversation.id]);
|
|
|
|
|
|
|
|
const onSelectModeEnter = useCallback(() => {
|
|
|
|
toggleSelectMode(true);
|
|
|
|
}, [toggleSelectMode]);
|
|
|
|
|
|
|
|
const onShowMembers = useCallback(() => {
|
|
|
|
pushPanelForConversation({ type: PanelType.GroupV1Members });
|
|
|
|
}, [pushPanelForConversation]);
|
|
|
|
|
|
|
|
const onViewConversationDetails = useCallback(() => {
|
|
|
|
pushPanelForConversation({ type: PanelType.ConversationDetails });
|
|
|
|
}, [pushPanelForConversation]);
|
|
|
|
|
2024-09-04 21:15:30 +00:00
|
|
|
const onViewAllMedia = useCallback(() => {
|
2024-03-19 13:46:09 +00:00
|
|
|
pushPanelForConversation({ type: PanelType.AllMedia });
|
|
|
|
}, [pushPanelForConversation]);
|
|
|
|
|
|
|
|
const onViewUserStories = useCallback(() => {
|
|
|
|
viewUserStories({
|
|
|
|
conversationId: conversation.id,
|
|
|
|
storyViewMode: StoryViewModeType.User,
|
|
|
|
});
|
|
|
|
}, [viewUserStories, conversation.id]);
|
|
|
|
|
|
|
|
const minimalConversation = useMinimalConversation(conversation);
|
|
|
|
|
2024-05-28 15:56:00 +00:00
|
|
|
const localDeleteWarningShown = useSelector(getLocalDeleteWarningShown);
|
|
|
|
const { putItem } = useItemsActions();
|
|
|
|
const setLocalDeleteWarningShown = () =>
|
|
|
|
putItem('localDeleteWarningShown', true);
|
|
|
|
|
2023-06-27 18:38:20 +00:00
|
|
|
return (
|
|
|
|
<ConversationHeader
|
2024-03-19 13:46:09 +00:00
|
|
|
addedByName={addedByName}
|
2023-06-27 18:38:20 +00:00
|
|
|
badge={badge}
|
2023-06-29 18:40:00 +00:00
|
|
|
cannotLeaveBecauseYouAreLastAdmin={cannotLeaveBecauseYouAreLastAdmin}
|
2024-03-19 13:46:09 +00:00
|
|
|
conversation={minimalConversation}
|
|
|
|
conversationName={conversationName}
|
2024-08-26 20:48:41 +00:00
|
|
|
hasActiveCall={hasActiveCall}
|
2023-07-10 22:44:32 +00:00
|
|
|
hasPanelShowing={hasPanelShowing}
|
2023-06-27 18:38:20 +00:00
|
|
|
hasStories={hasStories}
|
|
|
|
i18n={i18n}
|
2024-05-28 15:56:00 +00:00
|
|
|
localDeleteWarningShown={localDeleteWarningShown}
|
|
|
|
isDeleteSyncSendEnabled={isDeleteSyncSendEnabled}
|
2024-03-19 13:46:09 +00:00
|
|
|
isMissingMandatoryProfileSharing={isMissingMandatoryProfileSharing}
|
|
|
|
isSelectMode={isSelectMode}
|
2023-06-27 18:38:20 +00:00
|
|
|
isSignalConversation={isSignalConversation(conversation)}
|
|
|
|
isSMSOnly={isConversationSMSOnly(conversation)}
|
2024-03-19 13:46:09 +00:00
|
|
|
onConversationAccept={onConversationAccept}
|
|
|
|
onConversationArchive={onConversationArchive}
|
|
|
|
onConversationBlock={onConversationBlock}
|
|
|
|
onConversationBlockAndReportSpam={onConversationBlockAndReportSpam}
|
|
|
|
onConversationDelete={onConversationDelete}
|
|
|
|
onConversationDeleteMessages={onConversationDeleteMessages}
|
|
|
|
onConversationDisappearingMessagesChange={
|
|
|
|
onConversationDisappearingMessagesChange
|
|
|
|
}
|
|
|
|
onConversationLeaveGroup={onConversationLeaveGroup}
|
|
|
|
onConversationMarkUnread={onConversationMarkUnread}
|
|
|
|
onConversationMuteExpirationChange={onConversationMuteExpirationChange}
|
|
|
|
onConversationPin={onConversationPin}
|
|
|
|
onConversationReportSpam={onConversationReportSpam}
|
|
|
|
onConversationUnarchive={onConversationUnarchive}
|
|
|
|
onConversationUnpin={onConversationUnpin}
|
|
|
|
onOutgoingAudioCall={onOutgoingAudioCall}
|
|
|
|
onOutgoingVideoCall={onOutgoingVideoCall}
|
|
|
|
onSearchInConversation={onSearchInConversation}
|
|
|
|
onSelectModeEnter={onSelectModeEnter}
|
|
|
|
onShowMembers={onShowMembers}
|
|
|
|
onViewConversationDetails={onViewConversationDetails}
|
2024-09-04 21:15:30 +00:00
|
|
|
onViewAllMedia={onViewAllMedia}
|
2024-03-19 13:46:09 +00:00
|
|
|
onViewUserStories={onViewUserStories}
|
2023-06-27 18:38:20 +00:00
|
|
|
outgoingCallButtonStyle={outgoingCallButtonStyle}
|
2024-05-28 15:56:00 +00:00
|
|
|
setLocalDeleteWarningShown={setLocalDeleteWarningShown}
|
2024-03-19 13:46:09 +00:00
|
|
|
sharedGroupNames={conversation.sharedGroupNames}
|
2023-06-27 18:38:20 +00:00
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
);
|
2024-03-13 20:44:13 +00:00
|
|
|
});
|