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

84 lines
2.6 KiB
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// 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';
import {
ConversationDetails,
StateProps,
} from '../../components/conversation/conversation-details/ConversationDetails';
2021-03-11 21:29:31 +00:00
import {
getCandidateContactsForNewGroup,
getConversationByIdSelector,
2021-03-11 21:29:31 +00:00
} from '../selectors/conversations';
import { getGroupMemberships } from '../../util/getGroupMemberships';
import { getIntl } from '../selectors/user';
2021-08-23 23:14:53 +00:00
import { MediaItemType } from '../../types/MediaItem';
import { assert } from '../../util/assert';
import { SignalService as Proto } from '../../protobuf';
export type SmartConversationDetailsProps = {
2021-03-11 21:29:31 +00:00
addMembers: (conversationIds: ReadonlyArray<string>) => Promise<void>;
conversationId: string;
loadRecentMediaItems: (limit: number) => void;
setDisappearingMessages: (seconds: number) => void;
showAllMedia: () => void;
2021-05-28 16:15:17 +00:00
showGroupChatColorEditor: () => void;
showGroupLinkManagement: () => void;
showGroupV2Permissions: () => void;
2021-08-05 12:35:33 +00:00
showConversationNotificationsSettings: () => void;
showPendingInvites: () => void;
showLightboxForMedia: (
selectedMediaItem: MediaItemType,
media: Array<MediaItemType>
) => void;
updateGroupAttributes: (
_: Readonly<{
avatar?: undefined | ArrayBuffer;
title?: string;
}>
) => Promise<void>;
onBlock: () => void;
onLeave: () => void;
};
const ACCESS_ENUM = Proto.AccessControl.AccessRequired;
const mapStateToProps = (
state: StateType,
props: SmartConversationDetailsProps
): StateProps => {
const conversationSelector = getConversationByIdSelector(state);
const conversation = conversationSelector(props.conversationId);
assert(
conversation,
'<SmartConversationDetails> expected a conversation to be found'
);
const canEditGroupInfo = Boolean(conversation.canEditGroupInfo);
const isAdmin = Boolean(conversation.areWeAdmin);
const candidateContactsToAdd = getCandidateContactsForNewGroup(state);
const hasGroupLink =
Boolean(conversation.groupLink) &&
conversation.accessControlAddFromInviteLink !== ACCESS_ENUM.UNSATISFIABLE;
return {
...props,
canEditGroupInfo,
2021-03-11 21:29:31 +00:00
candidateContactsToAdd,
conversation,
i18n: getIntl(state),
isAdmin,
...getGroupMemberships(conversation, conversationSelector),
2021-08-06 00:17:05 +00:00
userAvatarData: conversation.avatars || [],
hasGroupLink,
};
};
2021-08-06 00:17:05 +00:00
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartConversationDetails = smart(ConversationDetails);