/* * Wire * Copyright (C) 2022 Wire Swiss GmbH * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * */ import {FC, useEffect} from 'react'; import {TabIndex} from '@wireapp/react-ui-kit/lib/types/enums'; import {FadingScrollbar} from 'Components/FadingScrollbar'; import * as Icon from 'Components/Icon'; import {ServiceDetails} from 'Components/panel/ServiceDetails'; import {useKoSubscribableChildren} from 'Util/ComponentUtil'; import {handleKeyDown} from 'Util/KeyboardUtil'; import {t} from 'Util/LocalizerUtil'; import {Conversation} from '../../../entity/Conversation'; import {User} from '../../../entity/User'; import {IntegrationRepository} from '../../../integration/IntegrationRepository'; import {ServiceEntity} from '../../../integration/ServiceEntity'; import {generatePermissionHelpers} from '../../../user/UserPermission'; import {ActionsViewModel} from '../../../view_model/ActionsViewModel'; import {PanelHeader} from '../PanelHeader'; interface GroupParticipantServiceProps { activeConversation: Conversation; actionsViewModel: ActionsViewModel; integrationRepository: IntegrationRepository; enableRemove: boolean; goToRoot: () => void; onBack: () => void; onClose: () => void; serviceEntity: ServiceEntity; selfUser: User; isAddMode?: boolean; } const GroupParticipantService: FC = ({ activeConversation, actionsViewModel, integrationRepository, enableRemove, goToRoot, onBack, onClose, serviceEntity, selfUser, isAddMode = false, }) => { const { inTeam, isActiveParticipant, participating_user_ets: participatingUserEts, } = useKoSubscribableChildren(activeConversation, ['inTeam', 'isActiveParticipant', 'participating_user_ets']); const {teamRole} = useKoSubscribableChildren(selfUser, ['teamRole']); const {canChatWithServices} = generatePermissionHelpers(teamRole); const serviceUser = participatingUserEts.find(user => user.serviceId === serviceEntity.id); const showActions = isActiveParticipant && serviceUser && inTeam; const onOpen = () => { actionsViewModel.open1to1ConversationWithService(serviceEntity); }; const onRemove = (user: User) => { actionsViewModel.removeFromConversation(activeConversation, user); onBack(); }; const onAdd = () => { integrationRepository.addServiceToExistingConversation(activeConversation, serviceEntity); goToRoot(); }; useEffect(() => { integrationRepository.addProviderNameToParticipant(serviceEntity); }, [integrationRepository, serviceEntity]); return (
{showActions && canChatWithServices() && (
handleKeyDown(event, onOpen)} >
{t('groupParticipantActionOpenConversation')}
)} {showActions && enableRemove && (
onRemove(serviceUser)} onKeyDown={event => handleKeyDown(event, () => onRemove(serviceUser))} >
{t('groupParticipantActionRemove')}
)}
{isAddMode && (
)}
); }; export {GroupParticipantService};