Skip to content

Commit 821416d

Browse files
committed
Use the JoinRuleSettings component for the guest link access prompt.
1 parent 00aadf1 commit 821416d

File tree

5 files changed

+64
-35
lines changed

5 files changed

+64
-35
lines changed

res/css/views/settings/_JoinRuleSettings.pcss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ Please see LICENSE files in the repository root for full details.
5353
display: block;
5454
}
5555

56+
&.mx_StyledRadioButton_disabled {
57+
opacity: 0.5;
58+
}
59+
60+
&.mx_StyledRadioButton_disabled + span {
61+
opacity: 0.5;
62+
}
63+
5664
& + span {
5765
display: inline-block;
5866
margin-left: 34px;
@@ -71,3 +79,7 @@ Please see LICENSE files in the repository root for full details.
7179
font: var(--cpd-font-body-md-regular);
7280
margin-top: var(--cpd-space-2x);
7381
}
82+
83+
.mx_JoinRuleSettings_recommended {
84+
color: $accent-1000;
85+
}

src/components/views/rooms/RoomHeader/CallGuestLinkButton.tsx

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import { EventType, JoinRule, Room } from "matrix-js-sdk/src/matrix";
1414
import Modal from "../../../../Modal";
1515
import ShareDialog from "../../dialogs/ShareDialog";
1616
import { _t } from "../../../../languageHandler";
17-
import SettingsStore from "../../../../settings/SettingsStore";
1817
import { calculateRoomVia } from "../../../../utils/permalinks/Permalinks";
1918
import BaseDialog from "../../dialogs/BaseDialog";
2019
import { useGuestAccessInformation } from "../../../../hooks/room/useGuestAccessInformation";
20+
import JoinRuleSettings from "../../settings/JoinRuleSettings";
2121

