2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-11-11 17:36:05 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-03-28 00:32:47 +00:00
|
|
|
import React, { memo, useCallback, useMemo } from 'react';
|
2024-03-13 20:44:13 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { ContactModal } from '../../components/conversation/ContactModal';
|
2021-11-30 16:29:57 +00:00
|
|
|
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';
|
2020-11-11 17:36:05 +00:00
|
|
|
import { getConversationSelector } from '../selectors/conversations';
|
2023-03-08 02:15:25 +00:00
|
|
|
import { getHasStoriesSelector } from '../selectors/stories2';
|
2024-06-18 16:15:56 +00:00
|
|
|
import {
|
|
|
|
getActiveCallState,
|
|
|
|
isInFullScreenCall as getIsInFullScreenCall,
|
|
|
|
} from '../selectors/calling';
|
2024-03-13 20:44:13 +00:00
|
|
|
import { useStoriesActions } from '../ducks/stories';
|
|
|
|
import { useConversationsActions } from '../ducks/conversations';
|
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { useCallingActions } from '../ducks/calling';
|
|
|
|
import { getContactModalState } from '../selectors/globalModals';
|
2024-03-28 00:32:47 +00:00
|
|
|
import { strictAssert } from '../../util/assert';
|
2024-03-13 20:44:13 +00:00
|
|
|
|
|
|
|
export const SmartContactModal = memo(function SmartContactModal() {
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const theme = useSelector(getTheme);
|
|
|
|
const { conversationId, contactId } = useSelector(getContactModalState) ?? {};
|
|
|
|
const conversationSelector = useSelector(getConversationSelector);
|
|
|
|
const hasStoriesSelector = useSelector(getHasStoriesSelector);
|
|
|
|
const activeCallState = useSelector(getActiveCallState);
|
2024-06-18 16:15:56 +00:00
|
|
|
const isInFullScreenCall = useSelector(getIsInFullScreenCall);
|
2024-03-13 20:44:13 +00:00
|
|
|
const badgesSelector = useSelector(getBadgesSelector);
|
|
|
|
const areWeASubscriber = useSelector(getAreWeASubscriber);
|
|
|
|
|
|
|
|
const conversation = conversationSelector(conversationId);
|
|
|
|
const contact = conversationSelector(contactId);
|
|
|
|
const hasStories = hasStoriesSelector(contactId);
|
|
|
|
const hasActiveCall = activeCallState != null;
|
|
|
|
const badges = badgesSelector(contact.badges);
|
|
|
|
|
|
|
|
const areWeAdmin = conversation?.areWeAdmin ?? false;
|
2020-11-11 17:36:05 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const ourMembership = useMemo(() => {
|
|
|
|
return conversation?.memberships?.find(membership => {
|
|
|
|
return membership.aci === contact.serviceId;
|
2021-01-29 21:19:24 +00:00
|
|
|
});
|
2024-03-13 20:44:13 +00:00
|
|
|
}, [conversation?.memberships, contact]);
|
|
|
|
|
|
|
|
const isMember = ourMembership != null;
|
|
|
|
const isAdmin = ourMembership?.isAdmin ?? false;
|
|
|
|
|
|
|
|
const {
|
|
|
|
removeMemberFromGroup,
|
|
|
|
showConversation,
|
|
|
|
updateConversationModelSharedGroups,
|
|
|
|
toggleAdmin,
|
|
|
|
blockConversation,
|
|
|
|
} = useConversationsActions();
|
|
|
|
const { viewUserStories } = useStoriesActions();
|
|
|
|
const {
|
|
|
|
toggleAboutContactModal,
|
|
|
|
toggleAddUserToAnotherGroupModal,
|
|
|
|
toggleSafetyNumberModal,
|
|
|
|
hideContactModal,
|
2024-03-28 00:32:47 +00:00
|
|
|
toggleEditNicknameAndNoteModal,
|
2024-03-13 20:44:13 +00:00
|
|
|
} = useGlobalModalActions();
|
|
|
|
const {
|
|
|
|
onOutgoingVideoCallInConversation,
|
|
|
|
onOutgoingAudioCallInConversation,
|
2024-06-18 16:15:56 +00:00
|
|
|
togglePip,
|
2024-03-13 20:44:13 +00:00
|
|
|
} = useCallingActions();
|
|
|
|
|
2024-03-28 00:32:47 +00:00
|
|
|
const handleOpenEditNicknameAndNoteModal = useCallback(() => {
|
|
|
|
strictAssert(contactId != null, 'Expected conversationId to be set');
|
|
|
|
toggleEditNicknameAndNoteModal({ conversationId: contactId });
|
|
|
|
}, [toggleEditNicknameAndNoteModal, contactId]);
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
return (
|
|
|
|
<ContactModal
|
|
|
|
areWeAdmin={areWeAdmin}
|
|
|
|
areWeASubscriber={areWeASubscriber}
|
|
|
|
badges={badges}
|
|
|
|
blockConversation={blockConversation}
|
|
|
|
contact={contact}
|
|
|
|
conversation={conversation}
|
|
|
|
hasActiveCall={hasActiveCall}
|
|
|
|
hasStories={hasStories}
|
|
|
|
hideContactModal={hideContactModal}
|
|
|
|
i18n={i18n}
|
|
|
|
isAdmin={isAdmin}
|
2024-06-18 16:15:56 +00:00
|
|
|
isInFullScreenCall={isInFullScreenCall}
|
2024-03-13 20:44:13 +00:00
|
|
|
isMember={isMember}
|
2024-03-28 00:32:47 +00:00
|
|
|
onOpenEditNicknameAndNoteModal={handleOpenEditNicknameAndNoteModal}
|
2024-03-13 20:44:13 +00:00
|
|
|
onOutgoingAudioCallInConversation={onOutgoingAudioCallInConversation}
|
|
|
|
onOutgoingVideoCallInConversation={onOutgoingVideoCallInConversation}
|
|
|
|
removeMemberFromGroup={removeMemberFromGroup}
|
|
|
|
showConversation={showConversation}
|
|
|
|
theme={theme}
|
|
|
|
toggleAboutContactModal={toggleAboutContactModal}
|
|
|
|
toggleAddUserToAnotherGroupModal={toggleAddUserToAnotherGroupModal}
|
|
|
|
toggleAdmin={toggleAdmin}
|
2024-06-18 16:15:56 +00:00
|
|
|
togglePip={togglePip}
|
2024-03-13 20:44:13 +00:00
|
|
|
toggleSafetyNumberModal={toggleSafetyNumberModal}
|
|
|
|
updateConversationModelSharedGroups={updateConversationModelSharedGroups}
|
|
|
|
viewUserStories={viewUserStories}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|