From 51ef148327949358391c2cd2d7c1a7b9d0cd53e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 29 Dec 2021 09:54:40 +0100 Subject: [PATCH 1/4] Don't show replaced calls in the timeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/messages/CallEvent.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/views/messages/CallEvent.tsx b/src/components/views/messages/CallEvent.tsx index d6df8c354e9..4cf9ee7e9dc 100644 --- a/src/components/views/messages/CallEvent.tsx +++ b/src/components/views/messages/CallEvent.tsx @@ -63,7 +63,7 @@ export default class CallEvent extends React.PureComponent { this.props.callEventGrouper.addListener(CallEventGrouperEvent.LengthChanged, this.onLengthChanged); this.resizeObserver = new ResizeObserver(this.resizeObserverCallback); - this.resizeObserver.observe(this.wrapperElement.current); + this.wrapperElement.current && this.resizeObserver.observe(this.wrapperElement.current); } componentWillUnmount() { @@ -248,13 +248,17 @@ export default class CallEvent extends React.PureComponent { ); } - render() { + public render(): JSX.Element { + const hangupReason = this.props.callEventGrouper.hangupReason; + + // If the call was replaced we don't render anything since we render the other call + if (hangupReason === CallErrorCode.Replaced) return null; + const event = this.props.mxEvent; const sender = event.sender ? event.sender.name : event.getSender(); const isVoice = this.props.callEventGrouper.isVoice; const callType = isVoice ? _t("Voice call") : _t("Video call"); const callState = this.state.callState; - const hangupReason = this.props.callEventGrouper.hangupReason; const content = this.renderContent(callState); const className = classNames("mx_CallEvent", { mx_CallEvent_voice: isVoice, From 429d8ad50c00384b60943f95c7982c7aaac6241f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 14 Jan 2022 16:42:02 +0100 Subject: [PATCH 2/4] Revert changes to CallEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/messages/CallEvent.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/views/messages/CallEvent.tsx b/src/components/views/messages/CallEvent.tsx index 4cf9ee7e9dc..2c09fa7fb0b 100644 --- a/src/components/views/messages/CallEvent.tsx +++ b/src/components/views/messages/CallEvent.tsx @@ -249,16 +249,12 @@ export default class CallEvent extends React.PureComponent { } public render(): JSX.Element { - const hangupReason = this.props.callEventGrouper.hangupReason; - - // If the call was replaced we don't render anything since we render the other call - if (hangupReason === CallErrorCode.Replaced) return null; - const event = this.props.mxEvent; const sender = event.sender ? event.sender.name : event.getSender(); const isVoice = this.props.callEventGrouper.isVoice; const callType = isVoice ? _t("Voice call") : _t("Video call"); const callState = this.state.callState; + const hangupReason = this.props.callEventGrouper.hangupReason; const content = this.renderContent(callState); const className = classNames("mx_CallEvent", { mx_CallEvent_voice: isVoice, From ea148a1c9df355c4a3ea025e334a2cbb0e9de8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 14 Jan 2022 17:20:43 +0100 Subject: [PATCH 3/4] Add option to force hide event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/utils/EventUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/EventUtils.ts b/src/utils/EventUtils.ts index f48e720e702..066e68857be 100644 --- a/src/utils/EventUtils.ts +++ b/src/utils/EventUtils.ts @@ -114,7 +114,7 @@ export function findEditableEvent({ } } -export function getEventDisplayInfo(mxEvent: MatrixEvent): { +export function getEventDisplayInfo(mxEvent: MatrixEvent, hideEvent?: boolean): { isInfoMessage: boolean; tileHandler: string; isBubbleMessage: boolean; @@ -161,7 +161,7 @@ export function getEventDisplayInfo(mxEvent: MatrixEvent): { // source tile when there's no regular tile for an event and also for // replace relations (which otherwise would display as a confusing // duplicate of the thing they are replacing). - if (SettingsStore.getValue("showHiddenEventsInTimeline") && !haveTileForEvent(mxEvent)) { + if ((hideEvent || !haveTileForEvent(mxEvent)) && SettingsStore.getValue("showHiddenEventsInTimeline")) { tileHandler = "messages.ViewSourceEvent"; isBubbleMessage = false; // Reuse info message avatar and sender profile styling From 7aa00f66f6403e90ba106efdbf82bd9b6b8e073d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 14 Jan 2022 17:20:58 +0100 Subject: [PATCH 4/4] Hide replaced calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/rooms/EventTile.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx index 17513dde766..556c2778188 100644 --- a/src/components/views/rooms/EventTile.tsx +++ b/src/components/views/rooms/EventTile.tsx @@ -25,6 +25,7 @@ import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread'; import { logger } from "matrix-js-sdk/src/logger"; import { NotificationCountType, Room } from 'matrix-js-sdk/src/models/room'; import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; +import { CallErrorCode } from "matrix-js-sdk/src/webrtc/call"; import ReplyChain from "../elements/ReplyChain"; import { _t } from '../../../languageHandler'; @@ -1071,6 +1072,18 @@ export default class EventTile extends React.Component { }); }; + /** + * In some cases we can't use shouldHideEvent() since whether or not we hide + * an event depends on other things that the event itself + * @returns {boolean} true if event should be hidden + */ + private shouldHideEvent(): boolean { + // If the call was replaced we don't render anything since we render the other call + if (this.props.callEventGrouper?.hangupReason === CallErrorCode.Replaced) return true; + + return false; + } + render() { const msgtype = this.props.mxEvent.getContent().msgtype; const eventType = this.props.mxEvent.getType() as EventType; @@ -1080,7 +1093,7 @@ export default class EventTile extends React.Component { isInfoMessage, isLeftAlignedBubbleMessage, noBubbleEvent, - } = getEventDisplayInfo(this.props.mxEvent); + } = getEventDisplayInfo(this.props.mxEvent, this.shouldHideEvent()); const { isQuoteExpanded } = this.state; // This shouldn't happen: the caller should check we support this type