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

Fix buttons of widget in a room #12288

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
newState.showRightPanel = false;
}

const initialEventId = this.context.roomViewStore.getInitialEventId();
const initialEventId = this.context.roomViewStore.getInitialEventId() ?? this.state.initialEventId;
if (initialEventId) {
let initialEvent = room?.findEventById(initialEventId);
// The event does not exist in the current sync data
Expand Down Expand Up @@ -1430,6 +1430,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
tombstone: this.getRoomTombstone(room),
liveTimeline: room.getLiveTimeline(),
});

dis.dispatch<ActionPayload>({ action: Action.RoomLoaded });
};

private onRoomTimelineReset = (room?: Room): void => {
Expand Down
5 changes: 5 additions & 0 deletions src/dispatcher/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ export enum Action {
*/
OpenSpotlight = "open_spotlight",

/**
* Fired when the room loaded.
*/
RoomLoaded = "room_loaded",

/**
* Opens right panel with 3pid invite information
*/
Expand Down
20 changes: 15 additions & 5 deletions src/stores/RoomViewStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ export class RoomViewStore extends EventEmitter {
this.cancelAskToJoin(payload as CancelAskToJoinPayload);
break;
}
case Action.RoomLoaded: {
this.setViewRoomOpts();
break;
}
}
}

Expand Down Expand Up @@ -446,10 +450,6 @@ export class RoomViewStore extends EventEmitter {
return;
}

const viewRoomOpts: ViewRoomOpts = { buttons: [] };
// Allow modules to update the list of buttons for the room by updating `viewRoomOpts`.
ModuleRunner.instance.invoke(RoomViewLifecycle.ViewRoom, viewRoomOpts, this.getRoomId());

const newState: Partial<State> = {
roomId: payload.room_id,
roomAlias: payload.room_alias ?? null,
Expand All @@ -472,7 +472,6 @@ export class RoomViewStore extends EventEmitter {
(payload.room_id === this.state.roomId
? this.state.viewingCall
: CallStore.instance.getActiveCall(payload.room_id) !== null),
viewRoomOpts,
};

// Allow being given an event to be replied to when switching rooms but sanity check its for this room
Expand Down Expand Up @@ -837,4 +836,15 @@ export class RoomViewStore extends EventEmitter {
public getViewRoomOpts(): ViewRoomOpts {
return this.state.viewRoomOpts;
}

/**
* Invokes the view room lifecycle to set the view room options.
*
* @returns {void}
*/
private setViewRoomOpts(): void {
const viewRoomOpts: ViewRoomOpts = { buttons: [] };
ModuleRunner.instance.invoke(RoomViewLifecycle.ViewRoom, viewRoomOpts, this.getRoomId());
this.setState({ viewRoomOpts });
}
}
6 changes: 6 additions & 0 deletions test/components/structures/RoomView-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -711,4 +711,10 @@ describe("RoomView", () => {

await expect(prom).resolves.toEqual(expect.objectContaining({ room_id: room2.roomId }));
});

it("fires Action.RoomLoaded", async () => {
jest.spyOn(dis, "dispatch");
await mountRoomView();
expect(dis.dispatch).toHaveBeenCalledWith({ action: Action.RoomLoaded });
});
});
14 changes: 6 additions & 8 deletions test/stores/RoomViewStore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ describe("RoomViewStore", function () {
await untilDispatch(Action.CancelAskToJoin, dis);
};

const dispatchRoomLoaded = async () => {
dis.dispatch({ action: Action.RoomLoaded });
await untilDispatch(Action.RoomLoaded, dis);
};

let roomViewStore: RoomViewStore;
let slidingSyncManager: SlidingSyncManager;
let dis: MatrixDispatcher;
Expand Down Expand Up @@ -423,10 +428,6 @@ describe("RoomViewStore", function () {
});
});

afterEach(() => {
jest.spyOn(SettingsStore, "getValue").mockReset();
});

it("subscribes to the room", async () => {
const setRoomVisible = jest
.spyOn(slidingSyncManager, "setRoomVisible")
Expand Down Expand Up @@ -600,10 +601,7 @@ describe("RoomViewStore", function () {
opts.buttons = buttons;
}
});

dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
await untilDispatch(Action.ViewRoom, dis);

await dispatchRoomLoaded();
expect(roomViewStore.getViewRoomOpts()).toEqual({ buttons });
});
});
Expand Down
Loading