diff --git a/src/CallHandler.tsx b/src/CallHandler.tsx index 4cf6561fc29..0af6dedcd26 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 931bddf335a..ec835d1e312 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 4cfc5327030..8cc04d8628c 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()); };