signal-desktop/ts/components/conversation/ConversationHero.tsx

261 lines
7.2 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2022 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useEffect, useState } from 'react';
import type { Props as AvatarProps } from '../Avatar';
import { Avatar, AvatarBlur } from '../Avatar';
2020-05-27 21:37:06 +00:00
import { ContactName } from './ContactName';
2021-01-26 01:01:19 +00:00
import { About } from './About';
2021-06-02 00:24:28 +00:00
import { GroupDescription } from './GroupDescription';
2021-04-16 15:51:26 +00:00
import { SharedGroupNames } from '../SharedGroupNames';
2021-11-02 23:01:13 +00:00
import type { LocalizerType, ThemeType } from '../../types/Util';
2022-07-22 00:44:35 +00:00
import type { HasStories } from '../../types/Stories';
2022-08-22 17:44:23 +00:00
import type { ViewUserStoriesActionCreatorType } from '../../state/ducks/stories';
import { StoryViewModeType } from '../../types/Stories';
import { ConfirmationDialog } from '../ConfirmationDialog';
import { Button, ButtonSize, ButtonVariant } from '../Button';
import { shouldBlurAvatar } from '../../util/shouldBlurAvatar';
2021-09-21 20:45:25 +00:00
import { openLinkInWebBrowser } from '../../util/openLinkInWebBrowser';
2020-05-27 21:37:06 +00:00
export type Props = {
2021-01-26 01:01:19 +00:00
about?: string;
acceptedMessageRequest?: boolean;
2021-06-02 00:24:28 +00:00
groupDescription?: string;
2022-07-22 00:44:35 +00:00
hasStories?: HasStories;
id: string;
2020-05-27 21:37:06 +00:00
i18n: LocalizerType;
2021-05-07 22:21:10 +00:00
isMe: boolean;
2022-11-09 02:38:19 +00:00
isSignalConversation?: boolean;
2020-05-27 21:37:06 +00:00
membersCount?: number;
2022-09-28 16:27:52 +00:00
name?: string;
phoneNumber?: string;
sharedGroupNames?: Array<string>;
unblurAvatar: () => void;
unblurredAvatarPath?: string;
updateSharedGroups: () => unknown;
2021-11-02 23:01:13 +00:00
theme: ThemeType;
2022-08-22 17:44:23 +00:00
viewUserStories: ViewUserStoriesActionCreatorType;
2020-05-27 21:37:06 +00:00
} & Omit<AvatarProps, 'onClick' | 'size' | 'noteToSelf'>;
const renderMembershipRow = ({
acceptedMessageRequest,
2020-05-27 21:37:06 +00:00
conversationType,
i18n,
2020-05-27 21:37:06 +00:00
isMe,
onClickMessageRequestWarning,
phoneNumber,
sharedGroupNames,
}: Pick<
Props,
| 'acceptedMessageRequest'
| 'conversationType'
| 'i18n'
| 'isMe'
| 'phoneNumber'
> &
Required<Pick<Props, 'sharedGroupNames'>> & {
onClickMessageRequestWarning: () => void;
}) => {
2020-05-27 21:37:06 +00:00
const className = 'module-conversation-hero__membership';
if (conversationType !== 'direct') {
return null;
}
2020-05-27 21:37:06 +00:00
if (isMe) {
return <div className={className}>{i18n('noteToSelfHero')}</div>;
}
if (sharedGroupNames.length > 0) {
2021-04-16 15:51:26 +00:00
return (
<div className={className}>
<SharedGroupNames
i18n={i18n}
nameClassName={`${className}__name`}
sharedGroupNames={sharedGroupNames}
/>
</div>
);
2020-05-27 21:37:06 +00:00
}
if (acceptedMessageRequest) {
if (phoneNumber) {
return null;
}
return <div className={className}>{i18n('no-groups-in-common')}</div>;
}
return (
<div className="module-conversation-hero__message-request-warning">
<div className="module-conversation-hero__message-request-warning__message">
{i18n('no-groups-in-common-warning')}
</div>
<Button
onClick={onClickMessageRequestWarning}
size={ButtonSize.Small}
variant={ButtonVariant.SecondaryAffirmative}
>
{i18n('MessageRequestWarning__learn-more')}
</Button>
</div>
);
2020-05-27 21:37:06 +00:00
};
export const ConversationHero = ({
i18n,
2021-01-26 01:01:19 +00:00
about,
acceptedMessageRequest,
2020-05-27 21:37:06 +00:00
avatarPath,
2021-11-02 23:01:13 +00:00
badge,
2020-05-27 21:37:06 +00:00
color,
conversationType,
2021-06-02 00:24:28 +00:00
groupDescription,
2022-07-22 00:44:35 +00:00
hasStories,
id,
2020-05-27 21:37:06 +00:00
isMe,
2022-11-09 02:38:19 +00:00
isSignalConversation,
2020-05-27 21:37:06 +00:00
membersCount,
2020-08-05 01:13:19 +00:00
sharedGroupNames = [],
2020-05-27 21:37:06 +00:00
name,
phoneNumber,
profileName,
2021-11-02 23:01:13 +00:00
theme,
2020-07-24 01:35:32 +00:00
title,
unblurAvatar,
unblurredAvatarPath,
2020-08-07 00:50:54 +00:00
updateSharedGroups,
2022-07-22 00:44:35 +00:00
viewUserStories,
2020-09-14 19:51:27 +00:00
}: Props): JSX.Element => {
2021-11-11 22:43:05 +00:00
const [isShowingMessageRequestWarning, setIsShowingMessageRequestWarning] =
useState(false);
const closeMessageRequestWarning = () => {
setIsShowingMessageRequestWarning(false);
};
2020-08-07 00:50:54 +00:00
useEffect(() => {
// Kick off the expensive hydration of the current sharedGroupNames
updateSharedGroups();
}, [updateSharedGroups]);
2022-07-22 00:44:35 +00:00
let avatarBlur: AvatarBlur = AvatarBlur.NoBlur;
let avatarOnClick: undefined | (() => void);
if (
shouldBlurAvatar({
acceptedMessageRequest,
avatarPath,
isMe,
sharedGroupNames,
unblurredAvatarPath,
})
) {
avatarBlur = AvatarBlur.BlurPictureWithClickToView;
avatarOnClick = unblurAvatar;
2022-07-22 00:44:35 +00:00
} else if (hasStories) {
avatarOnClick = () => {
2022-08-22 17:44:23 +00:00
viewUserStories({
conversationId: id,
storyViewMode: StoryViewModeType.User,
});
2022-07-22 00:44:35 +00:00
};
}
2020-07-24 01:35:32 +00:00
const phoneNumberOnly = Boolean(
!name && !profileName && conversationType === 'direct'
);
2020-09-14 19:51:27 +00:00
/* eslint-disable no-nested-ternary */
2020-05-27 21:37:06 +00:00
return (
<>
<div className="module-conversation-hero">
<Avatar
acceptedMessageRequest={acceptedMessageRequest}
avatarPath={avatarPath}
2021-11-02 23:01:13 +00:00
badge={badge}
blur={avatarBlur}
className="module-conversation-hero__avatar"
color={color}
conversationType={conversationType}
i18n={i18n}
isMe={isMe}
noteToSelf={isMe}
onClick={avatarOnClick}
profileName={profileName}
sharedGroupNames={sharedGroupNames}
size={112}
2022-10-04 21:39:29 +00:00
// user may have stories, but we don't show that on Note to Self conversation
storyRing={isMe ? undefined : hasStories}
2021-11-02 23:01:13 +00:00
theme={theme}
title={title}
/>
<h1 className="module-conversation-hero__profile-name">
2022-11-09 02:38:19 +00:00
{isMe ? (
i18n('noteToSelf')
) : (
<ContactName
isSignalConversation={isSignalConversation}
title={title}
/>
)}
</h1>
{about && !isMe && (
<div className="module-about__container">
<About text={about} />
</div>
2020-05-27 21:37:06 +00:00
)}
{!isMe ? (
<div className="module-conversation-hero__with">
{groupDescription ? (
<GroupDescription
i18n={i18n}
title={title}
text={groupDescription}
/>
) : membersCount != null ? (
i18n('icu:ConversationHero--members', { count: membersCount })
) : phoneNumberOnly ? null : (
phoneNumber
)}
</div>
) : null}
2022-11-09 02:38:19 +00:00
{!isSignalConversation &&
renderMembershipRow({
acceptedMessageRequest,
conversationType,
i18n,
isMe,
onClickMessageRequestWarning() {
setIsShowingMessageRequestWarning(true);
},
phoneNumber,
sharedGroupNames,
})}
{!isSignalConversation && (
<div className="module-conversation-hero__linkNotification">
{i18n('messageHistoryUnsynced')}
</div>
)}
</div>
{isShowingMessageRequestWarning && (
<ConfirmationDialog
2022-09-27 20:24:21 +00:00
dialogName="ConversationHere.messageRequestWarning"
i18n={i18n}
onClose={closeMessageRequestWarning}
actions={[
{
text: i18n('MessageRequestWarning__dialog__learn-even-more'),
action: () => {
2021-09-21 20:45:25 +00:00
openLinkInWebBrowser(
'https://support.signal.org/hc/articles/360007459591'
);
closeMessageRequestWarning();
},
},
]}
>
{i18n('MessageRequestWarning__dialog__details')}
</ConfirmationDialog>
2021-01-26 01:01:19 +00:00
)}
</>
2020-05-27 21:37:06 +00:00
);
2020-09-14 19:51:27 +00:00
/* eslint-enable no-nested-ternary */
2020-05-27 21:37:06 +00:00
};