Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Convert IncomingCallBox to a toast #6470

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions res/css/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
@import "./views/spaces/_SpacePublicShare.scss";
@import "./views/terms/_InlineTermsAgreement.scss";
@import "./views/toasts/_AnalyticsToast.scss";
@import "./views/toasts/_IncomingCallToast.scss";
@import "./views/toasts/_NonUrgentEchoFailureToast.scss";
@import "./views/verification/_VerificationShowSas.scss";
@import "./views/voip/_CallContainer.scss";
Expand Down
4 changes: 2 additions & 2 deletions res/css/structures/_ToastContainer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ limitations under the License.
margin: 0 4px;
grid-row: 2 / 4;
grid-column: 1;
background-color: $dark-panel-bg-color;
background-color: $toast-bg-color;
box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.5);
border-radius: 8px;
}
Expand All @@ -37,7 +37,7 @@ limitations under the License.
grid-row: 1 / 3;
grid-column: 1;
color: $primary-fg-color;
background-color: $dark-panel-bg-color;
background-color: $toast-bg-color;
box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.5);
border-radius: 8px;
overflow: hidden;
Expand Down
149 changes: 149 additions & 0 deletions res/css/views/toasts/_IncomingCallToast.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
Copyright 2020 The Matrix.org Foundation C.I.C.
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_IncomingCallToast {
display: flex;
flex-direction: row;
pointer-events: initial; // restore pointer events so the user can accept/decline

.mx_IncomingCallToast_content {
display: flex;
flex-direction: column;
margin-left: 8px;

.mx_CallEvent_caller {
font-weight: bold;
font-size: $font-15px;
line-height: $font-18px;

margin-top: 2px;
}

.mx_CallEvent_type {
font-size: $font-12px;
line-height: $font-15px;
color: $tertiary-fg-color;

margin-top: 4px;
margin-bottom: 6px;

display: flex;
flex-direction: row;
align-items: center;

.mx_CallEvent_type_icon {
height: 16px;
width: 16px;
margin-right: 6px;

&::before {
content: '';
position: absolute;
height: inherit;
width: inherit;
background-color: $tertiary-fg-color;
mask-repeat: no-repeat;
mask-size: contain;
}
}
}

&.mx_IncomingCallToast_content_voice {
.mx_CallEvent_type .mx_CallEvent_type_icon::before,
.mx_IncomingCallToast_buttons .mx_IncomingCallToast_button_accept span::before {
mask-image: url('$(res)/img/element-icons/call/voice-call.svg');
}
}

&.mx_IncomingCallToast_content_video {
.mx_CallEvent_type .mx_CallEvent_type_icon::before,
.mx_IncomingCallToast_buttons .mx_IncomingCallToast_button_accept span::before {
mask-image: url('$(res)/img/element-icons/call/video-call.svg');
}
}

.mx_IncomingCallToast_buttons {
margin-top: 8px;
display: flex;
flex-direction: row;
gap: 12px;

.mx_IncomingCallToast_button {
height: 24px;
padding: 0px 8px;
flex-shrink: 0;
flex-grow: 1;
margin-right: 0;
font-size: $font-15px;
line-height: $font-24px;

span {
padding: 8px 0;
display: flex;
align-items: center;

&::before {
content: '';
display: inline-block;
background-color: $button-fg-color;
mask-position: center;
mask-repeat: no-repeat;
margin-right: 8px;
}
}

&.mx_IncomingCallToast_button_accept span::before {
mask-size: 13px;
width: 13px;
height: 13px;
}

&.mx_IncomingCallToast_button_decline span::before {
mask-image: url('$(res)/img/element-icons/call/hangup.svg');
mask-size: 16px;
width: 16px;
height: 16px;
}
}
}
}

.mx_IncomingCallToast_iconButton {
display: flex;
height: 20px;
width: 20px;

&::before {
content: '';

height: inherit;
width: inherit;
background-color: $tertiary-fg-color;
mask-repeat: no-repeat;
mask-size: contain;
mask-position: center;
}
}

.mx_IncomingCallToast_silence::before {
mask-image: url('$(res)/img/voip/silence.svg');
}

.mx_IncomingCallToast_unSilence::before {
mask-image: url('$(res)/img/voip/un-silence.svg');
}
}
80 changes: 0 additions & 80 deletions res/css/views/voip/_CallContainer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,84 +43,4 @@ limitations under the License.
.mx_AppTile_persistedWrapper div {
min-width: 350px;
}

.mx_IncomingCallBox {
min-width: 250px;
background-color: $voipcall-plinth-color;
padding: 8px;
box-shadow: 0px 14px 24px rgba(0, 0, 0, 0.08);
border-radius: 8px;

pointer-events: initial; // restore pointer events so the user can accept/decline
cursor: pointer;

.mx_IncomingCallBox_CallerInfo {
display: flex;
direction: row;

img, .mx_BaseAvatar_initial {
margin: 8px;
}

> div {
display: flex;
flex-direction: column;

justify-content: center;
}

h1, p {
margin: 0px;
padding: 0px;
font-size: $font-14px;
line-height: $font-16px;
}

h1 {
font-weight: bold;
}
}

.mx_IncomingCallBox_buttons {
padding: 8px;
display: flex;
flex-direction: row;

> .mx_IncomingCallBox_spacer {
width: 8px;
}

> * {
flex-shrink: 0;
flex-grow: 1;
margin-right: 0;
font-size: $font-15px;
line-height: $font-24px;
}
}

.mx_IncomingCallBox_iconButton {
position: absolute;
right: 8px;

&::before {
content: '';

height: 20px;
width: 20px;
background-color: $icon-button-color;
mask-repeat: no-repeat;
mask-size: contain;
mask-position: center;
}
}

.mx_IncomingCallBox_silence::before {
mask-image: url('$(res)/img/voip/silence.svg');
}

.mx_IncomingCallBox_unSilence::before {
mask-image: url('$(res)/img/voip/un-silence.svg');
}
}
}
2 changes: 1 addition & 1 deletion res/css/views/voip/_CallView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ limitations under the License.
.mx_CallView_pip {
width: 320px;
padding-bottom: 8px;
background-color: $voipcall-plinth-color;
background-color: $toast-bg-color;
box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.20);
border-radius: 8px;

