From 5a284b62ebc243505f8ae8cf38080a0f39d7e707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 6 Aug 2021 13:57:27 +0200 Subject: [PATCH 1/4] Add formatCallTime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/DateUtils.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/DateUtils.ts b/src/DateUtils.ts index e4a1175d889..9d4b9d5f57e 100644 --- a/src/DateUtils.ts +++ b/src/DateUtils.ts @@ -123,6 +123,19 @@ export function formatTime(date: Date, showTwelveHour = false): string { return pad(date.getHours()) + ':' + pad(date.getMinutes()); } +export function formatCallTime(date: Date): string { + const hours = date.getUTCHours(); + const minutes = date.getUTCMinutes(); + const seconds = date.getUTCSeconds(); + + let output = ""; + if (hours) output += `${hours}h `; + if (minutes || output) output += `${minutes}m `; + if (seconds || output) output += `${seconds}s`; + + return output; +} + const MILLIS_IN_DAY = 86400000; export function wantsDateSeparator(prevEventDate: Date, nextEventDate: Date): boolean { if (!nextEventDate || !prevEventDate) { From c1449ff01a747494a4472744033c1a8034b820ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 6 Aug 2021 13:59:26 +0200 Subject: [PATCH 2/4] Show call length MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/structures/CallEventGrouper.ts | 9 +++++++++ src/components/views/messages/CallEvent.tsx | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/structures/CallEventGrouper.ts b/src/components/structures/CallEventGrouper.ts index ce3b5308585..861c978bb09 100644 --- a/src/components/structures/CallEventGrouper.ts +++ b/src/components/structures/CallEventGrouper.ts @@ -61,6 +61,10 @@ export default class CallEventGrouper extends EventEmitter { return [...this.events].find((event) => event.getType() === EventType.CallReject); } + private get selectAnswer(): MatrixEvent { + return [...this.events].find((event) => event.getType() === EventType.CallSelectAnswer); + } + public get isVoice(): boolean { const invite = this.invite; if (!invite) return; @@ -82,6 +86,11 @@ export default class CallEventGrouper extends EventEmitter { return Boolean(this.reject); } + public get length(): Date { + if (!this.hangup || !this.selectAnswer) return; + return new Date(this.hangup.getDate().getTime() - this.selectAnswer.getDate().getTime()); + } + /** * Returns true if there are only events from the other side - we missed the call */ diff --git a/src/components/views/messages/CallEvent.tsx b/src/components/views/messages/CallEvent.tsx index a204907caa5..107832bfc29 100644 --- a/src/components/views/messages/CallEvent.tsx +++ b/src/components/views/messages/CallEvent.tsx @@ -25,6 +25,7 @@ import { CallErrorCode, CallState } from 'matrix-js-sdk/src/webrtc/call'; import InfoTooltip, { InfoTooltipKind } from '../elements/InfoTooltip'; import classNames from 'classnames'; import AccessibleTooltipButton from '../elements/AccessibleTooltipButton'; +import { formatCallTime } from "../../../DateUtils"; interface IProps { mxEvent: MatrixEvent; @@ -131,9 +132,14 @@ export default class CallEvent extends React.Component { // https://github.com/vector-im/riot-android/issues/2623 // Also the correct hangup code as of VoIP v1 (with underscore) // Also, if we don't have a reason + const length = this.props.callEventGrouper.length; + let text = _t("Call ended"); + if (length) { + text += " • " + formatCallTime(length); + } return (
- { _t("Call ended") } + { text }
); } else if (hangupReason === CallErrorCode.InviteTimeout) { From 43325eb866f16793882a8cc4019e31be4b4cf2a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 6 Aug 2021 14:24:14 +0200 Subject: [PATCH 3/4] date -> delta MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/DateUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DateUtils.ts b/src/DateUtils.ts index 9d4b9d5f57e..e8b81ca315a 100644 --- a/src/DateUtils.ts +++ b/src/DateUtils.ts @@ -123,10 +123,10 @@ export function formatTime(date: Date, showTwelveHour = false): string { return pad(date.getHours()) + ':' + pad(date.getMinutes()); } -export function formatCallTime(date: Date): string { - const hours = date.getUTCHours(); - const minutes = date.getUTCMinutes(); - const seconds = date.getUTCSeconds(); +export function formatCallTime(delta: Date): string { + const hours = delta.getUTCHours(); + const minutes = delta.getUTCMinutes(); + const seconds = delta.getUTCSeconds(); let output = ""; if (hours) output += `${hours}h `; From 8368aa13ca6eb0450a78b85f32c7e2ea7faf4782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 6 Aug 2021 14:38:53 +0200 Subject: [PATCH 4/4] length -> duration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/structures/CallEventGrouper.ts | 2 +- src/components/views/messages/CallEvent.tsx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/structures/CallEventGrouper.ts b/src/components/structures/CallEventGrouper.ts index 861c978bb09..2b18a4316c5 100644 --- a/src/components/structures/CallEventGrouper.ts +++ b/src/components/structures/CallEventGrouper.ts @@ -86,7 +86,7 @@ export default class CallEventGrouper extends EventEmitter { return Boolean(this.reject); } - public get length(): Date { + public get duration(): Date { if (!this.hangup || !this.selectAnswer) return; return new Date(this.hangup.getDate().getTime() - this.selectAnswer.getDate().getTime()); } diff --git a/src/components/views/messages/CallEvent.tsx b/src/components/views/messages/CallEvent.tsx index 107832bfc29..bc868c35b31 100644 --- a/src/components/views/messages/CallEvent.tsx +++ b/src/components/views/messages/CallEvent.tsx @@ -132,10 +132,10 @@ export default class CallEvent extends React.Component { // https://github.com/vector-im/riot-android/issues/2623 // Also the correct hangup code as of VoIP v1 (with underscore) // Also, if we don't have a reason - const length = this.props.callEventGrouper.length; + const duration = this.props.callEventGrouper.duration; let text = _t("Call ended"); - if (length) { - text += " • " + formatCallTime(length); + if (duration) { + text += " • " + formatCallTime(duration); } return (