2021-01-14 12:07:05 -06:00
|
|
|
// Copyright 2020-2021 Signal Messenger, LLC
|
2020-10-30 15:34:04 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-10-30 12:52:21 -05:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { pick } from 'lodash';
|
2020-11-19 10:37:56 -06:00
|
|
|
import {
|
|
|
|
ConversationHeader,
|
|
|
|
OutgoingCallButtonStyle,
|
|
|
|
} from '../../components/conversation/ConversationHeader';
|
2021-06-17 10:15:10 -07:00
|
|
|
import {
|
|
|
|
getConversationSelector,
|
|
|
|
isMissingRequiredProfileSharing,
|
|
|
|
} from '../selectors/conversations';
|
2020-10-30 12:52:21 -05:00
|
|
|
import { StateType } from '../reducer';
|
2020-11-13 13:57:55 -06:00
|
|
|
import { CallMode } from '../../types/Calling';
|
2020-11-19 10:37:56 -06:00
|
|
|
import {
|
|
|
|
ConversationType,
|
|
|
|
getConversationCallMode,
|
|
|
|
} from '../ducks/conversations';
|
2020-11-20 11:19:28 -06:00
|
|
|
import { getActiveCall, isAnybodyElseInGroupCall } from '../ducks/calling';
|
2021-08-18 19:14:30 -05:00
|
|
|
import { getUserUuid, getIntl } from '../selectors/user';
|
2020-11-20 11:19:28 -06:00
|
|
|
import { getOwn } from '../../util/getOwn';
|
2020-11-19 10:37:56 -06:00
|
|
|
import { missingCaseError } from '../../util/missingCaseError';
|
2021-05-25 15:30:57 -07:00
|
|
|
import { isConversationSMSOnly } from '../../util/isConversationSMSOnly';
|
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-10-05 12:47:06 -04:00
|
|
|
onArchive: () => void;
|
2020-10-30 12:52:21 -05:00
|
|
|
onDeleteMessages: () => void;
|
|
|
|
onGoBack: () => void;
|
2021-10-05 12:47:06 -04:00
|
|
|
onMarkUnread: () => void;
|
|
|
|
onMoveToInbox: () => void;
|
2020-10-30 12:52:21 -05:00
|
|
|
onOutgoingAudioCallInConversation: () => void;
|
|
|
|
onOutgoingVideoCallInConversation: () => void;
|
|
|
|
onResetSession: () => void;
|
|
|
|
onSearchInConversation: () => void;
|
|
|
|
onSetDisappearingMessages: (seconds: number) => void;
|
|
|
|
onSetMuteNotifications: (seconds: number) => void;
|
|
|
|
onSetPin: (value: boolean) => void;
|
|
|
|
onShowAllMedia: () => void;
|
2021-05-28 12:15:17 -04:00
|
|
|
onShowChatColorEditor: () => void;
|
2021-01-27 19:18:50 -05:00
|
|
|
onShowContactModal: (contactId: string) => void;
|
2021-10-05 12:47:06 -04:00
|
|
|
onShowConversationDetails: () => void;
|
2020-10-30 12:52:21 -05:00
|
|
|
onShowGroupMembers: () => void;
|
|
|
|
onShowSafetyNumber: () => void;
|
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;
|
|
|
|
|
|
|
|
if (getActiveCall(calling)) {
|
2020-11-19 10:37:56 -06:00
|
|
|
return OutgoingCallButtonStyle.None;
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversationCallMode = getConversationCallMode(conversation);
|
|
|
|
switch (conversationCallMode) {
|
|
|
|
case CallMode.None:
|
|
|
|
return OutgoingCallButtonStyle.None;
|
|
|
|
case CallMode.Direct:
|
|
|
|
return OutgoingCallButtonStyle.Both;
|
2020-11-20 11:19:28 -06:00
|
|
|
case CallMode.Group: {
|
|
|
|
const call = getOwn(calling.callsByConversation, conversation.id);
|
|
|
|
if (
|
|
|
|
call?.callMode === CallMode.Group &&
|
2021-08-18 19:14:30 -05:00
|
|
|
isAnybodyElseInGroupCall(call.peekInfo, getUserUuid(state))
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-30 12:52:21 -05:00
|
|
|
const mapStateToProps = (state: StateType, ownProps: OwnProps) => {
|
2021-02-23 14:34:28 -06:00
|
|
|
const { id } = ownProps;
|
|
|
|
|
|
|
|
const conversation = getConversationSelector(state)(id);
|
2020-10-30 12:52:21 -05:00
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('Could not find conversation');
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...pick(conversation, [
|
|
|
|
'acceptedMessageRequest',
|
2021-07-20 16:18:35 -04:00
|
|
|
'announcementsOnly',
|
|
|
|
'areWeAdmin',
|
2020-10-30 12:52:21 -05:00
|
|
|
'avatarPath',
|
|
|
|
'canChangeTimer',
|
|
|
|
'color',
|
|
|
|
'expireTimer',
|
2021-07-20 16:18:35 -04:00
|
|
|
'groupVersion',
|
2020-10-30 12:52:21 -05:00
|
|
|
'isArchived',
|
|
|
|
'isMe',
|
|
|
|
'isPinned',
|
|
|
|
'isVerified',
|
|
|
|
'left',
|
|
|
|
'markedUnread',
|
|
|
|
'muteExpiresAt',
|
|
|
|
'name',
|
|
|
|
'phoneNumber',
|
|
|
|
'profileName',
|
2021-07-20 16:18:35 -04:00
|
|
|
'sharedGroupNames',
|
2020-10-30 12:52:21 -05:00
|
|
|
'title',
|
|
|
|
'type',
|
2021-04-30 14:40:25 -05:00
|
|
|
'unblurredAvatarPath',
|
2020-10-30 12:52:21 -05:00
|
|
|
]),
|
2021-01-29 16:19:24 -05:00
|
|
|
conversationTitle: state.conversations.selectedConversationTitle,
|
2021-06-17 10:15:10 -07:00
|
|
|
isMissingMandatoryProfileSharing: isMissingRequiredProfileSharing(
|
|
|
|
conversation
|
2021-03-04 10:06:49 -08:00
|
|
|
),
|
2021-05-25 15:30:57 -07:00
|
|
|
isSMSOnly: isConversationSMSOnly(conversation),
|
2020-10-30 12:52:21 -05:00
|
|
|
i18n: getIntl(state),
|
|
|
|
showBackButton: state.conversations.selectedConversationPanelDepth > 0,
|
2020-11-19 10:37:56 -06:00
|
|
|
outgoingCallButtonStyle: getOutgoingCallButtonStyle(conversation, state),
|
2020-10-30 12:52:21 -05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, {});
|
|
|
|
|
|
|
|
export const SmartConversationHeader = smart(ConversationHeader);
|