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

Commit 494d9de

Browse files
authored
Fix buttons of widget in a room (#12288)
* Revert 3acd648 - Fix timeline position when moving to a room and coming back * Fix initialEventId
1 parent 28f7aac commit 494d9de

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

src/components/structures/RoomView.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
687687
newState.showRightPanel = false;
688688
}
689689

690-
const initialEventId = this.context.roomViewStore.getInitialEventId();
690+
const initialEventId = this.context.roomViewStore.getInitialEventId() ?? this.state.initialEventId;
691691
if (initialEventId) {
692692
let initialEvent = room?.findEventById(initialEventId);
693693
// The event does not exist in the current sync data
@@ -1430,6 +1430,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
14301430
tombstone: this.getRoomTombstone(room),
14311431
liveTimeline: room.getLiveTimeline(),
14321432
});
1433+
1434+
dis.dispatch<ActionPayload>({ action: Action.RoomLoaded });
14331435
};
14341436

14351437
private onRoomTimelineReset = (room?: Room): void => {

src/dispatcher/actions.ts

+5
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ export enum Action {
374374
*/
375375
OpenSpotlight = "open_spotlight",
376376

377+
/**
378+
* Fired when the room loaded.
379+
*/
380+
RoomLoaded = "room_loaded",
381+
377382
/**
378383
* Opens right panel with 3pid invite information
379384
*/

src/stores/RoomViewStore.tsx

+15-5
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ export class RoomViewStore extends EventEmitter {
382382
this.cancelAskToJoin(payload as CancelAskToJoinPayload);
383383
break;
384384
}
385+
case Action.RoomLoaded: {
386+
this.setViewRoomOpts();
387+
break;
388+
}
385389
}
386390
}
387391

@@ -446,10 +450,6 @@ export class RoomViewStore extends EventEmitter {
446450
return;
447451
}
448452

449-
const viewRoomOpts: ViewRoomOpts = { buttons: [] };
450-
// Allow modules to update the list of buttons for the room by updating `viewRoomOpts`.
451-
ModuleRunner.instance.invoke(RoomViewLifecycle.ViewRoom, viewRoomOpts, this.getRoomId());
452-
453453
const newState: Partial<State> = {
454454
roomId: payload.room_id,
455455
roomAlias: payload.room_alias ?? null,
@@ -472,7 +472,6 @@ export class RoomViewStore extends EventEmitter {
472472
(payload.room_id === this.state.roomId
473473
? this.state.viewingCall
474474
: CallStore.instance.getActiveCall(payload.room_id) !== null),
475-
viewRoomOpts,
476475
};
477476

478477
// Allow being given an event to be replied to when switching rooms but sanity check its for this room
@@ -837,4 +836,15 @@ export class RoomViewStore extends EventEmitter {
837836
public getViewRoomOpts(): ViewRoomOpts {
838837
return this.state.viewRoomOpts;
839838
}
839+
840+
/**
841+
* Invokes the view room lifecycle to set the view room options.
842+
*
843+
* @returns {void}
844+
*/
845+
private setViewRoomOpts(): void {
846+
const viewRoomOpts: ViewRoomOpts = { buttons: [] };
847+
ModuleRunner.instance.invoke(RoomViewLifecycle.ViewRoom, viewRoomOpts, this.getRoomId());
848+
this.setState({ viewRoomOpts });
849+
}
840850
}

test/components/structures/RoomView-test.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -711,4 +711,10 @@ describe("RoomView", () => {
711711

712712
await expect(prom).resolves.toEqual(expect.objectContaining({ room_id: room2.roomId }));
713713
});
714+
715+
it("fires Action.RoomLoaded", async () => {
716+
jest.spyOn(dis, "dispatch");
717+
await mountRoomView();
718+
expect(dis.dispatch).toHaveBeenCalledWith({ action: Action.RoomLoaded });
719+
});
714720
});

test/stores/RoomViewStore-test.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ describe("RoomViewStore", function () {
137137
await untilDispatch(Action.CancelAskToJoin, dis);
138138
};
139139

140+
const dispatchRoomLoaded = async () => {
141+
dis.dispatch({ action: Action.RoomLoaded });
142+
await untilDispatch(Action.RoomLoaded, dis);
143+
};
144+
140145
let roomViewStore: RoomViewStore;
141146
let slidingSyncManager: SlidingSyncManager;
142147
let dis: MatrixDispatcher;
@@ -423,10 +428,6 @@ describe("RoomViewStore", function () {
423428
});
424429
});
425430

426-
afterEach(() => {
427-
jest.spyOn(SettingsStore, "getValue").mockReset();
428-
});
429-
430431
it("subscribes to the room", async () => {
431432
const setRoomVisible = jest
432433
.spyOn(slidingSyncManager, "setRoomVisible")
@@ -600,10 +601,7 @@ describe("RoomViewStore", function () {
600601
opts.buttons = buttons;
601602
}
602603
});
603-
604-
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
605-
await untilDispatch(Action.ViewRoom, dis);
606-
604+
await dispatchRoomLoaded();
607605
expect(roomViewStore.getViewRoomOpts()).toEqual({ buttons });
608606
});
609607
});

0 commit comments

Comments
 (0)