Signal-Desktop/ts/state/smart/ConversationHeader.tsx

124 lines
3.7 KiB
TypeScript
Raw Normal View History

// 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';
import {
ConversationHeader,
OutgoingCallButtonStyle,
} from '../../components/conversation/ConversationHeader';
2021-11-02 23:01:13 +00:00
import { getPreferredBadgeSelector } from '../selectors/badges';
import {
getConversationSelector,
isMissingRequiredProfileSharing,
} from '../selectors/conversations';
import type { StateType } from '../reducer';
2020-11-13 19:57:55 +00:00
import { CallMode } from '../../types/Calling';
import type { ConversationType } from '../ducks/conversations';
import { getConversationCallMode } from '../ducks/conversations';
2020-11-20 17:19:28 +00:00
import { getActiveCall, isAnybodyElseInGroupCall } from '../ducks/calling';
2021-11-02 23:01:13 +00:00
import { getUserUuid, getIntl, getTheme } from '../selectors/user';
2020-11-20 17:19:28 +00:00
import { getOwn } from '../../util/getOwn';
import { missingCaseError } from '../../util/missingCaseError';
import { isConversationSMSOnly } from '../../util/isConversationSMSOnly';
2020-10-30 17:52:21 +00:00
export type OwnProps = {
2020-10-30 17:52:21 +00:00
id: string;
2021-10-05 16:47:06 +00:00
onArchive: () => void;
2020-10-30 17:52:21 +00:00
onDeleteMessages: () => void;
onGoBack: () => void;
2021-10-05 16:47:06 +00:00
onMarkUnread: () => void;
onMoveToInbox: () => void;
2020-10-30 17:52:21 +00:00
onOutgoingAudioCallInConversation: () => void;
onOutgoingVideoCallInConversation: () => void;
onSearchInConversation: () => void;
onSetDisappearingMessages: (seconds: number) => void;
onSetMuteNotifications: (seconds: number) => void;
onSetPin: (value: boolean) => void;
onShowAllMedia: () => void;
2021-10-05 16:47:06 +00:00
onShowConversationDetails: () => void;
2020-10-30 17:52:21 +00:00
onShowGroupMembers: () => void;
};
2020-10-30 17:52:21 +00:00
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: {
const call = getOwn(calling.callsByConversation, conversation.id);
if (
call?.callMode === CallMode.Group &&
isAnybodyElseInGroupCall(call.peekInfo, getUserUuid(state))
2020-11-20 17:19:28 +00:00
) {
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 { 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',
2021-07-20 20:18:35 +00:00
'announcementsOnly',
'areWeAdmin',
2020-10-30 17:52:21 +00:00
'avatarPath',
'canChangeTimer',
'color',
'expireTimer',
2021-07-20 20:18:35 +00:00
'groupVersion',
2020-10-30 17:52:21 +00:00
'isArchived',
'isMe',
'isPinned',
'isVerified',
'left',
'markedUnread',
'muteExpiresAt',
'name',
'phoneNumber',
'profileName',
2021-07-20 20:18:35 +00:00
'sharedGroupNames',
2020-10-30 17:52:21 +00:00
'title',
'type',
'unblurredAvatarPath',
2020-10-30 17:52:21 +00:00
]),
2021-11-02 23:01:13 +00:00
badge: getPreferredBadgeSelector(state)(conversation.badges),
conversationTitle: state.conversations.selectedConversationTitle,
isMissingMandatoryProfileSharing: isMissingRequiredProfileSharing(
conversation
),
isSMSOnly: isConversationSMSOnly(conversation),
2020-10-30 17:52:21 +00:00
i18n: getIntl(state),
showBackButton: state.conversations.selectedConversationPanelDepth > 0,
outgoingCallButtonStyle: getOutgoingCallButtonStyle(conversation, state),
2021-11-02 23:01:13 +00:00
theme: getTheme(state),
2020-10-30 17:52:21 +00:00
};
};
const smart = connect(mapStateToProps, {});
export const SmartConversationHeader = smart(ConversationHeader);