2020-11-11 17:36:05 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { mapDispatchToProps } from '../actions';
|
|
|
|
import {
|
|
|
|
ContactModal,
|
|
|
|
PropsType,
|
|
|
|
} from '../../components/conversation/ContactModal';
|
|
|
|
import { StateType } from '../reducer';
|
|
|
|
|
|
|
|
import { getIntl } from '../selectors/user';
|
|
|
|
import { getConversationSelector } from '../selectors/conversations';
|
|
|
|
|
|
|
|
export type SmartContactModalProps = {
|
|
|
|
contactId: string;
|
|
|
|
currentConversationId: string;
|
|
|
|
readonly onClose: () => unknown;
|
|
|
|
readonly openConversation: (conversationId: string) => void;
|
|
|
|
readonly removeMember: (conversationId: string) => void;
|
2021-01-29 21:19:24 +00:00
|
|
|
readonly showSafetyNumber: (conversationId: string) => void;
|
|
|
|
readonly toggleAdmin: (conversationId: string) => void;
|
2021-05-21 17:27:28 +00:00
|
|
|
readonly updateSharedGroups: () => void;
|
2020-11-11 17:36:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = (
|
|
|
|
state: StateType,
|
|
|
|
props: SmartContactModalProps
|
|
|
|
): PropsType => {
|
|
|
|
const { contactId, currentConversationId } = props;
|
|
|
|
|
|
|
|
const currentConversation = getConversationSelector(state)(
|
|
|
|
currentConversationId
|
|
|
|
);
|
|
|
|
const contact = getConversationSelector(state)(contactId);
|
|
|
|
|
|
|
|
const areWeAdmin =
|
|
|
|
currentConversation && currentConversation.areWeAdmin
|
|
|
|
? currentConversation.areWeAdmin
|
|
|
|
: false;
|
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
let isMember = false;
|
|
|
|
let isAdmin = false;
|
|
|
|
if (contact && currentConversation && currentConversation.memberships) {
|
|
|
|
currentConversation.memberships.forEach(membership => {
|
2021-04-29 18:32:38 +00:00
|
|
|
if (membership.conversationId === contact.id) {
|
2021-01-29 21:19:24 +00:00
|
|
|
isMember = true;
|
|
|
|
isAdmin = membership.isAdmin;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-11 17:36:05 +00:00
|
|
|
return {
|
|
|
|
...props,
|
|
|
|
areWeAdmin,
|
|
|
|
contact,
|
|
|
|
i18n: getIntl(state),
|
2021-01-29 21:19:24 +00:00
|
|
|
isAdmin,
|
2020-11-11 17:36:05 +00:00
|
|
|
isMember,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
export const SmartContactModal = smart(ContactModal);
|