Allow setting knock room directory visibility (#11529)
* Allow setting knock room directory visibility Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net> * Apply PR feedback Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net> --------- Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net>
This commit is contained in:
parent
77b681eed9
commit
0059c7c1ee
4 changed files with 122 additions and 6 deletions
|
@ -14,8 +14,15 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { ReactNode } from "react";
|
||||
import { IJoinRuleEventContent, JoinRule, RestrictedAllowType, Room, EventType } from "matrix-js-sdk/src/matrix";
|
||||
import React, { ReactNode, useEffect, useState } from "react";
|
||||
import {
|
||||
IJoinRuleEventContent,
|
||||
JoinRule,
|
||||
RestrictedAllowType,
|
||||
Room,
|
||||
EventType,
|
||||
Visibility,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import StyledRadioGroup, { IDefinition } from "../elements/StyledRadioGroup";
|
||||
import { _t } from "../../../languageHandler";
|
||||
|
@ -34,6 +41,7 @@ import { Action } from "../../../dispatcher/actions";
|
|||
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
|
||||
import { doesRoomVersionSupport, PreferredRoomVersions } from "../../../utils/PreferredRoomVersions";
|
||||
import SettingsStore from "../../../settings/SettingsStore";
|
||||
import LabelledCheckbox from "../elements/LabelledCheckbox";
|
||||
|
||||
export interface JoinRuleSettingsProps {
|
||||
room: Room;
|
||||
|
@ -76,6 +84,22 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
|
|||
? content?.allow?.filter((o) => o.type === RestrictedAllowType.RoomMembership).map((o) => o.room_id)
|
||||
: undefined;
|
||||
|
||||
const [isPublicKnockRoom, setIsPublicKnockRoom] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (joinRule === JoinRule.Knock) {
|
||||
cli.getRoomDirectoryVisibility(room.roomId)
|
||||
.then(({ visibility }) => setIsPublicKnockRoom(visibility === Visibility.Public))
|
||||
.catch(onError);
|
||||
}
|
||||
}, [cli, joinRule, onError, room.roomId]);
|
||||
|
||||
const onIsPublicKnockRoomChange = (checked: boolean): void => {
|
||||
cli.setRoomDirectoryVisibility(room.roomId, checked ? Visibility.Public : Visibility.Private)
|
||||
.then(() => setIsPublicKnockRoom(checked))
|
||||
.catch(onError);
|
||||
};
|
||||
|
||||
const editRestrictedRoomIds = async (): Promise<string[] | undefined> => {
|
||||
let selected = restrictedAllowRoomIds;
|
||||
if (!selected?.length && SpaceStore.instance.activeSpaceRoom) {
|
||||
|
@ -297,7 +321,22 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
|
|||
{preferredKnockVersion && upgradeRequiredPill}
|
||||
</>
|
||||
),
|
||||
description: _t("People cannot join unless access is granted."),
|
||||
description: (
|
||||
<>
|
||||
{_t("People cannot join unless access is granted.")}
|
||||
<LabelledCheckbox
|
||||
className="mx_JoinRuleSettings_labelledCheckbox"
|
||||
disabled={joinRule !== JoinRule.Knock}
|
||||
label={
|
||||
room.isSpaceRoom()
|
||||
? _t("Make this space visible in the public room directory.")
|
||||
: _t("Make this room visible in the public room directory.")
|
||||
}
|
||||
onChange={onIsPublicKnockRoomChange}
|
||||
value={isPublicKnockRoom}
|
||||
/>
|
||||
</>
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue