From 7c20eb9b7461079ebc4604e90f4cafa50fb5943e Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 28 Jan 2022 17:05:57 +0000 Subject: [PATCH] Put call on hold when transfer dialog is opened (#7669) And take it off hold if the dialog is cancelled. Also changes the onFinished signature of invitedialog which claimed to return an array of strings but never did, so now it just returns a boolean. --- src/CallHandler.tsx | 18 +++++++++++++++++ .../views/context_menus/CallContextMenu.tsx | 7 +------ src/components/views/dialogs/InviteDialog.tsx | 20 ++++++++++--------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/CallHandler.tsx b/src/CallHandler.tsx index 4cf6561fc2..0af6dedcd2 100644 --- a/src/CallHandler.tsx +++ b/src/CallHandler.tsx @@ -39,6 +39,7 @@ import { WidgetType } from "./widgets/WidgetType"; import { SettingLevel } from "./settings/SettingLevel"; import QuestionDialog from "./components/views/dialogs/QuestionDialog"; import ErrorDialog from "./components/views/dialogs/ErrorDialog"; +import InviteDialog, { KIND_CALL_TRANSFER } from "./components/views/dialogs/InviteDialog"; import WidgetStore from "./stores/WidgetStore"; import { WidgetMessagingStore } from "./stores/widgets/WidgetMessagingStore"; import { ElementWidgetActions } from "./stores/widgets/ElementWidgetActions"; @@ -1100,6 +1101,23 @@ export default class CallHandler extends EventEmitter { }); } + /* + * Shows the transfer dialog for a call, signalling to the other end that + * a transfer is about to happen + */ + public showTransferDialog(call: MatrixCall): void { + call.setRemoteOnHold(true); + const { finished } = Modal.createTrackedDialog( + 'Transfer Call', '', InviteDialog, { kind: KIND_CALL_TRANSFER, call }, + /*className=*/"mx_InviteDialog_transferWrapper", /*isPriority=*/false, /*isStatic=*/true, + ); + finished.then((results: boolean[]) => { + if (results.length === 0 || results[0] === false) { + call.setRemoteOnHold(false); + } + }); + } + private addCallForRoom(roomId: string, call: MatrixCall, changedRooms = false): void { if (this.calls.has(roomId)) { logger.log(`Couldn't add call to room ${roomId}: already have a call for this room`); diff --git a/src/components/views/context_menus/CallContextMenu.tsx b/src/components/views/context_menus/CallContextMenu.tsx index 931bddf335..ec835d1e31 100644 --- a/src/components/views/context_menus/CallContextMenu.tsx +++ b/src/components/views/context_menus/CallContextMenu.tsx @@ -21,8 +21,6 @@ import { MatrixCall } from 'matrix-js-sdk/src/webrtc/call'; import { _t } from '../../../languageHandler'; import ContextMenu, { IProps as IContextMenuProps, MenuItem } from '../../structures/ContextMenu'; import CallHandler from '../../../CallHandler'; -import InviteDialog, { KIND_CALL_TRANSFER } from '../dialogs/InviteDialog'; -import Modal from '../../../Modal'; import { replaceableComponent } from "../../../utils/replaceableComponent"; interface IProps extends IContextMenuProps { @@ -52,10 +50,7 @@ export default class CallContextMenu extends React.Component { }; onTransferClick = () => { - Modal.createTrackedDialog( - 'Transfer Call', '', InviteDialog, { kind: KIND_CALL_TRANSFER, call: this.props.call }, - /*className=*/"mx_InviteDialog_transferWrapper", /*isPriority=*/false, /*isStatic=*/true, - ); + CallHandler.instance.showTransferDialog(this.props.call); this.props.onFinished(); }; diff --git a/src/components/views/dialogs/InviteDialog.tsx b/src/components/views/dialogs/InviteDialog.tsx index 4cfc532703..8cc04d8628 100644 --- a/src/components/views/dialogs/InviteDialog.tsx +++ b/src/components/views/dialogs/InviteDialog.tsx @@ -352,8 +352,10 @@ class DMRoomTile extends React.PureComponent { } interface IInviteDialogProps { - // Takes an array of user IDs/emails to invite. - onFinished: (toInvite?: string[]) => void; + // Takes a boolean which is true if a user / users were invited / + // a call transfer was initiated or false if the dialog was cancelled + // with no action taken. + onFinished: (success: boolean) => void; // The kind of invite being performed. Assumed to be KIND_DM if // not provided. @@ -685,7 +687,7 @@ export default class InviteDialog extends React.PureComponent { @@ -824,7 +826,7 @@ export default class InviteDialog extends React.PureComponent { - this.props.onFinished([]); + this.props.onFinished(false); }; private updateSuggestions = async (term) => { @@ -1086,11 +1088,11 @@ export default class InviteDialog extends React.PureComponent { e.preventDefault(); dis.fire(Action.ViewUserSettings); - this.props.onFinished(); + this.props.onFinished(false); }; private onCommunityInviteClick = (e) => { - this.props.onFinished(); + this.props.onFinished(false); showCommunityInviteDialog(CommunityPrototypeStore.instance.getSelectedCommunityId()); };