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
|
|
|
|
|
2020-10-30 17:52:21 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { pick } from 'lodash';
|
2022-07-22 00:44:35 +00:00
|
|
|
import type { ConversationType } from '../ducks/conversations';
|
|
|
|
import type { StateType } from '../reducer';
|
2020-11-19 16:37:56 +00:00
|
|
|
import {
|
|
|
|
ConversationHeader,
|
|
|
|
OutgoingCallButtonStyle,
|
|
|
|
} from '../../components/conversation/ConversationHeader';
|
2021-11-02 23:01:13 +00:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2021-06-17 17:15:10 +00:00
|
|
|
import {
|
|
|
|
getConversationSelector,
|
2022-12-14 18:41:04 +00:00
|
|
|
getConversationTitle,
|
2021-06-17 17:15:10 +00:00
|
|
|
isMissingRequiredProfileSharing,
|
|
|
|
} from '../selectors/conversations';
|
2020-11-13 19:57:55 +00:00
|
|
|
import { CallMode } from '../../types/Calling';
|
2020-11-20 17:19:28 +00:00
|
|
|
import { getActiveCall, isAnybodyElseInGroupCall } from '../ducks/calling';
|
2022-07-22 00:44:35 +00:00
|
|
|
import { getConversationCallMode } from '../ducks/conversations';
|
|
|
|
import { getHasStoriesSelector } from '../selectors/stories';
|
2020-11-20 17:19:28 +00:00
|
|
|
import { getOwn } from '../../util/getOwn';
|
2022-07-22 00:44:35 +00:00
|
|
|
import { getUserACI, getIntl, getTheme } from '../selectors/user';
|
2021-05-25 22:30:57 +00:00
|
|
|
import { isConversationSMSOnly } from '../../util/isConversationSMSOnly';
|
2022-07-22 00:44:35 +00:00
|
|
|
import { mapDispatchToProps } from '../actions';
|
|
|
|
import { missingCaseError } from '../../util/missingCaseError';
|
2022-02-23 18:48:40 +00:00
|
|
|
import { strictAssert } from '../../util/assert';
|
2022-11-09 02:38:19 +00:00
|
|
|
import { isSignalConversation } from '../../util/isSignalConversation';
|
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
|
|
|
|
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;
|
2022-07-08 20:46:25 +00:00
|
|
|
const ourACI = getUserACI(state);
|
|
|
|
strictAssert(ourACI, 'getOutgoingCallButtonStyle missing our uuid');
|
2020-11-20 17:19:28 +00:00
|
|
|
|
|
|
|
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: {
|
|
|
|
const call = getOwn(calling.callsByConversation, conversation.id);
|
|
|
|
if (
|
|
|
|
call?.callMode === CallMode.Group &&
|
2022-07-08 20:46:25 +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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2022-07-22 00:44:35 +00:00
|
|
|
const hasStories = getHasStoriesSelector(state)(id);
|
|
|
|
|
2020-10-30 17:52:21 +00:00
|
|
|
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',
|
2021-04-30 19:40:25 +00:00
|
|
|
'unblurredAvatarPath',
|
2020-10-30 17:52:21 +00:00
|
|
|
]),
|
2021-11-02 23:01:13 +00:00
|
|
|
badge: getPreferredBadgeSelector(state)(conversation.badges),
|
2022-12-14 18:41:04 +00:00
|
|
|
conversationTitle: getConversationTitle(state),
|
2022-07-22 00:44:35 +00:00
|
|
|
hasStories,
|
2021-11-11 22:43:05 +00:00
|
|
|
isMissingMandatoryProfileSharing:
|
|
|
|
isMissingRequiredProfileSharing(conversation),
|
2021-05-25 22:30:57 +00:00
|
|
|
isSMSOnly: isConversationSMSOnly(conversation),
|
2022-11-09 02:38:19 +00:00
|
|
|
isSignalConversation: isSignalConversation(conversation),
|
2020-10-30 17:52:21 +00:00
|
|
|
i18n: getIntl(state),
|
2022-12-14 18:41:04 +00:00
|
|
|
showBackButton: state.conversations.selectedConversationPanels.length > 0,
|
2020-11-19 16:37:56 +00:00
|
|
|
outgoingCallButtonStyle: getOutgoingCallButtonStyle(conversation, state),
|
2021-11-02 23:01:13 +00:00
|
|
|
theme: getTheme(state),
|
2020-10-30 17:52:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-07-22 00:44:35 +00:00
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
2020-10-30 17:52:21 +00:00
|
|
|
|
|
|
|
export const SmartConversationHeader = smart(ConversationHeader);
|