From c5633a24fe92f9983863d49682c91bb24fdd5682 Mon Sep 17 00:00:00 2001 From: Kerry Date: Tue, 3 May 2022 11:04:47 +0200 Subject: [PATCH] Live location sharing: don't group beacon info with room creation summary (#8468) * dont group beacon info with room creation summary Signed-off-by: Kerry Archibald * remove debugs Signed-off-by: Kerry Archibald * add comment Signed-off-by: Kerry Archibald * update comment Signed-off-by: Kerry Archibald --- src/components/structures/MessagePanel.tsx | 9 ++++++- .../structures/MessagePanel-test.js | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/components/structures/MessagePanel.tsx b/src/components/structures/MessagePanel.tsx index 38d18e92f7..5dd5ea0193 100644 --- a/src/components/structures/MessagePanel.tsx +++ b/src/components/structures/MessagePanel.tsx @@ -23,6 +23,7 @@ import { MatrixEvent } from 'matrix-js-sdk/src/models/event'; import { Relations } from "matrix-js-sdk/src/models/relations"; import { logger } from 'matrix-js-sdk/src/logger'; import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state"; +import { M_BEACON_INFO } from 'matrix-js-sdk/src/@types/beacon'; import shouldHideEvent from '../../shouldHideEvent'; import { wantsDateSeparator } from '../../DateUtils'; @@ -1079,7 +1080,7 @@ abstract class BaseGrouper { // Wrap initial room creation events into a GenericEventListSummary // Grouping only events sent by the same user that sent the `m.room.create` and only until -// the first non-state event or membership event which is not regarding the sender of the `m.room.create` event +// the first non-state event, beacon_info event or membership event which is not regarding the sender of the `m.room.create` event class CreationGrouper extends BaseGrouper { static canStartGroup = function(panel: MessagePanel, ev: MatrixEvent): boolean { return ev.getType() === EventType.RoomCreate; @@ -1098,9 +1099,15 @@ class CreationGrouper extends BaseGrouper { && (ev.getStateKey() !== createEvent.getSender() || ev.getContent()["membership"] !== "join")) { return false; } + // beacons are not part of room creation configuration + // should be shown in timeline + if (M_BEACON_INFO.matches(ev.getType())) { + return false; + } if (ev.isState() && ev.getSender() === createEvent.getSender()) { return true; } + return false; } diff --git a/test/components/structures/MessagePanel-test.js b/test/components/structures/MessagePanel-test.js index 4b2d549936..769e90c9bb 100644 --- a/test/components/structures/MessagePanel-test.js +++ b/test/components/structures/MessagePanel-test.js @@ -34,6 +34,11 @@ import * as TestUtilsMatrix from "../../test-utils"; import EventListSummary from "../../../src/components/views/elements/EventListSummary"; import GenericEventListSummary from "../../../src/components/views/elements/GenericEventListSummary"; import DateSeparator from "../../../src/components/views/messages/DateSeparator"; +import { makeBeaconInfoEvent } from '../../test-utils'; + +jest.mock('../../../src/utils/beacon', () => ({ + useBeacon: jest.fn(), +})); let client; const room = new Matrix.Room("!roomId:server_name"); @@ -481,6 +486,27 @@ describe('MessagePanel', function() { expect(summaryEventTiles.length).toEqual(tiles.length - 3); }); + it('should not collapse beacons as part of creation events', function() { + const [creationEvent] = mkCreationEvents(); + const beaconInfoEvent = makeBeaconInfoEvent( + creationEvent.getSender(), + creationEvent.getRoomId(), + { isLive: true }, + ); + const combinedEvents = [creationEvent, beaconInfoEvent]; + TestUtilsMatrix.upsertRoomStateEvents(room, combinedEvents); + const res = mount( + , + ); + + const summaryTiles = res.find(GenericEventListSummary); + const summaryTile = summaryTiles.at(0); + + const summaryEventTiles = summaryTile.find(UnwrappedEventTile); + // nothing in the summary + expect(summaryEventTiles.length).toEqual(0); + }); + it('should hide read-marker at the end of creation event summary', function() { const events = mkCreationEvents(); TestUtilsMatrix.upsertRoomStateEvents(room, events);