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

58 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { connect } from 'react-redux';
import { mapDispatchToProps } from '../actions';
import type { PropsDataType } from '../../components/conversation/ContactModal';
import { ContactModal } from '../../components/conversation/ContactModal';
import type { StateType } from '../reducer';
import { getAreWeASubscriber } from '../selectors/items';
2021-11-11 16:23:00 +00:00
import { getIntl, getTheme } from '../selectors/user';
2021-11-02 23:01:13 +00:00
import { getBadgesSelector } from '../selectors/badges';
import { getConversationSelector } from '../selectors/conversations';
import { getHasStoriesSelector } from '../selectors/stories2';
2021-09-21 22:37:10 +00:00
const mapStateToProps = (state: StateType): PropsDataType => {
const { contactId, conversationId } =
state.globalModals.contactModalState || {};
2021-09-21 22:37:10 +00:00
const currentConversation = getConversationSelector(state)(conversationId);
const contact = getConversationSelector(state)(contactId);
const areWeAdmin =
currentConversation && currentConversation.areWeAdmin
? currentConversation.areWeAdmin
: false;
let isMember = false;
let isAdmin = false;
if (contact && currentConversation && currentConversation.memberships) {
currentConversation.memberships.forEach(membership => {
2023-08-16 20:54:39 +00:00
if (membership.aci === contact.serviceId) {
isMember = true;
isAdmin = membership.isAdmin;
}
});
}
2022-07-22 00:44:35 +00:00
const hasStories = getHasStoriesSelector(state)(conversationId);
return {
areWeASubscriber: getAreWeASubscriber(state),
areWeAdmin,
2021-11-02 23:01:13 +00:00
badges: getBadgesSelector(state)(contact.badges),
contact,
conversation: currentConversation,
2022-07-22 00:44:35 +00:00
hasStories,
i18n: getIntl(state),
isAdmin,
isMember,
2021-11-11 16:23:00 +00:00
theme: getTheme(state),
};
};
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartContactModal = smart(ContactModal);