2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-01-29 21:19:24 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-04-05 00:38:22 +00:00
|
|
|
import React from 'react';
|
2021-01-29 21:19:24 +00:00
|
|
|
import { connect } from 'react-redux';
|
2022-09-26 16:24:52 +00:00
|
|
|
import { sortBy } from 'lodash';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../reducer';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { mapDispatchToProps } from '../actions';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateProps } from '../../components/conversation/conversation-details/ConversationDetails';
|
|
|
|
import { ConversationDetails } from '../../components/conversation/conversation-details/ConversationDetails';
|
2021-03-11 21:29:31 +00:00
|
|
|
import {
|
2021-04-29 18:32:38 +00:00
|
|
|
getConversationByIdSelector,
|
2023-08-16 20:54:39 +00:00
|
|
|
getConversationByServiceIdSelector,
|
2022-09-26 16:24:52 +00:00
|
|
|
getAllComposableConversations,
|
2021-03-11 21:29:31 +00:00
|
|
|
} from '../selectors/conversations';
|
2021-05-13 14:47:30 +00:00
|
|
|
import { getGroupMemberships } from '../../util/getGroupMemberships';
|
2022-02-16 18:33:52 +00:00
|
|
|
import { getActiveCallState } from '../selectors/calling';
|
2021-11-30 16:29:57 +00:00
|
|
|
import { getAreWeASubscriber } from '../selectors/items';
|
2021-11-02 23:01:13 +00:00
|
|
|
import { getIntl, getTheme } from '../selectors/user';
|
|
|
|
import {
|
|
|
|
getBadgesSelector,
|
|
|
|
getPreferredBadgeSelector,
|
|
|
|
} from '../selectors/badges';
|
2022-09-15 19:17:15 +00:00
|
|
|
import { assertDev } from '../../util/assert';
|
2021-08-17 14:10:27 +00:00
|
|
|
import { SignalService as Proto } from '../../protobuf';
|
2021-12-04 02:10:03 +00:00
|
|
|
import { getConversationColorAttributes } from '../../util/getConversationColorAttributes';
|
2022-04-05 00:38:22 +00:00
|
|
|
import type { SmartChooseGroupMembersModalPropsType } from './ChooseGroupMembersModal';
|
|
|
|
import { SmartChooseGroupMembersModal } from './ChooseGroupMembersModal';
|
|
|
|
import type { SmartConfirmAdditionsModalPropsType } from './ConfirmAdditionsModal';
|
|
|
|
import { SmartConfirmAdditionsModal } from './ConfirmAdditionsModal';
|
2022-10-24 20:46:36 +00:00
|
|
|
import {
|
|
|
|
getGroupSizeRecommendedLimit,
|
|
|
|
getGroupSizeHardLimit,
|
|
|
|
} from '../../groups/limits';
|
2023-08-09 00:53:06 +00:00
|
|
|
import type { CallHistoryGroup } from '../../types/CallDisposition';
|
|
|
|
import { getSelectedNavTab } from '../selectors/nav';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
export type SmartConversationDetailsProps = {
|
|
|
|
conversationId: string;
|
2023-08-09 00:53:06 +00:00
|
|
|
callHistoryGroup?: CallHistoryGroup | null;
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
|
|
|
|
2021-08-17 14:10:27 +00:00
|
|
|
const ACCESS_ENUM = Proto.AccessControl.AccessRequired;
|
|
|
|
|
2022-04-05 00:38:22 +00:00
|
|
|
const renderChooseGroupMembersModal = (
|
|
|
|
props: SmartChooseGroupMembersModalPropsType
|
|
|
|
) => {
|
|
|
|
return <SmartChooseGroupMembersModal {...props} />;
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderConfirmAdditionsModal = (
|
|
|
|
props: SmartConfirmAdditionsModalPropsType
|
|
|
|
) => {
|
|
|
|
return <SmartConfirmAdditionsModal {...props} />;
|
|
|
|
};
|
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
const mapStateToProps = (
|
|
|
|
state: StateType,
|
|
|
|
props: SmartConversationDetailsProps
|
|
|
|
): StateProps => {
|
2021-04-29 18:32:38 +00:00
|
|
|
const conversationSelector = getConversationByIdSelector(state);
|
|
|
|
const conversation = conversationSelector(props.conversationId);
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2021-04-29 18:32:38 +00:00
|
|
|
conversation,
|
|
|
|
'<SmartConversationDetails> expected a conversation to be found'
|
|
|
|
);
|
|
|
|
|
2021-08-17 14:10:27 +00:00
|
|
|
const canEditGroupInfo = Boolean(conversation.canEditGroupInfo);
|
2022-09-26 16:24:52 +00:00
|
|
|
const canAddNewMembers = Boolean(conversation.canAddNewMembers);
|
2021-08-17 14:10:27 +00:00
|
|
|
const isAdmin = Boolean(conversation.areWeAdmin);
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2021-08-17 14:10:27 +00:00
|
|
|
const hasGroupLink =
|
|
|
|
Boolean(conversation.groupLink) &&
|
|
|
|
conversation.accessControlAddFromInviteLink !== ACCESS_ENUM.UNSATISFIABLE;
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const conversationByServiceIdSelector =
|
|
|
|
getConversationByServiceIdSelector(state);
|
2021-11-02 23:01:13 +00:00
|
|
|
const groupMemberships = getGroupMemberships(
|
|
|
|
conversation,
|
2023-08-16 20:54:39 +00:00
|
|
|
conversationByServiceIdSelector
|
2021-11-02 23:01:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const badges = getBadgesSelector(state)(conversation.badges);
|
|
|
|
|
2022-09-26 16:24:52 +00:00
|
|
|
const groupsInCommon =
|
|
|
|
conversation.type === 'direct'
|
|
|
|
? getAllComposableConversations(state).filter(
|
|
|
|
c =>
|
|
|
|
c.type === 'group' &&
|
|
|
|
(c.memberships ?? []).some(
|
2023-08-16 20:54:39 +00:00
|
|
|
member => member.aci === conversation.serviceId
|
2022-09-26 16:24:52 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
: [];
|
|
|
|
|
|
|
|
const groupsInCommonSorted = sortBy(groupsInCommon, 'title');
|
|
|
|
|
2022-10-24 20:46:36 +00:00
|
|
|
const maxGroupSize = getGroupSizeHardLimit(1001);
|
|
|
|
const maxRecommendedGroupSize = getGroupSizeRecommendedLimit(151);
|
2021-01-29 21:19:24 +00:00
|
|
|
return {
|
|
|
|
...props,
|
2023-08-09 00:53:06 +00:00
|
|
|
|
2021-11-30 16:29:57 +00:00
|
|
|
areWeASubscriber: getAreWeASubscriber(state),
|
2021-11-02 23:01:13 +00:00
|
|
|
badges,
|
2021-01-29 21:19:24 +00:00
|
|
|
canEditGroupInfo,
|
2022-09-26 16:24:52 +00:00
|
|
|
canAddNewMembers,
|
2021-12-04 02:10:03 +00:00
|
|
|
conversation: {
|
|
|
|
...conversation,
|
|
|
|
...getConversationColorAttributes(conversation),
|
|
|
|
},
|
2021-11-17 21:11:21 +00:00
|
|
|
getPreferredBadge: getPreferredBadgeSelector(state),
|
2022-02-16 18:33:52 +00:00
|
|
|
hasActiveCall: Boolean(getActiveCallState(state)),
|
2021-01-29 21:19:24 +00:00
|
|
|
i18n: getIntl(state),
|
|
|
|
isAdmin,
|
2021-11-02 23:01:13 +00:00
|
|
|
...groupMemberships,
|
2022-10-24 20:46:36 +00:00
|
|
|
maxGroupSize,
|
|
|
|
maxRecommendedGroupSize,
|
2021-08-06 00:17:05 +00:00
|
|
|
userAvatarData: conversation.avatars || [],
|
2021-08-17 14:10:27 +00:00
|
|
|
hasGroupLink,
|
2022-09-26 16:24:52 +00:00
|
|
|
groupsInCommon: groupsInCommonSorted,
|
2021-10-20 23:46:41 +00:00
|
|
|
isGroup: conversation.type === 'group',
|
2023-08-09 00:53:06 +00:00
|
|
|
selectedNavTab: getSelectedNavTab(state),
|
2021-11-02 23:01:13 +00:00
|
|
|
theme: getTheme(state),
|
2022-04-05 00:38:22 +00:00
|
|
|
renderChooseGroupMembersModal,
|
|
|
|
renderConfirmAdditionsModal,
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
export const SmartConversationDetails = smart(ConversationDetails);
|