Skip to content

Commit

Permalink
Use the JoinRuleSettings component for the guest link access prompt.
Browse files Browse the repository at this point in the history
  • Loading branch information
toger5 committed Dec 2, 2024
1 parent 00aadf1 commit 57bf52a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 29 deletions.
8 changes: 8 additions & 0 deletions res/css/views/settings/_JoinRuleSettings.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ Please see LICENSE files in the repository root for full details.
display: block;
}

&.mx_StyledRadioButton_disabled {
opacity: 0.5;
}

&.mx_StyledRadioButton_disabled + span {
opacity: 0.5;
}

& + span {
display: inline-block;
margin-left: 34px;
Expand Down
40 changes: 17 additions & 23 deletions src/components/views/rooms/RoomHeader/CallGuestLinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { EventType, JoinRule, Room } from "matrix-js-sdk/src/matrix";
import Modal from "../../../../Modal";
import ShareDialog from "../../dialogs/ShareDialog";
import { _t } from "../../../../languageHandler";
import SettingsStore from "../../../../settings/SettingsStore";
import { calculateRoomVia } from "../../../../utils/permalinks/Permalinks";
import BaseDialog from "../../dialogs/BaseDialog";
import { useGuestAccessInformation } from "../../../../hooks/room/useGuestAccessInformation";
import JoinRuleSettings from "../../settings/JoinRuleSettings";

/**
* 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).
Expand Down Expand Up @@ -99,7 +99,6 @@ export const JoinRuleDialog: React.FC<{
room: Room;
canInvite: boolean;
}> = ({ onFinished, room, canInvite }) => {
const askToJoinEnabled = SettingsStore.getValue("feature_ask_to_join");
const [isUpdating, setIsUpdating] = React.useState<undefined | JoinRule>(undefined);
const changeJoinRule = useCallback(
async (newRule: JoinRule) => {
Expand All @@ -120,27 +119,22 @@ export const JoinRuleDialog: React.FC<{
);
return (
<BaseDialog title={_t("update_room_access_modal|title")} onFinished={onFinished} className="mx_JoinRuleDialog">
<p>{_t("update_room_access_modal|description")}</p>
<div className="mx_JoinRuleDialogButtons">
{askToJoinEnabled && canInvite && (
<Button
kind="secondary"
className="mx_Dialog_nonDialogButton"
disabled={isUpdating === JoinRule.Knock}
onClick={() => changeJoinRule(JoinRule.Knock)}
>
{_t("action|ask_to_join")}
</Button>
)}
<Button
className="mx_Dialog_nonDialogButton"
kind="destructive"
disabled={isUpdating === JoinRule.Public}
onClick={() => changeJoinRule(JoinRule.Public)}
>
{_t("common|public")}
</Button>
</div>
<p>{_t("update_room_access_modal|description", {}, { b: (sub) => <strong>{sub}</strong> })}</p>
<p>
{_t("update_room_access_modal|revert_access_description", {}, { b: (sub) => <strong>{sub}</strong> })}
</p>
<JoinRuleSettings
room={room}
disabledOptions={new Set([JoinRule.Invite, JoinRule.Private, JoinRule.Restricted])}
beforeChange={async (newRule) => {
await changeJoinRule(newRule).catch(() => {
return false;
});
return true;
}}
closeSettingsFn={() => {}}
onError={(error: unknown) => logger.error("Could not generate change access level:", error)}
/>
<p>{_t("update_room_access_modal|dont_change_description")}</p>
<div className="mx_JoinRuleDialogButtons">
<Button
Expand Down
6 changes: 4 additions & 2 deletions src/components/views/settings/JoinRuleSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface JoinRuleSettingsProps {
onError(error: unknown): void;
beforeChange?(joinRule: JoinRule): Promise<boolean>; // if returns false then aborts the change
aliasWarning?: ReactNode;
disabledOptions?: Set<JoinRule>;
}

const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
Expand All @@ -45,6 +46,7 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
onError,
beforeChange,
closeSettingsFn,
disabledOptions,
}) => {
const cli = room.client;

Expand Down Expand Up @@ -147,7 +149,7 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
}
});

closeSettingsFn();
closeSettingsFn?.();

// switch to the new room in the background
dis.dispatch<ViewRoomPayload>({
Expand Down Expand Up @@ -397,7 +399,7 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
name="joinRule"
value={joinRule}
onChange={onChange}
definitions={definitions}
definitions={definitions.map((d) => (disabledOptions?.has(d.value) ? { ...d, disabled: true } : d))}
disabled={disabled}
className="mx_JoinRuleSettings_radioButton"
/>
Expand Down
7 changes: 5 additions & 2 deletions src/i18n/strings/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -3693,8 +3693,11 @@
"unavailable": "Nicht verfügbar"
},
"update_room_access_modal": {
"no_change": "Ich möchte die Zugriffsebene nicht ändern.",
"title": "Ändern Sie die Zugriffsebene des Raums"
"description": "Um einen Konferenzlink zu erstellen müssen sie es Gästen erlauben diesem Raum beizutreten ohne deren matrix id einzuladen. Der Raum muss <b>Öffentlich</b> sein oder sie mussen es den nutzern erlauben <b>Beitrittsanfragen</b> zu stellen.",
"dont_change_description": "Wenn sie die Raum Zutrittseinstellung nicht ändern möchten, kann ein neuer Raum fuer die Konferenz erstellt werden.",
"revert_access_description": "(In den Raum Einstellungen kann die Zutrittseinstellung zurückgesetzt werden: <b>Sicherheit</b> / <b>Zutritt</b>)",
"no_change": "Ich möchte die Raum Zutrittseinstellung nicht ändern.",
"title": "Ändern Sie die Raum Zutrittseinstellung"
},
"upload_failed_generic": "Die Datei „%(fileName)s“ konnte nicht hochgeladen werden.",
"upload_failed_size": "Die Datei „%(fileName)s“ überschreitet das Hochladelimit deines Heim-Servers",
Expand Down
5 changes: 3 additions & 2 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -3718,9 +3718,10 @@
"unavailable": "Unavailable"
},
"update_room_access_modal": {
"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.",
"dont_change_description": "Alternatively, you can hold the call in a separate room.",
"description": "To create a share link, you need to allow guests to join this room without inviting there user id. The room needs to be <b>public</b> or you need to allow users to <b>ask to join</b>.",
"dont_change_description": "If you don't want to change the access of this room, you can create a new room for the element call.",
"no_change": "I don't want to change the access level.",
"revert_access_description": "(This can be reverted to the previous value in the Room Settings: <b>Security & Privacy</b> / <b>Access</b>)",
"title": "Change the room access level"
},
"upload_failed_generic": "The file '%(fileName)s' failed to upload.",
Expand Down

0 comments on commit 57bf52a

Please sign in to comment.