Expand Down
4 changes: 2 additions & 2 deletions res/themes/dark/css/_dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ $eventtile-meta-color: $roomtopic-color;
$header-divider-color: $header-panel-text-primary-color;
$composer-e2e-icon-color: $header-panel-text-primary-color;

// this probably shouldn't have it's own colour
$voipcall-plinth-color: #394049;
$quinary-content-color: #394049;
$toast-bg-color: $quinary-content-color;

// ********************

Expand Down
4 changes: 2 additions & 2 deletions res/themes/legacy-dark/css/_legacy-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ $eventtile-meta-color: $roomtopic-color;
$header-divider-color: $header-panel-text-primary-color;
$composer-e2e-icon-color: $header-panel-text-primary-color;

// this probably shouldn't have it's own colour
$voipcall-plinth-color: #394049;
$quinary-content-color: #394049;
$toast-bg-color: $quinary-content-color;

// ********************

Expand Down
2 changes: 1 addition & 1 deletion res/themes/legacy-light/css/_legacy-light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ $eventtile-meta-color: $roomtopic-color;
$composer-e2e-icon-color: #91a1c0;
$header-divider-color: #91a1c0;

// this probably shouldn't have it's own colour
$toast-bg-color: $system-light;
$voipcall-plinth-color: $system-light;

// ********************
Expand Down
2 changes: 1 addition & 1 deletion res/themes/light/css/_light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ $eventtile-meta-color: $roomtopic-color;
$composer-e2e-icon-color: #91A1C0;
$header-divider-color: #91A1C0;

// this probably shouldn't have it's own colour
$toast-bg-color: $system-light;
$voipcall-plinth-color: $system-light;

// ********************
Expand Down
16 changes: 16 additions & 0 deletions src/CallHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ import { randomUppercaseString, randomLowercaseString } from "matrix-js-sdk/src/
import EventEmitter from 'events';
import SdkConfig from './SdkConfig';
import { ensureDMExists, findDMForUser } from './createRoom';
import { getIncomingCallToastKey } from './toasts/IncomingCallToast';
import ToastStore from './stores/ToastStore';
import IncomingCallToast from "./toasts/IncomingCallToast";

export const PROTOCOL_PSTN = 'm.protocol.pstn';
export const PROTOCOL_PSTN_PREFIXED = 'im.vector.protocol.pstn';
Expand Down Expand Up @@ -624,6 +627,19 @@ export default class CallHandler extends EventEmitter {
`Call state in ${mappedRoomId} changed to ${status}`,
);

const toastKey = getIncomingCallToastKey(call.callId);
if (status === CallState.Ringing) {
ToastStore.sharedInstance().addOrReplaceToast({
key: toastKey,
priority: 100,
component: IncomingCallToast,
bodyClassName: "mx_IncomingCallToast",
props: { call },
});
} else {
ToastStore.sharedInstance().dismissToast(toastKey);
}

dis.dispatch({
action: 'call_state',
room_id: mappedRoomId,
Expand Down
39 changes: 25 additions & 14 deletions src/components/structures/ToastContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,39 @@ export default class ToastContainer extends React.Component<{}, IState> {
let containerClasses;
if (totalCount !== 0) {
const topToast = this.state.toasts[0];
const { title, icon, key, component, className, props } = topToast;
const toastClasses = classNames("mx_Toast_toast", {
const { title, icon, key, component, className, bodyClassName, props } = topToast;
const bodyClasses = classNames("mx_Toast_body", bodyClassName);
const toastClasses = classNames("mx_Toast_toast", className, {
"mx_Toast_hasIcon": icon,
[`mx_Toast_icon_${icon}`]: icon,
}, className);
});
const toastProps = Object.assign({}, props, {
key,
toastKey: key,
});
const content = React.createElement(component, toastProps);

let countIndicator;
if (isStacked || this.state.countSeen > 0) {
if (title && isStacked || this.state.countSeen > 0) {
countIndicator = ` (${this.state.countSeen + 1}/${this.state.countSeen + totalCount})`;
}

const toastProps = Object.assign({}, props, {
key,
toastKey: key,
});
toast = (<div className={toastClasses}>
<div className="mx_Toast_title">
<h2>{ title }</h2>
<span>{ countIndicator }</span>
let titleElement;
if (title) {
titleElement = (
<div className="mx_Toast_title">
<h2>{ title }</h2>
<span>{ countIndicator }</span>
</div>
);
}

toast = (
<div className={toastClasses}>
{ titleElement }
<div className={bodyClasses}>{ content }</div>
</div>
<div className="mx_Toast_body">{ React.createElement(component, toastProps) }</div>
</div>);
);

containerClasses = classNames("mx_ToastContainer", {
"mx_ToastContainer_stacked": isStacked,
Expand Down
Loading