2222
/**
2323
* Display a button to open a dialog to share a link to the call using a element call guest spa url (`element_call:guest_spa_url` in the EW config).
@@ -99,7 +99,6 @@ export const JoinRuleDialog: React.FC<{
9999
room: Room;
100100
canInvite: boolean;
101101
}> = ({ onFinished, room, canInvite }) => {
102-
const askToJoinEnabled = SettingsStore.getValue("feature_ask_to_join");
103102
const [isUpdating, setIsUpdating] = React.useState<undefined | JoinRule>(undefined);
104103
const changeJoinRule = useCallback(
105104
async (newRule: JoinRule) => {
@@ -120,27 +119,24 @@ export const JoinRuleDialog: React.FC<{
120119
);
121120
return (
122121
<BaseDialog title={_t("update_room_access_modal|title")} onFinished={onFinished} className="mx_JoinRuleDialog">
123-
<p>{_t("update_room_access_modal|description")}</p>
124-
<div className="mx_JoinRuleDialogButtons">
125-
{askToJoinEnabled && canInvite && (
126-
<Button
127-
kind="secondary"
128-
className="mx_Dialog_nonDialogButton"
129-
disabled={isUpdating === JoinRule.Knock}
130-
onClick={() => changeJoinRule(JoinRule.Knock)}
131-
>
132-
{_t("action|ask_to_join")}
133-
</Button>
134-
)}
135-
<Button
136-
className="mx_Dialog_nonDialogButton"
137-
kind="destructive"
138-
disabled={isUpdating === JoinRule.Public}
139-
onClick={() => changeJoinRule(JoinRule.Public)}
140-
>
141-
{_t("common|public")}
142-
</Button>
143-
</div>
122+
<p>{_t("update_room_access_modal|description", {}, { b: (sub) => <strong>{sub}</strong> })}</p>
123+
<p>
124+
{_t("update_room_access_modal|revert_access_description", {}, { b: (sub) => <strong>{sub}</strong> })}
125+
</p>
126+
<JoinRuleSettings
127+
recommendedOption={JoinRule.Knock}
128+
room={room}
129+
disabledOptions={new Set([JoinRule.Invite, JoinRule.Private, JoinRule.Restricted])}
130+
hiddenOptions={new Set([JoinRule.Restricted])}
131+
beforeChange={async (newRule) => {
132+
await changeJoinRule(newRule).catch(() => {
133+
return false;
134+
});
135+
return true;
136+
}}
137+
closeSettingsFn={() => {}}
138+
onError={(error: unknown) => logger.error("Could not generate change access level:", error)}
139+
/>
144140
<p>{_t("update_room_access_modal|dont_change_description")}</p>
145141
<div className="mx_JoinRuleDialogButtons">
146142
<Button

src/components/views/settings/JoinRuleSettings.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export interface JoinRuleSettingsProps {
3636
onError(error: unknown): void;
3737
beforeChange?(joinRule: JoinRule): Promise<boolean>; // if returns false then aborts the change
3838
aliasWarning?: ReactNode;
39+
disabledOptions?: Set<JoinRule>;
40+
hiddenOptions?: Set<JoinRule>;
41+
recommendedOption?: JoinRule;
3942
}
4043

4144
const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
@@ -45,6 +48,9 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
4548
onError,
4649
beforeChange,
4750
closeSettingsFn,
51+
disabledOptions,
52+
hiddenOptions,
53+
recommendedOption,
4854
}) => {
4955
const cli = room.client;
5056

@@ -147,7 +153,7 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
147153
}
148154
});
149155

150-
closeSettingsFn();
156+
closeSettingsFn?.();
151157

152158
// switch to the new room in the background
153159
dis.dispatch<ViewRoomPayload>({
@@ -170,18 +176,26 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
170176
{_t("room_settings|security|join_rule_upgrade_required")}
171177
</span>
172178
);
179+
const withRecommendLabel = (label: string, rule: JoinRule): React.ReactNode =>
180+
rule === recommendedOption ? (
181+
<>
182+
{label} (<span className="mx_JoinRuleSettings_recommended">{_t("common|recommended")}</span>)
183+
</>
184+
) : (
185+
label
186+
);
173187

174188
const definitions: IDefinition<JoinRule>[] = [
175189
{
176190
value: JoinRule.Invite,
177-
label: _t("room_settings|security|join_rule_invite"),
191+
label: withRecommendLabel(_t("room_settings|security|join_rule_invite"), JoinRule.Invite),
178192
description: _t("room_settings|security|join_rule_invite_description"),
179193
checked:
180194
joinRule === JoinRule.Invite || (joinRule === JoinRule.Restricted && !restrictedAllowRoomIds?.length),
181195
},
182196
{
183197
value: JoinRule.Public,
184-
label: _t("common|public"),
198+
label: withRecommendLabel(_t("common|public"), JoinRule.Public),
185199
description: (
186200
<>
187201
{_t("room_settings|security|join_rule_public_description")}
@@ -292,7 +306,7 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
292306
value: JoinRule.Restricted,
293307
label: (
294308
<>
295-
{_t("room_settings|security|join_rule_restricted")}
309+
{withRecommendLabel(_t("room_settings|security|join_rule_restricted"), JoinRule.Restricted)}
296310
{preferredRestrictionVersion && upgradeRequiredPill}
297311
</>
298312
),
@@ -303,11 +317,11 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
303317
}
304318

305319
if (askToJoinEnabled && (roomSupportsKnock || preferredKnockVersion)) {
306-
definitions.push({
320+
definitions.splice(Math.max(0, definitions.length - 1), 0, {
307321
value: JoinRule.Knock,
308322
label: (
309323
<>
310-
{_t("room_settings|security|join_rule_knock")}
324+
{withRecommendLabel(_t("room_settings|security|join_rule_knock"), JoinRule.Knock)}
311325
{preferredKnockVersion && upgradeRequiredPill}
312326
</>
313327
),
@@ -397,7 +411,9 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
397411
name="joinRule"
398412
value={joinRule}
399413
onChange={onChange}
400-
definitions={definitions}
414+
definitions={definitions
415+
.map((d) => (disabledOptions?.has(d.value) ? { ...d, disabled: true } : d))
416+
.filter((d) => !hiddenOptions?.has(d.value))}
401417
disabled={disabled}
402418
className="mx_JoinRuleSettings_radioButton"
403419
/>

src/i18n/strings/de_DE.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,8 +3693,11 @@
36933693
"unavailable": "Nicht verfügbar"
36943694
},
36953695
"update_room_access_modal": {
3696-
"no_change": "Ich möchte die Zugriffsebene nicht ändern.",
3697-
"title": "Ändern Sie die Zugriffsebene des Raums"
3696+
"description": "Um einen Konferenzlink zu erstellen, mache diesen Raum <b>öffentlich</b> oder aktiviere die Option, dass Benutzer eine <b>Beitrittsanfrage</b> stellen können. So können Gäste ohne direkte Einladung beitreten.",
3697+
"dont_change_description": "Wenn die Zugriffsrechte dieses Raums unverändert bleiben sollen, erstelle einen neuen Raum für den Element-Anruf.",
3698+
"revert_access_description": "(In den Raum Einstellungen kann die Zutrittseinstellung zurückgesetzt werden: <b>Sicherheit</b> / <b>Zutritt</b>)",
3699+
"no_change": "Ich möchte die Raum Zutrittseinstellung nicht ändern.",
3700+
"title": "Erlaube Gastbenutzern, diesen Raum beizutreten"
36983701
},
36993702
"upload_failed_generic": "Die Datei „%(fileName)s“ konnte nicht hochgeladen werden.",
37003703
"upload_failed_size": "Die Datei „%(fileName)s“ überschreitet das Hochladelimit deines Heim-Servers",

src/i18n/strings/en_EN.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@
542542
"qr_code": "QR Code",
543543
"random": "Random",
544544
"reactions": "Reactions",
545+
"recommended": "Recommended",
545546
"report_a_bug": "Report a bug",
546547
"room": "Room",
547548
"room_name": "Room name",
@@ -3718,10 +3719,11 @@
37183719
"unavailable": "Unavailable"
37193720
},
37203721
"update_room_access_modal": {
3721-
"description": "To create a share link, you need to allow guests to join this room. This may make the room less secure. When you're done with the call, you can make the room private again.",
3722-
"dont_change_description": "Alternatively, you can hold the call in a separate room.",
3722+
"description": "To create a share link, make this room <b>public</b> or enable the option for users to <b>ask to join</b>. This allows guests to join without being invited.",
3723+
"dont_change_description": "If you don't want to change the access of this room, you can create a new room for the call link.",
37233724
"no_change": "I don't want to change the access level.",
3724-
"title": "Change the room access level"
3725+
"revert_access_description": "(This can be reverted to the previous value in the Room Settings: <b>Security & Privacy</b> / <b>Access</b>)",
3726+
"title": "Allow guest users to join this room"
37253727
},
37263728
"upload_failed_generic": "The file '%(fileName)s' failed to upload.",
37273729
"upload_failed_size": "The file '%(fileName)s' exceeds this homeserver's size limit for uploads",

0 commit comments

Comments
 (0)