Use knock rooms sync to reflect the knock state (#11596)

Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net>
This commit is contained in:
Charly Nguyen
2023-09-11 16:33:40 +00:00
committed by GitHub
parent bb91df1d3c
commit 5cf2e1514b
6 changed files with 10 additions and 46 deletions
+1 -5
View File
@@ -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<IRoomProps, IRoomState> {
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<IRoomProps, IRoomState> {
: 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<IRoomProps, IRoomState> {
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<IRoomProps, IRoomState> {
<RoomPreviewBar
room={this.state.room}
promptAskToJoin={myMembership === "leave" || this.state.promptAskToJoin}
knocked={myMembership === "knock" || this.state.knocked}
knocked={myMembership === "knock"}
onSubmitAskToJoin={this.onSubmitAskToJoin}
onCancelAskToJoin={this.onCancelAskToJoin}
onForgetClick={this.onForgetClick}
-1
View File
@@ -73,7 +73,6 @@ const RoomContext = createContext<
msc3946ProcessDynamicPredecessor: false,
canAskToJoin: false,
promptAskToJoin: false,
knocked: false,
});
RoomContext.displayName = "RoomContext";
export default RoomContext;
+4 -18
View File
@@ -119,7 +119,6 @@ interface State {
viewingCall: boolean;
promptAskToJoin: boolean;
knocked: boolean;
}
const INITIAL_STATE: State = {
@@ -141,7 +140,6 @@ const INITIAL_STATE: State = {
wasContextSwitch: false,
viewingCall: false,
promptAskToJoin: false,
knocked: false,
};
type Listener = (isActive: boolean) => 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 }),
);