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