From b871456681b68c17daa128fb876a88d3e614cc17 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Wed, 12 Oct 2022 17:58:57 +0200 Subject: [PATCH] Hide voice broadcast chunks (#9397) --- src/events/EventTileFactory.tsx | 6 +++ src/voice-broadcast/index.ts | 1 + test/events/EventTileFactory-test.ts | 60 ++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/events/EventTileFactory.tsx b/src/events/EventTileFactory.tsx index 9ff402f45d..89bf9cbd73 100644 --- a/src/events/EventTileFactory.tsx +++ b/src/events/EventTileFactory.tsx @@ -46,6 +46,7 @@ import ViewSourceEvent from "../components/views/messages/ViewSourceEvent"; import { shouldDisplayAsBeaconTile } from "../utils/beacon/timeline"; import { shouldDisplayAsVoiceBroadcastTile } from "../voice-broadcast/utils/shouldDisplayAsVoiceBroadcastTile"; import { ElementCall } from "../models/Call"; +import { VoiceBroadcastChunkEventType } from "../voice-broadcast"; // Subset of EventTile's IProps plus some mixins export interface EventTileTypeProps { @@ -252,6 +253,11 @@ export function pickFactory( return noEventFactoryFactory(); } + if (mxEvent.getContent()[VoiceBroadcastChunkEventType]) { + // hide voice broadcast chunks + return noEventFactoryFactory(); + } + return EVENT_TILE_TYPES.get(evType) ?? noEventFactoryFactory(); } diff --git a/src/voice-broadcast/index.ts b/src/voice-broadcast/index.ts index 81f47a29ba..73f428fd34 100644 --- a/src/voice-broadcast/index.ts +++ b/src/voice-broadcast/index.ts @@ -32,6 +32,7 @@ export * from "./utils/shouldDisplayAsVoiceBroadcastTile"; export * from "./utils/startNewVoiceBroadcastRecording"; export const VoiceBroadcastInfoEventType = "io.element.voice_broadcast_info"; +export const VoiceBroadcastChunkEventType = "io.element.voice_broadcast_chunk"; export enum VoiceBroadcastInfoState { Started = "started", diff --git a/test/events/EventTileFactory-test.ts b/test/events/EventTileFactory-test.ts index ebda574dfc..9625ffe448 100644 --- a/test/events/EventTileFactory-test.ts +++ b/test/events/EventTileFactory-test.ts @@ -1,12 +1,9 @@ /* Copyright 2022 The Matrix.org Foundation C.I.C. - 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. @@ -14,23 +11,70 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix"; +import { EventType, MatrixClient, MatrixEvent, MsgType } from "matrix-js-sdk/src/matrix"; import { JSONEventFactory, pickFactory } from "../../src/events/EventTileFactory"; -import { createTestClient } from "../test-utils"; +import { VoiceBroadcastChunkEventType } from "../../src/voice-broadcast"; +import { createTestClient, mkEvent } from "../test-utils"; const roomId = "!room:example.com"; describe("pickFactory", () => { + let voiceBroadcastChunkEvent: MatrixEvent; + let audioMessageEvent: MatrixEvent; + let client: MatrixClient; + + beforeAll(() => { + client = createTestClient(); + voiceBroadcastChunkEvent = mkEvent({ + event: true, + type: EventType.RoomMessage, + user: client.getUserId(), + room: roomId, + content: { + msgtype: MsgType.Audio, + [VoiceBroadcastChunkEventType]: {}, + }, + }); + audioMessageEvent = mkEvent({ + event: true, + type: EventType.RoomMessage, + user: client.getUserId(), + room: roomId, + content: { + msgtype: MsgType.Audio, + }, + }); + }); + it("should return JSONEventFactory for a no-op m.room.power_levels event", () => { - const cli = createTestClient(); const event = new MatrixEvent({ type: EventType.RoomPowerLevels, state_key: "", content: {}, - sender: cli.getUserId(), + sender: client.getUserId(), room_id: roomId, }); - expect(pickFactory(event, cli, true)).toBe(JSONEventFactory); + expect(pickFactory(event, client, true)).toBe(JSONEventFactory); + }); + + describe("when showing hidden events", () => { + it("should return a function for a voice broadcast event", () => { + expect(pickFactory(voiceBroadcastChunkEvent, client, true)).toBeInstanceOf(Function); + }); + + it("should return a function for an audio message event", () => { + expect(pickFactory(audioMessageEvent, client, true)).toBeInstanceOf(Function); + }); + }); + + describe("when not showing hidden events", () => { + it("should return undefined for a voice broadcast event", () => { + expect(pickFactory(voiceBroadcastChunkEvent, client, false)).toBeUndefined(); + }); + + it("should return a function for an audio message event", () => { + expect(pickFactory(audioMessageEvent, client, false)).toBeInstanceOf(Function); + }); }); });