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

Commit 7ce0950

Browse files
committed
Implement MSC3946 for AdvancedRoomSettingsTab
1 parent 06f5b99 commit 7ce0950

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

src/components/views/settings/tabs/room/AdvancedRoomSettingsTab.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import dis from "../../../../../dispatcher/dispatcher";
2626
import { Action } from "../../../../../dispatcher/actions";
2727
import CopyableText from "../../../elements/CopyableText";
2828
import { ViewRoomPayload } from "../../../../../dispatcher/payloads/ViewRoomPayload";
29+
import SettingsStore from "../../../../../settings/SettingsStore";
2930

3031
interface IProps {
3132
roomId: string;
@@ -49,6 +50,8 @@ export default class AdvancedRoomSettingsTab extends React.Component<IProps, ISt
4950
public constructor(props, context) {
5051
super(props, context);
5152

53+
const msc3946ProcessDynamicPredecessor = SettingsStore.getValue("feature_dynamic_room_predecessors");
54+
5255
this.state = {
5356
// This is eventually set to the value of room.getRecommendedVersion()
5457
upgradeRecommendation: null,
@@ -60,11 +63,10 @@ export default class AdvancedRoomSettingsTab extends React.Component<IProps, ISt
6063
const tombstone = room.currentState.getStateEvents(EventType.RoomTombstone, "");
6164

6265
const additionalStateChanges: Partial<IState> = {};
63-
const createEvent = room.currentState.getStateEvents(EventType.RoomCreate, "");
64-
const predecessor = createEvent ? createEvent.getContent().predecessor : null;
65-
if (predecessor && predecessor.room_id) {
66-
additionalStateChanges.oldRoomId = predecessor.room_id;
67-
additionalStateChanges.oldEventId = predecessor.event_id;
66+
const predecessor = room.findPredecessor(msc3946ProcessDynamicPredecessor);
67+
if (predecessor) {
68+
additionalStateChanges.oldRoomId = predecessor.roomId;
69+
additionalStateChanges.oldEventId = predecessor.eventId;
6870
}
6971

7072
this.setState({

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@
955955
"New group call experience": "New group call experience",
956956
"Live Location Sharing": "Live Location Sharing",
957957
"Temporary implementation. Locations persist in room history.": "Temporary implementation. Locations persist in room history.",
958+
"Dynamic room predecessors": "Dynamic room predecessors",
959+
"Enable MSC3946 (to support late-arriving room archives)": "Enable MSC3946 (to support late-arriving room archives)",
958960
"Favourite Messages": "Favourite Messages",
959961
"Under active development.": "Under active development.",
960962
"Force 15s voice broadcast chunk length": "Force 15s voice broadcast chunk length",

src/settings/Settings.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,15 @@ export const SETTINGS: { [setting: string]: ISetting } = {
439439
shouldWarn: true,
440440
default: false,
441441
},
442+
"feature_dynamic_room_predecessors": {
443+
isFeature: true,
444+
labsGroup: LabGroup.Rooms,
445+
supportedLevels: LEVELS_FEATURE,
446+
displayName: _td("Dynamic room predecessors"),
447+
description: _td("Enable MSC3946 (to support late-arriving room archives)"),
448+
shouldWarn: true,
449+
default: false,
450+
},
442451
"feature_favourite_messages": {
443452
isFeature: true,
444453
labsGroup: LabGroup.Messaging,

test/components/views/settings/tabs/room/AdvancedRoomSettingsTab-test.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { mkEvent, mkStubRoom, stubClient } from "../../../../../test-utils";
2626
import dis from "../../../../../../src/dispatcher/dispatcher";
2727
import { Action } from "../../../../../../src/dispatcher/actions";
2828
import { MatrixClientPeg } from "../../../../../../src/MatrixClientPeg";
29+
import SettingsStore from "../../../../../../src/settings/SettingsStore";
2930

3031
jest.mock("../../../../../../src/dispatcher/dispatcher");
3132

@@ -43,6 +44,12 @@ describe("AdvancedRoomSettingsTab", () => {
4344
cli = MatrixClientPeg.get();
4445
room = mkStubRoom(roomId, "test room", cli);
4546
mocked(cli.getRoom).mockReturnValue(room);
47+
mocked(dis.dispatch).mockReset();
48+
mocked(room.findPredecessor).mockImplementation((msc3946: boolean) =>
49+
msc3946
50+
? { roomId: "old_room_id_via_predecessor", eventId: null }
51+
: { roomId: "old_room_id", eventId: "tombstone_event_id" },
52+
);
4653
});
4754

4855
it("should render as expected", () => {
@@ -71,6 +78,17 @@ describe("AdvancedRoomSettingsTab", () => {
7178
room: room.roomId,
7279
});
7380

81+
// Because we're mocking Room.findPredecessor, it may not be necessary
82+
// to provide the actual event here, but we do need the create event,
83+
// and in future this may be needed, so included for symmetry.
84+
const predecessorEvent = mkEvent({
85+
event: true,
86+
user: "@a:b.com",
87+
type: EventType.RoomPredecessor,
88+
content: { predecessor_room_id: "old_room_id_via_predecessor" },
89+
room: room.roomId,
90+
});
91+
7492
type GetStateEvents2Args = (eventType: EventType | string, stateKey: string) => MatrixEvent | null;
7593

7694
const getStateEvents = jest.spyOn(
@@ -82,6 +100,8 @@ describe("AdvancedRoomSettingsTab", () => {
82100
switch (eventType) {
83101
case EventType.RoomCreate:
84102
return createEvent;
103+
case EventType.RoomPredecessor:
104+
return predecessorEvent;
85105
default:
86106
return null;
87107
}
@@ -101,4 +121,26 @@ describe("AdvancedRoomSettingsTab", () => {
101121
metricsViaKeyboard: false,
102122
});
103123
});
124+
125+
describe("When MSC3946 support is enabled", () => {
126+
beforeEach(() => {
127+
jest.spyOn(SettingsStore, "getValue")
128+
.mockReset()
129+
.mockImplementation((settingName) => settingName === "feature_dynamic_room_predecessors");
130+
});
131+
132+
it("should link to predecessor room via MSC3946 if enabled", async () => {
133+
mockStateEvents(room);
134+
const tab = renderTab();
135+
const link = await tab.findByText("View older messages in test room.");
136+
fireEvent.click(link);
137+
expect(dis.dispatch).toHaveBeenCalledWith({
138+
action: Action.ViewRoom,
139+
event_id: null,
140+
room_id: "old_room_id_via_predecessor",
141+
metricsTrigger: "WebPredecessorSettings",
142+
metricsViaKeyboard: false,
143+
});
144+
});
145+
});
104146
});

0 commit comments

Comments
 (0)