signal-desktop/ts/state/smart/ConversationHeader.tsx

114 lines
3.3 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2020-10-30 17:52:21 +00:00
import { connect } from 'react-redux';
import { pick } from 'lodash';
import {
ConversationHeader,
OutgoingCallButtonStyle,
} from '../../components/conversation/ConversationHeader';
2020-10-30 17:52:21 +00:00
import { getConversationSelector } from '../selectors/conversations';
import { StateType } from '../reducer';
2020-11-13 19:57:55 +00:00
import { CallMode } from '../../types/Calling';
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';
import { missingCaseError } from '../../util/missingCaseError';
import { isGroupCallingEnabled } from '../../util/isGroupCallingEnabled';
2020-10-30 17:52:21 +00:00
export interface OwnProps {
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;
onShowGroupMembers: () => void;
onArchive: () => void;
onMarkUnread: () => void;
onMoveToInbox: () => void;
onShowSafetyNumber: () => void;
}
const getOutgoingCallButtonStyle = (
conversation: ConversationType,
state: StateType
): OutgoingCallButtonStyle => {
2020-11-20 17:19:28 +00:00
const { calling } = state;
if (getActiveCall(calling)) {
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: {
if (!isGroupCallingEnabled()) {
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;
}
return OutgoingCallButtonStyle.JustVideo;
2020-11-20 17:19:28 +00:00
}
default:
throw missingCaseError(conversationCallMode);
}
};
2020-10-30 17:52:21 +00:00
const mapStateToProps = (state: StateType, ownProps: OwnProps) => {
const conversation = getConversationSelector(state)(ownProps.id);
if (!conversation) {
throw new Error('Could not find conversation');
}
return {
...pick(conversation, [
'acceptedMessageRequest',
'avatarPath',
'canChangeTimer',
'color',
'expireTimer',
'isArchived',
'isMe',
'isMissingMandatoryProfileSharing',
'isPinned',
'isVerified',
'left',
'markedUnread',
'muteExpiresAt',
'name',
'phoneNumber',
'profileName',
'title',
'type',
]),
i18n: getIntl(state),
showBackButton: state.conversations.selectedConversationPanelDepth > 0,
outgoingCallButtonStyle: getOutgoingCallButtonStyle(conversation, state),
2020-10-30 17:52:21 +00:00
};
};
const smart = connect(mapStateToProps, {});
export const SmartConversationHeader = smart(ConversationHeader);