From: Gimle Larpes <97182804+GimleLarpes@users.noreply.github.com> Date: Tue, 5 Aug 2025 13:10:42 +0000 (+0300) Subject: Prevent publishing rooms with incompatible joinrules to directory (#2406) X-Git-Tag: v4.9.0~5 X-Git-Url: https://git.wafflesoft.org/?a=commitdiff_plain;h=e6f14e79da4cffb69e38adb42a4cfba5e6a13268;p=rainny.git Prevent publishing rooms with incompatible joinrules to directory (#2406) * prevent listing "private" rooms on directory * clean up boolean expression * add knock_restricted --- diff --git a/src/app/features/common-settings/general/RoomPublish.tsx b/src/app/features/common-settings/general/RoomPublish.tsx index e27c687..57a0114 100644 --- a/src/app/features/common-settings/general/RoomPublish.tsx +++ b/src/app/features/common-settings/general/RoomPublish.tsx @@ -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,8 @@ 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'; +import { ExtendedJoinRules } from '../../../components/JoinRulesSwitcher'; type RoomPublishProps = { powerLevels: IPowerLevels; @@ -23,6 +26,9 @@ export function RoomPublish({ powerLevels }: RoomPublishProps) { StateEvent.RoomCanonicalAlias, userPowerLevel ); + const joinRuleEvent = useStateEvent(room, StateEvent.RoomJoinRules); + const content = joinRuleEvent?.getContent(); + const rule: ExtendedJoinRules = (content?.join_rule as ExtendedJoinRules) ?? JoinRule.Invite; const { visibilityState, setVisibility } = useRoomDirectoryVisibility(room.roomId); @@ -30,6 +36,8 @@ export function RoomPublish({ powerLevels }: RoomPublishProps) { const loading = visibilityState.status === AsyncStatus.Loading || toggleState.status === AsyncStatus.Loading; + const validRule = + rule === JoinRule.Public || rule === JoinRule.Knock || rule === 'knock_restricted'; return ( )}