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

907 lines
25 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2018 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import type { ReactNode } from 'react';
import React from 'react';
2019-07-31 16:16:29 +00:00
import classNames from 'classnames';
import {
ContextMenu,
ContextMenuTrigger,
MenuItem,
SubMenu,
} from 'react-contextmenu';
import { DisappearingTimeDialog } from '../DisappearingTimeDialog';
2020-12-12 00:45:14 +00:00
import { Avatar, AvatarSize } from '../Avatar';
2020-07-24 01:35:32 +00:00
import { InContactsIcon } from '../InContactsIcon';
2021-11-02 23:01:13 +00:00
import type { LocalizerType, ThemeType } from '../../types/Util';
import type {
ConversationType,
PopPanelForConversationActionType,
PushPanelForConversationActionType,
} from '../../state/ducks/conversations';
2021-11-02 23:01:13 +00:00
import type { BadgeType } from '../../badges/types';
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';
2021-08-05 12:35:33 +00:00
import { getMuteOptions } from '../../util/getMuteOptions';
import * as expirationTimer from '../../util/expirationTimer';
import { missingCaseError } from '../../util/missingCaseError';
import { isInSystemContacts } from '../../util/isInSystemContacts';
2022-11-09 02:38:19 +00:00
import { isConversationMuted } from '../../util/isConversationMuted';
import { ConfirmationDialog } from '../ConfirmationDialog';
2022-11-16 20:18:02 +00:00
import { DurationInSeconds } from '../../util/durations';
2022-05-10 18:14:08 +00:00
import {
useStartCallShortcuts,
useKeyboardShortcuts,
} from '../../hooks/useKeyboardShortcuts';
import { PanelType } from '../../types/Panels';
2023-04-20 17:03:43 +00:00
import { UserText } from '../UserText';
import { Alert } from '../Alert';
import { SizeObserver } from '../../hooks/useSizeObserver';
export enum OutgoingCallButtonStyle {
None,
JustVideo,
Both,
2020-11-20 17:19:28 +00:00
Join,
}
export type PropsDataType = {
2021-11-02 23:01:13 +00:00
badge?: BadgeType;
cannotLeaveBecauseYouAreLastAdmin: boolean;
hasPanelShowing?: boolean;
2022-07-22 00:44:35 +00:00
hasStories?: HasStories;
2020-10-30 17:52:21 +00:00
isMissingMandatoryProfileSharing?: boolean;
outgoingCallButtonStyle: OutgoingCallButtonStyle;
isSMSOnly?: boolean;
2022-11-09 02:38:19 +00:00
isSignalConversation?: boolean;
2021-11-02 23:01:13 +00:00
theme: ThemeType;
} & Pick<
ConversationType,
| 'acceptedMessageRequest'
2021-07-20 20:18:35 +00:00
| 'announcementsOnly'
| 'areWeAdmin'
| 'avatarPath'
| 'canChangeTimer'
| 'color'
| 'expireTimer'
| 'groupVersion'
| 'id'
| 'isArchived'
| 'isMe'
| 'isPinned'
| 'isVerified'
| 'left'
| 'markedUnread'
| 'muteExpiresAt'
| 'name'
| 'phoneNumber'
| 'profileName'
| 'sharedGroupNames'
| 'title'
| 'type'
| 'unblurredAvatarPath'
>;
export type PropsActionsType = {
destroyMessages: (conversationId: string) => void;
leaveGroup: (conversationId: string) => void;
onArchive: (conversationId: string) => void;
onMarkUnread: (conversationId: string) => void;
2023-03-20 22:23:53 +00:00
toggleSelectMode: (on: boolean) => void;
onMoveToInbox: (conversationId: string) => void;
onOutgoingAudioCallInConversation: (conversationId: string) => void;
onOutgoingVideoCallInConversation: (conversationId: string) => void;
pushPanelForConversation: PushPanelForConversationActionType;
popPanelForConversation: PopPanelForConversationActionType;
searchInConversation: (conversationId: string) => void;
setDisappearingMessages: (
conversationId: string,
seconds: DurationInSeconds
) => void;
setMuteExpiration: (conversationId: string, seconds: number) => void;
2022-12-07 01:00:02 +00:00
setPinned: (conversationId: string, value: boolean) => void;
2022-08-22 17:44:23 +00:00
viewUserStories: ViewUserStoriesActionCreatorType;
};
2019-03-12 00:20:16 +00:00
export type PropsHousekeepingType = {
2019-03-12 00:20:16 +00:00
i18n: LocalizerType;
};
2020-07-24 01:35:32 +00:00
export type PropsType = PropsDataType &
PropsActionsType &
PropsHousekeepingType;
2021-06-01 20:45:43 +00:00
enum ModalState {
NothingOpen,
CustomDisappearingTimeout,
}
2021-03-01 20:08:37 +00:00
type StateType = {
hasDeleteMessagesConfirmation: boolean;
hasLeaveGroupConfirmation: boolean;
hasCannotLeaveGroupBecauseYouAreLastAdminAlert: boolean;
2021-03-01 20:08:37 +00:00
isNarrow: boolean;
2021-06-01 20:45:43 +00:00
modalState: ModalState;
2021-03-01 20:08:37 +00:00
};
2021-06-01 20:45:43 +00:00
const TIMER_ITEM_CLASS = 'module-ConversationHeader__disappearing-timer__item';
2021-03-01 20:08:37 +00:00
export class ConversationHeader extends React.Component<PropsType, StateType> {
private showMenuBound: (event: React.MouseEvent<HTMLButtonElement>) => void;
2020-09-14 19:51:27 +00:00
// Comes from a third-party dependency
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2021-03-01 20:08:37 +00:00
private menuTriggerRef: React.RefObject<any>;
public headerRef: React.RefObject<HTMLDivElement>;
2020-07-24 01:35:32 +00:00
public constructor(props: PropsType) {
super(props);
this.state = {
hasDeleteMessagesConfirmation: false,
hasLeaveGroupConfirmation: false,
hasCannotLeaveGroupBecauseYouAreLastAdminAlert: false,
isNarrow: false,
modalState: ModalState.NothingOpen,
};
2021-03-01 20:08:37 +00:00
2019-01-14 21:49:58 +00:00
this.menuTriggerRef = React.createRef();
this.headerRef = React.createRef();
this.showMenuBound = this.showMenu.bind(this);
}
2021-03-01 20:08:37 +00:00
private showMenu(event: React.MouseEvent<HTMLButtonElement>): void {
2019-01-14 21:49:58 +00:00
if (this.menuTriggerRef.current) {
this.menuTriggerRef.current.handleContextClick(event);
}
}
2021-03-01 20:08:37 +00:00
private renderHeaderInfoTitle(): ReactNode {
const { name, title, type, i18n, isMe } = this.props;
2019-01-31 01:45:58 +00:00
if (isMe) {
return (
2021-03-01 20:08:37 +00:00
<div className="module-ConversationHeader__header__info__title">
2023-03-30 00:03:25 +00:00
{i18n('icu:noteToSelf')}
2023-03-02 06:57:35 +00:00
<span className="ContactModal__official-badge" />
2019-01-31 01:45:58 +00:00
</div>
);
}
return (
2021-03-01 20:08:37 +00:00
<div className="module-ConversationHeader__header__info__title">
2023-04-20 17:03:43 +00:00
<UserText text={title} />
{isInSystemContacts({ name, type }) ? (
2021-03-01 20:08:37 +00:00
<InContactsIcon
className="module-ConversationHeader__header__info__title__in-contacts-icon"
i18n={i18n}
tooltipContainerRef={this.headerRef}
2021-03-01 20:08:37 +00:00
/>
) : null}
</div>
);
}
2021-03-01 20:08:37 +00:00
private renderHeaderInfoSubtitle(): ReactNode {
const expirationNode = this.renderExpirationLength();
const verifiedNode = this.renderVerifiedIcon();
if (expirationNode || verifiedNode) {
return (
<div className="module-ConversationHeader__header__info__subtitle">
{expirationNode}
{verifiedNode}
</div>
);
}
return null;
}
private renderAvatar(): ReactNode {
const {
acceptedMessageRequest,
avatarPath,
2021-11-02 23:01:13 +00:00
badge,
color,
2022-07-22 00:44:35 +00:00
hasStories,
id,
i18n,
2020-07-24 01:35:32 +00:00
type,
2019-01-31 01:45:58 +00:00
isMe,
phoneNumber,
profileName,
sharedGroupNames,
2021-11-02 23:01:13 +00:00
theme,
2020-07-24 01:35:32 +00:00
title,
unblurredAvatarPath,
2022-07-22 00:44:35 +00:00
viewUserStories,
} = this.props;
return (
2021-03-01 20:08:37 +00:00
<span className="module-ConversationHeader__header__avatar">
<Avatar
acceptedMessageRequest={acceptedMessageRequest}
avatarPath={avatarPath}
2021-11-02 23:01:13 +00:00
badge={badge}
color={color}
2020-07-24 01:35:32 +00:00
conversationType={type}
i18n={i18n}
isMe={isMe}
2022-07-22 00:44:35 +00:00
noteToSelf={isMe}
onClick={
hasStories
? () => {
2022-08-22 17:44:23 +00:00
viewUserStories({
conversationId: id,
storyViewMode: StoryViewModeType.User,
});
2022-07-22 00:44:35 +00:00
}
: undefined
}
phoneNumber={phoneNumber}
profileName={profileName}
sharedGroupNames={sharedGroupNames}
2020-12-12 00:45:14 +00:00
size={AvatarSize.THIRTY_TWO}
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}
2022-07-22 00:44:35 +00:00
title={title}
unblurredAvatarPath={unblurredAvatarPath}
/>
</span>
);
}
2021-03-01 20:08:37 +00:00
private renderExpirationLength(): ReactNode {
const { i18n, expireTimer } = this.props;
if (!expireTimer) {
return null;
}
return (
2021-03-01 20:08:37 +00:00
<div className="module-ConversationHeader__header__info__subtitle__expiration">
{expirationTimer.format(i18n, expireTimer)}
</div>
);
}
2021-03-01 20:08:37 +00:00
private renderVerifiedIcon(): ReactNode {
const { i18n, isVerified } = this.props;
if (!isVerified) {
return null;
}
return (
<div className="module-ConversationHeader__header__info__subtitle__verified">
2023-03-30 00:03:25 +00:00
{i18n('icu:verified')}
2021-03-01 20:08:37 +00:00
</div>
);
}
private renderMoreButton(triggerId: string): ReactNode {
const { i18n } = this.props;
return (
2019-01-14 21:49:58 +00:00
<ContextMenuTrigger id={triggerId} ref={this.menuTriggerRef}>
<button
2020-09-14 19:51:27 +00:00
type="button"
onClick={this.showMenuBound}
2019-07-31 16:16:29 +00:00
className={classNames(
'module-ConversationHeader__button',
'module-ConversationHeader__button--more'
)}
2023-03-30 00:03:25 +00:00
aria-label={i18n('icu:moreInfo')}
/>
</ContextMenuTrigger>
);
}
2021-03-01 20:08:37 +00:00
private renderSearchButton(): ReactNode {
const { i18n, id, searchInConversation } = this.props;
2019-08-09 23:12:29 +00:00
return (
<button
2020-09-14 19:51:27 +00:00
type="button"
onClick={() => searchInConversation(id)}
2019-08-09 23:12:29 +00:00
className={classNames(
'module-ConversationHeader__button',
'module-ConversationHeader__button--search'
2019-08-09 23:12:29 +00:00
)}
2023-03-30 00:03:25 +00:00
aria-label={i18n('icu:search')}
2019-08-09 23:12:29 +00:00
/>
);
}
2021-03-01 20:08:37 +00:00
private renderMenu(triggerId: string): ReactNode {
const {
acceptedMessageRequest,
2020-10-30 17:52:21 +00:00
canChangeTimer,
cannotLeaveBecauseYouAreLastAdmin,
2021-06-01 20:45:43 +00:00
expireTimer,
groupVersion,
i18n,
id,
2020-10-30 17:52:21 +00:00
isArchived,
isMissingMandatoryProfileSharing,
2020-10-02 18:30:43 +00:00
isPinned,
2022-11-09 02:38:19 +00:00
isSignalConversation,
left,
markedUnread,
2020-10-30 17:52:21 +00:00
muteExpiresAt,
onArchive,
onMarkUnread,
2023-03-20 22:23:53 +00:00
toggleSelectMode,
onMoveToInbox,
pushPanelForConversation,
setDisappearingMessages,
setMuteExpiration,
2022-12-07 01:00:02 +00:00
setPinned,
type,
} = this.props;
2023-04-20 17:03:43 +00:00
const isRTL = i18n.getLocaleDirection() === 'rtl';
2021-08-05 12:35:33 +00:00
const muteOptions = getMuteOptions(muteExpiresAt, i18n);
2020-08-27 19:45:08 +00:00
2023-03-30 00:03:25 +00:00
const muteTitle = <span>{i18n('icu:muteNotificationsTitle')}</span>;
2022-11-09 02:38:19 +00:00
if (isSignalConversation) {
const isMuted = muteExpiresAt && isConversationMuted({ muteExpiresAt });
return (
2023-04-20 17:03:43 +00:00
<ContextMenu id={triggerId} rtl={isRTL}>
<SubMenu hoverDelay={1} title={muteTitle} rtl={!isRTL}>
2022-11-09 02:38:19 +00:00
{isMuted ? (
<MenuItem
onClick={() => {
setMuteExpiration(id, 0);
2022-11-09 02:38:19 +00:00
}}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:unmute')}
2022-11-09 02:38:19 +00:00
</MenuItem>
) : (
<MenuItem
onClick={() => {
setMuteExpiration(id, Number.MAX_SAFE_INTEGER);
2022-11-09 02:38:19 +00:00
}}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:muteAlways')}
2022-11-09 02:38:19 +00:00
</MenuItem>
)}
</SubMenu>
</ContextMenu>
);
}
const disappearingTitle = <span>{i18n('icu:disappearingMessages')}</span>;
2020-07-24 01:35:32 +00:00
const isGroup = type === 'group';
2020-10-30 17:52:21 +00:00
const disableTimerChanges = Boolean(
!canChangeTimer ||
!acceptedMessageRequest ||
left ||
isMissingMandatoryProfileSharing
);
const hasGV2AdminEnabled = isGroup && groupVersion === 2;
if (isGroup && groupVersion !== 2) {
return (
<ContextMenu id={triggerId}>
<MenuItem
onClick={() =>
pushPanelForConversation({ type: PanelType.GroupV1Members })
}
>
{i18n('icu:showMembers')}
</MenuItem>
<MenuItem
onClick={() =>
pushPanelForConversation({ type: PanelType.AllMedia })
}
>
{i18n('icu:viewRecentMedia')}
</MenuItem>
<MenuItem divider />
{isArchived ? (
<MenuItem onClick={() => onMoveToInbox(id)}>
{i18n('icu:moveConversationToInbox')}
</MenuItem>
) : (
<MenuItem onClick={() => onArchive(id)}>
{i18n('icu:archiveConversation')}
</MenuItem>
)}
<MenuItem
onClick={() =>
this.setState({ hasDeleteMessagesConfirmation: true })
}
>
{i18n('icu:deleteMessages')}
</MenuItem>
</ContextMenu>
);
}
2021-06-01 20:45:43 +00:00
const isActiveExpireTimer = (value: number): boolean => {
if (!expireTimer) {
return value === 0;
}
// Custom time...
if (value === -1) {
return !expirationTimer.DEFAULT_DURATIONS_SET.has(expireTimer);
}
return value === expireTimer;
};
const expireDurations: ReadonlyArray<ReactNode> = [
...expirationTimer.DEFAULT_DURATIONS_IN_SECONDS,
2022-11-16 20:18:02 +00:00
DurationInSeconds.fromSeconds(-1),
].map(seconds => {
2021-06-01 20:45:43 +00:00
let text: string;
if (seconds === -1) {
2023-03-30 00:03:25 +00:00
text = i18n('icu:customDisappearingTimeOption');
2021-06-01 20:45:43 +00:00
} else {
text = expirationTimer.format(i18n, seconds, {
capitalizeOff: true,
});
}
const onDurationClick = () => {
if (seconds === -1) {
this.setState({
modalState: ModalState.CustomDisappearingTimeout,
});
} else {
setDisappearingMessages(id, seconds);
2021-06-01 20:45:43 +00:00
}
};
return (
<MenuItem key={seconds} onClick={onDurationClick}>
<div
className={classNames(
TIMER_ITEM_CLASS,
isActiveExpireTimer(seconds) && `${TIMER_ITEM_CLASS}--active`
)}
>
{text}
</div>
</MenuItem>
);
});
return (
2023-04-20 17:03:43 +00:00
<ContextMenu id={triggerId} rtl={isRTL}>
2020-09-09 02:25:05 +00:00
{disableTimerChanges ? null : (
2023-04-20 17:03:43 +00:00
<SubMenu hoverDelay={1} title={disappearingTitle} rtl={!isRTL}>
2021-07-13 22:27:28 +00:00
{expireDurations}
</SubMenu>
2020-09-09 02:25:05 +00:00
)}
2023-04-20 17:03:43 +00:00
<SubMenu hoverDelay={1} title={muteTitle} rtl={!isRTL}>
{muteOptions.map(item => (
<MenuItem
key={item.name}
disabled={item.disabled}
onClick={() => {
setMuteExpiration(id, item.value);
}}
>
{item.name}
</MenuItem>
))}
</SubMenu>
{!isGroup || hasGV2AdminEnabled ? (
<MenuItem
onClick={() =>
pushPanelForConversation({
type: PanelType.ConversationDetails,
})
}
>
{isGroup
2023-03-30 00:03:25 +00:00
? i18n('icu:showConversationDetails')
: i18n('icu:showConversationDetails--direct')}
</MenuItem>
) : null}
2022-12-20 17:50:23 +00:00
<MenuItem
onClick={() => pushPanelForConversation({ type: PanelType.AllMedia })}
2022-12-20 17:50:23 +00:00
>
2023-03-30 00:03:25 +00:00
{i18n('icu:viewRecentMedia')}
2022-12-20 17:50:23 +00:00
</MenuItem>
<MenuItem divider />
2023-03-20 22:23:53 +00:00
<MenuItem
onClick={() => {
toggleSelectMode(true);
}}
>
{i18n('icu:ConversationHeader__menu__selectMessages')}
</MenuItem>
<MenuItem divider />
{!markedUnread ? (
<MenuItem onClick={() => onMarkUnread(id)}>
{i18n('icu:markUnread')}
</MenuItem>
) : null}
{isPinned ? (
<MenuItem onClick={() => setPinned(id, false)}>
{i18n('icu:unpinConversation')}
</MenuItem>
) : (
<MenuItem onClick={() => setPinned(id, true)}>
{i18n('icu:pinConversation')}
</MenuItem>
)}
2019-03-12 00:20:16 +00:00
{isArchived ? (
<MenuItem onClick={() => onMoveToInbox(id)}>
2023-03-30 00:03:25 +00:00
{i18n('icu:moveConversationToInbox')}
2019-03-12 00:20:16 +00:00
</MenuItem>
) : (
<MenuItem onClick={() => onArchive(id)}>
2023-03-30 00:03:25 +00:00
{i18n('icu:archiveConversation')}
</MenuItem>
2019-03-12 00:20:16 +00:00
)}
<MenuItem
onClick={() => this.setState({ hasDeleteMessagesConfirmation: true })}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:deleteMessages')}
</MenuItem>
{isGroup && (
<MenuItem
onClick={() => {
if (cannotLeaveBecauseYouAreLastAdmin) {
this.setState({
hasCannotLeaveGroupBecauseYouAreLastAdminAlert: true,
});
} else {
this.setState({ hasLeaveGroupConfirmation: true });
}
}}
>
{i18n(
'icu:ConversationHeader__ContextMenu__LeaveGroupAction__title'
)}
</MenuItem>
)}
</ContextMenu>
);
}
private renderDeleteMessagesConfirmationDialog(): ReactNode {
const { hasDeleteMessagesConfirmation } = this.state;
const { destroyMessages, i18n, id } = this.props;
if (!hasDeleteMessagesConfirmation) {
return;
}
return (
<ConfirmationDialog
dialogName="ConversationHeader.destroyMessages"
title={i18n(
'icu:ConversationHeader__DeleteMessagesConfirmation__title'
)}
actions={[
{
action: () => {
this.setState({ hasDeleteMessagesConfirmation: false });
destroyMessages(id);
},
style: 'negative',
2023-03-30 00:03:25 +00:00
text: i18n('icu:delete'),
},
]}
i18n={i18n}
onClose={() => {
this.setState({ hasDeleteMessagesConfirmation: false });
}}
>
{i18n(
'icu:ConversationHeader__DeleteMessagesConfirmation__description'
)}
</ConfirmationDialog>
);
}
private renderLeaveGroupConfirmationDialog(): ReactNode {
const { hasLeaveGroupConfirmation } = this.state;
const { cannotLeaveBecauseYouAreLastAdmin, leaveGroup, i18n, id } =
this.props;
if (!hasLeaveGroupConfirmation) {
return;
}
return (
<ConfirmationDialog
dialogName="ConversationHeader.leaveGroup"
title={i18n('icu:ConversationHeader__LeaveGroupConfirmation__title')}
actions={[
{
disabled: cannotLeaveBecauseYouAreLastAdmin,
action: () => {
this.setState({ hasLeaveGroupConfirmation: false });
if (!cannotLeaveBecauseYouAreLastAdmin) {
leaveGroup(id);
} else {
this.setState({
hasLeaveGroupConfirmation: false,
hasCannotLeaveGroupBecauseYouAreLastAdminAlert: true,
});
}
},
style: 'negative',
text: i18n(
'icu:ConversationHeader__LeaveGroupConfirmation__confirmButton'
),
},
]}
i18n={i18n}
onClose={() => {
this.setState({ hasLeaveGroupConfirmation: false });
}}
>
{i18n('icu:ConversationHeader__LeaveGroupConfirmation__description')}
</ConfirmationDialog>
);
}
private renderCannotLeaveGroupBecauseYouAreLastAdminAlert() {
const { hasCannotLeaveGroupBecauseYouAreLastAdminAlert } = this.state;
const { i18n } = this.props;
if (!hasCannotLeaveGroupBecauseYouAreLastAdminAlert) {
return;
}
return (
<Alert
i18n={i18n}
body={i18n(
'icu:ConversationHeader__CannotLeaveGroupBecauseYouAreLastAdminAlert__description'
)}
onClose={() => {
this.setState({
hasCannotLeaveGroupBecauseYouAreLastAdminAlert: false,
});
}}
/>
);
}
2021-03-01 20:08:37 +00:00
private renderHeader(): ReactNode {
const { groupVersion, pushPanelForConversation, type } = this.props;
2021-01-28 00:18:50 +00:00
2021-03-01 20:08:37 +00:00
let onClick: undefined | (() => void);
switch (type) {
case 'direct':
onClick = () => {
pushPanelForConversation({ type: PanelType.ConversationDetails });
};
2021-03-01 20:08:37 +00:00
break;
case 'group': {
const hasGV2AdminEnabled = groupVersion === 2;
2021-03-01 20:08:37 +00:00
onClick = hasGV2AdminEnabled
? () => {
pushPanelForConversation({
type: PanelType.ConversationDetails,
});
2021-03-01 20:08:37 +00:00
}
: undefined;
break;
}
default:
throw missingCaseError(type);
}
2022-07-22 00:44:35 +00:00
const avatar = this.renderAvatar();
2021-03-01 20:08:37 +00:00
const contents = (
2022-07-22 00:44:35 +00:00
<div className="module-ConversationHeader__header__info">
{this.renderHeaderInfoTitle()}
{this.renderHeaderInfoSubtitle()}
</div>
2021-03-01 20:08:37 +00:00
);
2021-03-01 20:08:37 +00:00
if (onClick) {
2021-01-28 00:18:50 +00:00
return (
2022-07-22 00:44:35 +00:00
<div className="module-ConversationHeader__header">
{avatar}
2023-06-30 14:05:06 +00:00
<div>
<button
type="button"
className="module-ConversationHeader__header--clickable"
onClick={onClick}
>
{contents}
</button>
</div>
2022-07-22 00:44:35 +00:00
</div>
2021-01-28 00:18:50 +00:00
);
}
return (
<div className="module-ConversationHeader__header" ref={this.headerRef}>
2022-07-22 00:44:35 +00:00
{avatar}
{contents}
</div>
);
2021-01-28 00:18:50 +00:00
}
public override render(): ReactNode {
2022-05-10 18:14:08 +00:00
const {
announcementsOnly,
areWeAdmin,
expireTimer,
hasPanelShowing,
2022-05-10 18:14:08 +00:00
i18n,
id,
isSMSOnly,
2022-11-09 02:38:19 +00:00
isSignalConversation,
2022-05-10 18:14:08 +00:00
onOutgoingAudioCallInConversation,
onOutgoingVideoCallInConversation,
outgoingCallButtonStyle,
setDisappearingMessages,
2022-05-10 18:14:08 +00:00
} = this.props;
if (hasPanelShowing) {
return null;
}
2021-06-01 20:45:43 +00:00
const { isNarrow, modalState } = this.state;
2019-01-14 21:49:58 +00:00
const triggerId = `conversation-${id}`;
2021-06-01 20:45:43 +00:00
let modalNode: ReactNode;
if (modalState === ModalState.NothingOpen) {
modalNode = undefined;
} else if (modalState === ModalState.CustomDisappearingTimeout) {
modalNode = (
<DisappearingTimeDialog
i18n={i18n}
initialValue={expireTimer}
onSubmit={value => {
this.setState({ modalState: ModalState.NothingOpen });
setDisappearingMessages(id, value);
2021-06-01 20:45:43 +00:00
}}
onClose={() => this.setState({ modalState: ModalState.NothingOpen })}
/>
);
} else {
throw missingCaseError(modalState);
}
return (
2021-06-01 20:45:43 +00:00
<>
{modalNode}
{this.renderDeleteMessagesConfirmationDialog()}
{this.renderLeaveGroupConfirmationDialog()}
{this.renderCannotLeaveGroupBecauseYouAreLastAdminAlert()}
<SizeObserver
onSizeChange={size => {
this.setState({ isNarrow: size.width < 500 });
2021-06-01 20:45:43 +00:00
}}
>
{measureRef => (
2021-06-01 20:45:43 +00:00
<div
className={classNames('module-ConversationHeader', {
'module-ConversationHeader--narrow': isNarrow,
})}
ref={measureRef}
>
{this.renderHeader()}
2022-11-09 02:38:19 +00:00
{!isSMSOnly && !isSignalConversation && (
2022-05-10 18:14:08 +00:00
<OutgoingCallButtons
announcementsOnly={announcementsOnly}
areWeAdmin={areWeAdmin}
i18n={i18n}
id={id}
2022-05-10 18:14:08 +00:00
isNarrow={isNarrow}
onOutgoingAudioCallInConversation={
onOutgoingAudioCallInConversation
}
onOutgoingVideoCallInConversation={
onOutgoingVideoCallInConversation
}
outgoingCallButtonStyle={outgoingCallButtonStyle}
/>
)}
2021-06-01 20:45:43 +00:00
{this.renderSearchButton()}
{this.renderMoreButton(triggerId)}
{this.renderMenu(triggerId)}
</div>
)}
</SizeObserver>
2021-06-01 20:45:43 +00:00
</>
);
}
}
2022-05-10 18:14:08 +00:00
function OutgoingCallButtons({
announcementsOnly,
areWeAdmin,
i18n,
id,
2022-05-10 18:14:08 +00:00
isNarrow,
onOutgoingAudioCallInConversation,
onOutgoingVideoCallInConversation,
outgoingCallButtonStyle,
}: { isNarrow: boolean } & Pick<
PropsType,
| 'announcementsOnly'
| 'areWeAdmin'
| 'i18n'
| 'id'
2022-05-10 18:14:08 +00:00
| 'onOutgoingAudioCallInConversation'
| 'onOutgoingVideoCallInConversation'
| 'outgoingCallButtonStyle'
>): JSX.Element | null {
const videoButton = (
<button
2023-03-30 00:03:25 +00:00
aria-label={i18n('icu:makeOutgoingVideoCall')}
2022-05-10 18:14:08 +00:00
className={classNames(
'module-ConversationHeader__button',
'module-ConversationHeader__button--video',
announcementsOnly && !areWeAdmin
2022-05-10 18:14:08 +00:00
? 'module-ConversationHeader__button--show-disabled'
: undefined
)}
onClick={() => onOutgoingVideoCallInConversation(id)}
2022-05-10 18:14:08 +00:00
type="button"
/>
);
const startCallShortcuts = useStartCallShortcuts(
() => onOutgoingAudioCallInConversation(id),
() => onOutgoingVideoCallInConversation(id)
2022-05-10 18:14:08 +00:00
);
useKeyboardShortcuts(startCallShortcuts);
switch (outgoingCallButtonStyle) {
case OutgoingCallButtonStyle.None:
return null;
case OutgoingCallButtonStyle.JustVideo:
return videoButton;
case OutgoingCallButtonStyle.Both:
return (
<>
{videoButton}
<button
type="button"
onClick={() => onOutgoingAudioCallInConversation(id)}
2022-05-10 18:14:08 +00:00
className={classNames(
'module-ConversationHeader__button',
'module-ConversationHeader__button--audio'
2022-05-10 18:14:08 +00:00
)}
2023-03-30 00:03:25 +00:00
aria-label={i18n('icu:makeOutgoingCall')}
2022-05-10 18:14:08 +00:00
/>
</>
);
case OutgoingCallButtonStyle.Join:
return (
<button
2023-03-30 00:03:25 +00:00
aria-label={i18n('icu:joinOngoingCall')}
2022-05-10 18:14:08 +00:00
className={classNames(
'module-ConversationHeader__button',
'module-ConversationHeader__button--join-call',
announcementsOnly && !areWeAdmin
? 'module-ConversationHeader__button--show-disabled'
: undefined
2022-05-10 18:14:08 +00:00
)}
onClick={() => onOutgoingVideoCallInConversation(id)}
2022-05-10 18:14:08 +00:00
type="button"
>
2023-03-30 00:03:25 +00:00
{isNarrow ? null : i18n('icu:joinOngoingCall')}
2022-05-10 18:14:08 +00:00
</button>
);
default:
throw missingCaseError(outgoingCallButtonStyle);
}
}