In conversation header, only show video button for group calls

This commit is contained in:
Evan Hahn 2020-11-19 10:37:56 -06:00 committed by Josh Perez
parent 07ff4c9dcb
commit 05205c77cf
4 changed files with 94 additions and 45 deletions

View file

@ -8,7 +8,10 @@ import { action } from '@storybook/addon-actions';
import { setup as setupI18n } from '../../../js/modules/i18n'; import { setup as setupI18n } from '../../../js/modules/i18n';
import enMessages from '../../../_locales/en/messages.json'; import enMessages from '../../../_locales/en/messages.json';
import { ConversationHeader } from './ConversationHeader'; import {
ConversationHeader,
OutgoingCallButtonStyle,
} from './ConversationHeader';
import { gifUrl } from '../../storybook/Fixtures'; import { gifUrl } from '../../storybook/Fixtures';
const book = storiesOf('Components/Conversation/ConversationHeader', module); const book = storiesOf('Components/Conversation/ConversationHeader', module);
@ -25,7 +28,7 @@ type ConversationHeaderStory = {
const commonProps = { const commonProps = {
showBackButton: false, showBackButton: false,
showCallButtons: true, outgoingCallButtonStyle: OutgoingCallButtonStyle.Both,
markedUnread: false, markedUnread: false,
i18n, i18n,
@ -186,6 +189,7 @@ const stories: Array<ConversationHeaderStory> = [
type: 'group', type: 'group',
expireTimer: 10, expireTimer: 10,
acceptedMessageRequest: true, acceptedMessageRequest: true,
outgoingCallButtonStyle: OutgoingCallButtonStyle.JustVideo,
}, },
}, },
{ {
@ -201,6 +205,7 @@ const stories: Array<ConversationHeaderStory> = [
left: true, left: true,
expireTimer: 10, expireTimer: 10,
acceptedMessageRequest: true, acceptedMessageRequest: true,
outgoingCallButtonStyle: OutgoingCallButtonStyle.JustVideo,
}, },
}, },
], ],
@ -220,6 +225,7 @@ const stories: Array<ConversationHeaderStory> = [
type: 'direct', type: 'direct',
isMe: true, isMe: true,
acceptedMessageRequest: true, acceptedMessageRequest: true,
outgoingCallButtonStyle: OutgoingCallButtonStyle.None,
}, },
}, },
], ],
@ -239,6 +245,7 @@ const stories: Array<ConversationHeaderStory> = [
type: 'direct', type: 'direct',
isMe: false, isMe: false,
acceptedMessageRequest: false, acceptedMessageRequest: false,
outgoingCallButtonStyle: OutgoingCallButtonStyle.None,
}, },
}, },
], ],

View file

