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

109 lines
3.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 type { StateType } from '../reducer';
2021-08-06 00:17:05 +00:00
import { mapDispatchToProps } from '../actions';
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 {
getCandidateContactsForNewGroup,
getConversationByIdSelector,
2021-10-26 22:59:08 +00:00
getConversationByUuidSelector,
2021-03-11 21:29:31 +00:00
} from '../selectors/conversations';
import { getGroupMemberships } from '../../util/getGroupMemberships';
import { getAreWeASubscriber } from '../selectors/items';
2021-11-02 23:01:13 +00:00
import { getIntl, getTheme } from '../selectors/user';
import type { MediaItemType } from '../../types/MediaItem';
2021-11-02 23:01:13 +00:00
import {
getBadgesSelector,
getPreferredBadgeSelector,
} from '../selectors/badges';
import { assert } from '../../util/assert';
import { SignalService as Proto } from '../../protobuf';
import { getConversationColorAttributes } from '../../util/getConversationColorAttributes';
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;
showChatColorEditor: () => 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<{
2021-09-24 00:49:05 +00:00
avatar?: undefined | Uint8Array;
title?: string;
}>
) => Promise<void>;
onBlock: () => void;
onLeave: () => void;
onUnblock: () => void;
setMuteExpiration: (muteExpiresAt: undefined | number) => unknown;
onOutgoingAudioCallInConversation: () => unknown;
onOutgoingVideoCallInConversation: () => unknown;
};
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;
2021-10-26 22:59:08 +00:00
const conversationByUuidSelector = getConversationByUuidSelector(state);
2021-11-02 23:01:13 +00:00
const groupMemberships = getGroupMemberships(
conversation,
conversationByUuidSelector
);
const badges = getBadgesSelector(state)(conversation.badges);
return {
...props,
areWeASubscriber: getAreWeASubscriber(state),
2021-11-02 23:01:13 +00:00
badges,
canEditGroupInfo,
2021-03-11 21:29:31 +00:00
candidateContactsToAdd,
conversation: {
...conversation,
...getConversationColorAttributes(conversation),
},
2021-11-17 21:11:21 +00:00
getPreferredBadge: getPreferredBadgeSelector(state),
i18n: getIntl(state),
isAdmin,
2021-11-02 23:01:13 +00:00
...groupMemberships,
2021-08-06 00:17:05 +00:00
userAvatarData: conversation.avatars || [],
hasGroupLink,
isGroup: conversation.type === 'group',
2021-11-02 23:01:13 +00:00
theme: getTheme(state),
};
};
2021-08-06 00:17:05 +00:00
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartConversationDetails = smart(ConversationDetails);