diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index d1b569ccfa3..c6162b4d289 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -245,7 +245,6 @@ export interface IRoomState { canAskToJoin: boolean; promptAskToJoin: boolean; - knocked: boolean; } interface LocalRoomViewProps { @@ -458,7 +457,6 @@ export class RoomView extends React.Component { msc3946ProcessDynamicPredecessor: SettingsStore.getValue("feature_dynamic_room_predecessors"), canAskToJoin: this.askToJoinEnabled, promptAskToJoin: false, - knocked: false, }; this.dispatcherRef = dis.register(this.onAction); @@ -664,7 +662,6 @@ export class RoomView extends React.Component { : false, activeCall: roomId ? CallStore.instance.getActiveCall(roomId) : null, promptAskToJoin: this.context.roomViewStore.promptAskToJoin(), - knocked: this.context.roomViewStore.knocked(), }; if ( @@ -2118,7 +2115,6 @@ export class RoomView extends React.Component { signUrl={this.props.threepidInvite?.signUrl} roomId={this.state.roomId} promptAskToJoin={this.state.promptAskToJoin} - knocked={this.state.knocked} onSubmitAskToJoin={this.onSubmitAskToJoin} onCancelAskToJoin={this.onCancelAskToJoin} /> @@ -2202,7 +2198,7 @@ export class RoomView extends React.Component { void; @@ -775,15 +773,6 @@ export class RoomViewStore extends EventEmitter { return this.state.promptAskToJoin; } - /** - * Gets the current state of the 'knocked' property. - * - * @returns {boolean} The value of the 'knocked' property. - */ - public knocked(): boolean { - return this.state.knocked; - } - /** * Submits a request to join a room by sending a knock request. * @@ -793,15 +782,13 @@ export class RoomViewStore extends EventEmitter { private submitAskToJoin(payload: SubmitAskToJoinPayload): void { MatrixClientPeg.safeGet() .knockRoom(payload.roomId, { viaServers: this.state.viaServers, ...payload.opts }) - .then(() => this.setState({ promptAskToJoin: false, knocked: true })) - .catch((err: MatrixError) => { - this.setState({ promptAskToJoin: false }); - + .catch((err: MatrixError) => Modal.createDialog(ErrorDialog, { title: _t("Failed to join"), description: err.httpStatus === 403 ? _t("You need an invite to access this room.") : err.message, - }); - }); + }), + ) + .finally(() => this.setState({ promptAskToJoin: false })); } /** @@ -813,7 +800,6 @@ export class RoomViewStore extends EventEmitter { private cancelAskToJoin(payload: CancelAskToJoinPayload): void { MatrixClientPeg.safeGet() .leave(payload.roomId) - .then(() => this.setState({ knocked: false })) .catch((err: MatrixError) => Modal.createDialog(ErrorDialog, { title: _t("Failed to cancel"), description: err.message }), ); diff --git a/test/components/views/rooms/SendMessageComposer-test.tsx b/test/components/views/rooms/SendMessageComposer-test.tsx index 00c6d6714d2..077f09fd35a 100644 --- a/test/components/views/rooms/SendMessageComposer-test.tsx +++ b/test/components/views/rooms/SendMessageComposer-test.tsx @@ -85,7 +85,6 @@ describe("", () => { msc3946ProcessDynamicPredecessor: false, canAskToJoin: false, promptAskToJoin: false, - knocked: false, }; describe("createMessageContent", () => { const permalinkCreator = jest.fn() as any; diff --git a/test/stores/RoomViewStore-test.ts b/test/stores/RoomViewStore-test.ts index b3e9f6613e9..6322d9acc01 100644 --- a/test/stores/RoomViewStore-test.ts +++ b/test/stores/RoomViewStore-test.ts @@ -507,39 +507,25 @@ describe("RoomViewStore", function () { }); }); - describe("knocked()", () => { - it("returns false", () => { - expect(roomViewStore.knocked()).toBe(false); - }); - - it("returns true", async () => { - jest.spyOn(mockClient, "knockRoom").mockResolvedValue({ room_id: roomId }); - await dispatchSubmitAskToJoin(roomId); - expect(roomViewStore.knocked()).toBe(true); - }); - }); - describe("Action.SubmitAskToJoin", () => { const reason = "some reason"; beforeEach(async () => await dispatchPromptAskToJoin()); - it("calls knockRoom(), sets askToJoin state to false and knocked state to true", async () => { + it("calls knockRoom() and sets promptAskToJoin state to false", async () => { jest.spyOn(mockClient, "knockRoom").mockResolvedValue({ room_id: roomId }); await dispatchSubmitAskToJoin(roomId, reason); expect(mockClient.knockRoom).toHaveBeenCalledWith(roomId, { reason, viaServers: [] }); expect(roomViewStore.promptAskToJoin()).toBe(false); - expect(roomViewStore.knocked()).toBe(true); }); - it("calls knockRoom(), sets askToJoin to false, keeps knocked state false and shows an error dialog", async () => { + it("calls knockRoom(), sets promptAskToJoin state to false and shows an error dialog", async () => { const error = new MatrixError(undefined, 403); jest.spyOn(mockClient, "knockRoom").mockRejectedValue(error); await dispatchSubmitAskToJoin(roomId, reason); expect(mockClient.knockRoom).toHaveBeenCalledWith(roomId, { reason, viaServers: [] }); expect(roomViewStore.promptAskToJoin()).toBe(false); - expect(roomViewStore.knocked()).toBe(false); expect(Modal.createDialog).toHaveBeenCalledWith(ErrorDialog, { description: "You need an invite to access this room.", title: "Failed to join", @@ -550,6 +536,7 @@ describe("RoomViewStore", function () { const error = new MatrixError(); jest.spyOn(mockClient, "knockRoom").mockRejectedValue(error); await dispatchSubmitAskToJoin(roomId); + expect(Modal.createDialog).toHaveBeenCalledWith(ErrorDialog, { description: error.message, title: "Failed to join", @@ -563,21 +550,19 @@ describe("RoomViewStore", function () { await dispatchSubmitAskToJoin(roomId); }); - it("calls leave() and sets knocked state to false", async () => { + it("calls leave()", async () => { jest.spyOn(mockClient, "leave").mockResolvedValue({}); await dispatchCancelAskToJoin(roomId); expect(mockClient.leave).toHaveBeenCalledWith(roomId); - expect(roomViewStore.knocked()).toBe(false); }); - it("calls leave(), keeps knocked state true and shows an error dialog", async () => { + it("calls leave() and shows an error dialog", async () => { const error = new MatrixError(); jest.spyOn(mockClient, "leave").mockRejectedValue(error); await dispatchCancelAskToJoin(roomId); expect(mockClient.leave).toHaveBeenCalledWith(roomId); - expect(roomViewStore.knocked()).toBe(true); expect(Modal.createDialog).toHaveBeenCalledWith(ErrorDialog, { description: error.message, title: "Failed to cancel", diff --git a/test/test-utils/room.ts b/test/test-utils/room.ts index 5cd27782428..5c4142005ae 100644 --- a/test/test-utils/room.ts +++ b/test/test-utils/room.ts @@ -90,7 +90,6 @@ export function getRoomContext(room: Room, override: Partial): IRoom msc3946ProcessDynamicPredecessor: false, canAskToJoin: false, promptAskToJoin: false, - knocked: false, ...override, };