@ -23,6 +23,13 @@ import {
TimerOption, TimerOption,
} from '../../util/ExpirationTimerOptions'; } from '../../util/ExpirationTimerOptions';
import { isMuted } from '../../util/isMuted'; import { isMuted } from '../../util/isMuted';
import { missingCaseError } from '../../util/missingCaseError';
export enum OutgoingCallButtonStyle {
None,
JustVideo,
Both,
}
export interface PropsDataType { export interface PropsDataType {
id: string; id: string;
@ -49,7 +56,7 @@ export interface PropsDataType {
muteExpiresAt?: number; muteExpiresAt?: number;
showBackButton?: boolean; showBackButton?: boolean;
showCallButtons?: boolean; outgoingCallButtonStyle: OutgoingCallButtonStyle;
} }
export interface PropsActionsType { export interface PropsActionsType {
@ -264,42 +271,51 @@ export class ConversationHeader extends React.Component<PropsType> {
i18n, i18n,
onOutgoingAudioCallInConversation, onOutgoingAudioCallInConversation,
onOutgoingVideoCallInConversation, onOutgoingVideoCallInConversation,
showCallButtons, outgoingCallButtonStyle,
showBackButton, showBackButton,
} = this.props; } = this.props;
if (!showCallButtons) { const videoButton = (
return null; <button
} type="button"
onClick={onOutgoingVideoCallInConversation}
return ( className={classNames(
<> 'module-conversation-header__video-calling-button',
<button showBackButton
type="button" ? null
onClick={onOutgoingVideoCallInConversation} : 'module-conversation-header__video-calling-button--show'
className={classNames( )}
'module-conversation-header__video-calling-button', disabled={showBackButton}
showBackButton aria-label={i18n('makeOutgoingVideoCall')}
? null />
: 'module-conversation-header__video-calling-button--show'
)}
disabled={showBackButton}
aria-label={i18n('makeOutgoingVideoCall')}
/>
<button
type="button"
onClick={onOutgoingAudioCallInConversation}
className={classNames(
'module-conversation-header__audio-calling-button',
showBackButton
? null
: 'module-conversation-header__audio-calling-button--show'
)}
disabled={showBackButton}
aria-label={i18n('makeOutgoingCall')}
/>
</>
); );
switch (outgoingCallButtonStyle) {
case OutgoingCallButtonStyle.None:
return null;
case OutgoingCallButtonStyle.JustVideo:
return videoButton;
case OutgoingCallButtonStyle.Both:
return (
<>
{videoButton}
<button
type="button"
onClick={onOutgoingAudioCallInConversation}
className={classNames(
'module-conversation-header__audio-calling-button',
showBackButton
? null
: 'module-conversation-header__audio-calling-button--show'
)}
disabled={showBackButton}
aria-label={i18n('makeOutgoingCall')}
/>
</>
);
default:
throw missingCaseError(outgoingCallButtonStyle);
}
} }
public renderMenu(triggerId: string): JSX.Element { public renderMenu(triggerId: string): JSX.Element {

View file

@ -3,13 +3,20 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { pick } from 'lodash'; import { pick } from 'lodash';
import { ConversationHeader } from '../../components/conversation/ConversationHeader'; import {
ConversationHeader,
OutgoingCallButtonStyle,
} from '../../components/conversation/ConversationHeader';
import { getConversationSelector } from '../selectors/conversations'; import { getConversationSelector } from '../selectors/conversations';
import { StateType } from '../reducer'; import { StateType } from '../reducer';
import { CallMode } from '../../types/Calling'; import { CallMode } from '../../types/Calling';
import { getConversationCallMode } from '../ducks/conversations'; import {
ConversationType,
getConversationCallMode,
} from '../ducks/conversations';
import { getActiveCall } from '../ducks/calling'; import { getActiveCall } from '../ducks/calling';
import { getIntl } from '../selectors/user'; import { getIntl } from '../selectors/user';
import { missingCaseError } from '../../util/missingCaseError';
export interface OwnProps { export interface OwnProps {
id: string; id: string;
@ -32,17 +39,36 @@ export interface OwnProps {
onShowSafetyNumber: () => void; onShowSafetyNumber: () => void;
} }
const getOutgoingCallButtonStyle = (
conversation: ConversationType,
state: StateType
): OutgoingCallButtonStyle => {
if (getActiveCall(state.calling)) {
return OutgoingCallButtonStyle.None;
}
const conversationCallMode = getConversationCallMode(conversation);
switch (conversationCallMode) {
case CallMode.None:
return OutgoingCallButtonStyle.None;
case CallMode.Direct:
return OutgoingCallButtonStyle.Both;
case CallMode.Group:
if (!window.GROUP_CALLING) {
return OutgoingCallButtonStyle.None;
}
return OutgoingCallButtonStyle.JustVideo;
default:
throw missingCaseError(conversationCallMode);
}
};
const mapStateToProps = (state: StateType, ownProps: OwnProps) => { const mapStateToProps = (state: StateType, ownProps: OwnProps) => {
const conversation = getConversationSelector(state)(ownProps.id); const conversation = getConversationSelector(state)(ownProps.id);
if (!conversation) { if (!conversation) {
throw new Error('Could not find conversation'); throw new Error('Could not find conversation');
} }
const conversationCallMode = getConversationCallMode(conversation);
const conversationSupportsCalls =
conversationCallMode === CallMode.Direct ||
(conversationCallMode === CallMode.Group && window.GROUP_CALLING);
return { return {
...pick(conversation, [ ...pick(conversation, [
'acceptedMessageRequest', 'acceptedMessageRequest',
@ -66,7 +92,7 @@ const mapStateToProps = (state: StateType, ownProps: OwnProps) => {
]), ]),
i18n: getIntl(state), i18n: getIntl(state),
showBackButton: state.conversations.selectedConversationPanelDepth > 0, showBackButton: state.conversations.selectedConversationPanelDepth > 0,
showCallButtons: conversationSupportsCalls && !getActiveCall(state.calling), outgoingCallButtonStyle: getOutgoingCallButtonStyle(conversation, state),
}; };
}; };

View file

@ -14728,7 +14728,7 @@
"rule": "React-createRef", "rule": "React-createRef",
"path": "ts/components/conversation/ConversationHeader.js", "path": "ts/components/conversation/ConversationHeader.js",
"line": " this.menuTriggerRef = react_1.default.createRef();", "line": " this.menuTriggerRef = react_1.default.createRef();",
"lineNumber": 21, "lineNumber": 28,
"reasonCategory": "usageTrusted", "reasonCategory": "usageTrusted",
"updated": "2020-08-28T16:12:19.904Z", "updated": "2020-08-28T16:12:19.904Z",
"reasonDetail": "Used to reference popup menu" "reasonDetail": "Used to reference popup menu"
@ -14737,7 +14737,7 @@
"rule": "React-createRef", "rule": "React-createRef",
"path": "ts/components/conversation/ConversationHeader.tsx", "path": "ts/components/conversation/ConversationHeader.tsx",
"line": " this.menuTriggerRef = React.createRef();", "line": " this.menuTriggerRef = React.createRef();",
"lineNumber": 93, "lineNumber": 100,
"reasonCategory": "usageTrusted", "reasonCategory": "usageTrusted",
"updated": "2020-05-20T20:10:43.540Z", "updated": "2020-05-20T20:10:43.540Z",
"reasonDetail": "Used to reference popup menu" "reasonDetail": "Used to reference popup menu"