2021-03-12 23:31:47 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-01-29 21:19:24 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import { StateType } from '../reducer';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { mapDispatchToProps } from '../actions';
|
2021-01-29 21:19:24 +00:00
|
|
|
import {
|
|
|
|
ConversationDetails,
|
|
|
|
StateProps,
|
|
|
|
} from '../../components/conversation/conversation-details/ConversationDetails';
|
2021-03-11 21:29:31 +00:00
|
|
|
import {
|
2021-05-04 16:17:32 +00:00
|
|
|
getCandidateContactsForNewGroup,
|
2021-04-29 18:32:38 +00:00
|
|
|
getConversationByIdSelector,
|
2021-03-11 21:29:31 +00:00
|
|
|
} from '../selectors/conversations';
|
2021-05-13 14:47:30 +00:00
|
|
|
import { getGroupMemberships } from '../../util/getGroupMemberships';
|
2021-01-29 21:19:24 +00:00
|
|
|
import { getIntl } from '../selectors/user';
|
2021-08-23 23:14:53 +00:00
|
|
|
import { MediaItemType } from '../../types/MediaItem';
|
2021-04-29 18:32:38 +00:00
|
|
|
import { assert } from '../../util/assert';
|
2021-08-17 14:10:27 +00:00
|
|
|
import { SignalService as Proto } from '../../protobuf';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
export type SmartConversationDetailsProps = {
|
2021-03-11 21:29:31 +00:00
|
|
|
addMembers: (conversationIds: ReadonlyArray<string>) => Promise<void>;
|
2021-01-29 21:19:24 +00:00
|
|
|
conversationId: string;
|
|
|
|
loadRecentMediaItems: (limit: number) => void;
|
|
|
|
setDisappearingMessages: (seconds: number) => void;
|
|
|
|
showAllMedia: () => void;
|
|
|
|
showContactModal: (conversationId: string) => void;
|
2021-05-28 16:15:17 +00:00
|
|
|
showGroupChatColorEditor: () => void;
|
2021-01-29 21:19:24 +00:00
|
|
|
showGroupLinkManagement: () => void;
|
|
|
|
showGroupV2Permissions: () => void;
|
2021-08-05 12:35:33 +00:00
|
|
|
showConversationNotificationsSettings: () => void;
|
2021-01-29 21:19:24 +00:00
|
|
|
showPendingInvites: () => void;
|
|
|
|
showLightboxForMedia: (
|
|
|
|
selectedMediaItem: MediaItemType,
|
|
|
|
media: Array<MediaItemType>
|
|
|
|
) => void;
|
2021-03-09 19:16:56 +00:00
|
|
|
updateGroupAttributes: (
|
|
|
|
_: Readonly<{
|
|
|
|
avatar?: undefined | ArrayBuffer;
|
|
|
|
title?: string;
|
|
|
|
}>
|
2021-03-12 23:31:47 +00:00
|
|
|
) => Promise<void>;
|
2021-04-28 20:27:16 +00:00
|
|
|
onBlock: () => void;
|
|
|
|
onLeave: () => void;
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
|
|
|
|
2021-08-17 14:10:27 +00:00
|
|
|
const ACCESS_ENUM = Proto.AccessControl.AccessRequired;
|
|
|
|
|
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);
|
|
|
|
assert(
|
|
|
|
conversation,
|
|
|
|
'<SmartConversationDetails> expected a conversation to be found'
|
|
|
|
);
|
|
|
|
|
2021-08-17 14:10:27 +00:00
|
|
|
const canEditGroupInfo = Boolean(conversation.canEditGroupInfo);
|
|
|
|
const isAdmin = Boolean(conversation.areWeAdmin);
|
2021-05-04 16:17:32 +00:00
|
|
|
const candidateContactsToAdd = getCandidateContactsForNewGroup(state);
|
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;
|
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
return {
|
|
|
|
...props,
|
|
|
|
canEditGroupInfo,
|
2021-03-11 21:29:31 +00:00
|
|
|
candidateContactsToAdd,
|
2021-01-29 21:19:24 +00:00
|
|
|
conversation,
|
|
|
|
i18n: getIntl(state),
|
|
|
|
isAdmin,
|
2021-05-13 14:47:30 +00:00
|
|
|
...getGroupMemberships(conversation, conversationSelector),
|
2021-08-06 00:17:05 +00:00
|
|
|
userAvatarData: conversation.avatars || [],
|
2021-08-17 14:10:27 +00:00
|
|
|
hasGroupLink,
|
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);
|