mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-04 14:30:29 +03:00
prevent listing "private" rooms on directory
This commit is contained in:
parent
31942b1114
commit
cdaeb18798
1 changed files with 8 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import React from 'react';
|
||||
import { Box, color, Spinner, Switch, Text } from 'folds';
|
||||
import { MatrixError } from 'matrix-js-sdk';
|
||||
import { JoinRule, MatrixError } from 'matrix-js-sdk';
|
||||
import { RoomJoinRulesEventContent } from 'matrix-js-sdk/lib/types';
|
||||
import { SequenceCard } from '../../../components/sequence-card';
|
||||
import { SequenceCardStyle } from '../../room-settings/styles.css';
|
||||
import { SettingTile } from '../../../components/setting-tile';
|
||||
|
|
@ -10,6 +11,7 @@ import { AsyncStatus, useAsyncCallback } from '../../../hooks/useAsyncCallback';
|
|||
import { IPowerLevels, powerLevelAPI } from '../../../hooks/usePowerLevels';
|
||||
import { StateEvent } from '../../../../types/matrix/room';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { useStateEvent } from '../../../hooks/useStateEvent';
|
||||
|
||||
type RoomPublishProps = {
|
||||
powerLevels: IPowerLevels;
|
||||
|
|
@ -23,6 +25,9 @@ export function RoomPublish({ powerLevels }: RoomPublishProps) {
|
|||
StateEvent.RoomCanonicalAlias,
|
||||
userPowerLevel
|
||||
);
|
||||
const joinRuleEvent = useStateEvent(room, StateEvent.RoomJoinRules);
|
||||
const content = joinRuleEvent?.getContent<RoomJoinRulesEventContent>();
|
||||
const rule: JoinRule = content?.join_rule ?? JoinRule.Invite;
|
||||
|
||||
const { visibilityState, setVisibility } = useRoomDirectoryVisibility(room.roomId);
|
||||
|
||||
|
|
@ -30,6 +35,7 @@ export function RoomPublish({ powerLevels }: RoomPublishProps) {
|
|||
|
||||
const loading =
|
||||
visibilityState.status === AsyncStatus.Loading || toggleState.status === AsyncStatus.Loading;
|
||||
const validRule = rule === JoinRule.Public || rule === JoinRule.Knock;
|
||||
|
||||
return (
|
||||
<SequenceCard
|
||||
|
|
@ -47,7 +53,7 @@ export function RoomPublish({ powerLevels }: RoomPublishProps) {
|
|||
<Switch
|
||||
value={visibilityState.data}
|
||||
onChange={toggleVisibility}
|
||||
disabled={!canEditCanonical}
|
||||
disabled={!(canEditCanonical && validRule)}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue