Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Créer les salons dans un espace #679

Merged
merged 14 commits into from
Sep 11, 2023
8 changes: 6 additions & 2 deletions src/tchap/components/views/dialogs/TchapCreateRoomDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import TchapCreateRoom from "../../../lib/createTchapRoom";
interface IProps {
defaultPublic?: boolean; // unused for Tchap version
defaultName?: string;
parentSpace?: Room; // unused for Tchap version
parentSpace?: Room;
defaultEncrypted?: boolean; // unused for Tchap version
onFinished(proceed: boolean, opts?: IOpts): void;
}
Expand All @@ -47,9 +47,11 @@ interface IState {

export default class TchapCreateRoomDialog extends React.Component<IProps, IState> {
private nameField = createRef<Field>();
private readonly createRoomInSpace: boolean;

public constructor(props) {
super(props);
this.createRoomInSpace = !!this.props.parentSpace;

const federationOptions = TchapUtils.getRoomFederationOptions();

Expand Down Expand Up @@ -132,6 +134,7 @@ export default class TchapCreateRoomDialog extends React.Component<IProps, IStat
this.state.name,
this.state.tchapRoomType,
this.isSelectedRoomFederated(),
this.props.parentSpace
),
);
} else {
Expand All @@ -149,7 +152,7 @@ export default class TchapCreateRoomDialog extends React.Component<IProps, IStat
public render() {
const shortDomain: string = TchapUtils.getShortDomain();

const title = _t("Create a room");
const title = this.createRoomInSpace ? _t("Create a room in this space") : _t("Create a room");

return (
<BaseDialog
Expand All @@ -176,6 +179,7 @@ export default class TchapCreateRoomDialog extends React.Component<IProps, IStat
forumFederationSwitchValue={this.state.forumFederationSwitchValue}
setForumFederationSwitchValue={this.onForumFederatedChange}
setRoomType={this.onTchapRoomTypeChange}
createRoomInSpace={this.createRoomInSpace}
/>
</div>
</form>
Expand Down
7 changes: 4 additions & 3 deletions src/tchap/components/views/elements/TchapRoomTypeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IProps {
forumFederationSwitchValue?: boolean;
setRoomType(value: TchapRoomType): void;
setForumFederationSwitchValue(forumFederationSwitchValue: boolean): void;
createRoomInSpace: boolean;
}

interface IState {
Expand Down Expand Up @@ -83,7 +84,7 @@ export default class TchapRoomTypeSelector extends React.Component<IProps, IStat
onChange={this.onRoomTypeChange}
>
<div className="tc_TchapRoomTypeSelector_RadioButton_title">{_t("Private room")}</div>
<div>{_t("Accessible to all users by invitation from an administrator.")}</div>
<div>{this.props.createRoomInSpace ? _t("Private discussions accessible to all users of this space.") : _t("Accessible to all users by invitation from an administrator.")}</div>
</StyledRadioButton>
</label>
<label className={externalClasses}>
Expand All @@ -97,7 +98,7 @@ export default class TchapRoomTypeSelector extends React.Component<IProps, IStat
{_t("Private room open to external users")}
</div>
<div>
{_t("Accessible to all users and to external guests by invitation of an administrator.")}
{this.props.createRoomInSpace ? _t("Private discussions accessible to all users of this space and to external guests by invitation of an administrator.") : _t("Accessible to all users and to external guests by invitation of an administrator.")}
</div>
</StyledRadioButton>
</label>
Expand All @@ -109,7 +110,7 @@ export default class TchapRoomTypeSelector extends React.Component<IProps, IStat
onChange={this.onRoomTypeChange}
>
<div className="tc_TchapRoomTypeSelector_RadioButton_title">{_t("Forum room")}</div>
<div>{_t("Accessible to all users from the forum directory or from a shared link.")}</div>
<div>{this.props.createRoomInSpace ? _t("Public discussion accessible to all users of this space or from a shared link.") : _t("Accessible to all users from the forum directory or from a shared link.")}</div>
{roomFederateOpt}
</StyledRadioButton>
</label>
Expand Down
16 changes: 16 additions & 0 deletions src/tchap/i18n/strings/tchap_translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@
"en":"Allow access to this room to all users, even outside \"%(domain)s\" domain",
"fr":"Autoriser l'accès à tous les utilisateurs, même ceux qui ne sont pas membres du domaine \"%(domain)s\""
},
"Create a room in this space": {
"en": "Create a room in this space",
"fr": "Créer un salon dans cet espace"
},
"Private discussions accessible to all users of this space.": {
"en": "Private discussions accessible to all users of this space.",
"fr": "Discussions privés accessible à tous les membres de cet espace"
odelcroi marked this conversation as resolved.
Show resolved Hide resolved
},
"Private discussions accessible to all users of this space and to external guests by invitation of an administrator.": {
"en": "Private discussions accessible to all users of this space and to external guests by invitation of an administrator.",
"fr": "Discussions privés accessible à tous les membres de cet espace et aux utilisateurs externes sur invitation d'un administrateur."
odelcroi marked this conversation as resolved.
Show resolved Hide resolved
},
"Public discussion accessible to all users of this space or from a shared link.": {
"en": "Public discussion accessible to all users of this space or from a shared link.",
"fr": "Discussions publiques accessible à tous les membres de cet espace ou depuis un lien de partage."
odelcroi marked this conversation as resolved.
Show resolved Hide resolved
},
"Scanning": {
"en": "Scanning",
"fr": "Scanning"
Expand Down
34 changes: 29 additions & 5 deletions src/tchap/lib/createTchapRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class TchapCreateRoom {
name: string,
tchapRoomType: TchapRoomType,
federate: boolean = DEFAULT_FEDERATE_VALUE,
parentSpace?: Room
): IOpts {
const opts: IOpts = {};
const createRoomOpts: ICreateRoomOpts = {};
Expand All @@ -30,10 +31,18 @@ export default class TchapCreateRoom {
createRoomOpts.creation_content = { "m.federate": federate };
createRoomOpts.initial_state = createRoomOpts.initial_state || [];

if(parentSpace) {
opts.parentSpace = parentSpace;
}

switch (tchapRoomType) {
case TchapRoomType.Forum: {
//"Forum" only for tchap members and not encrypted
createRoomOpts.visibility = Visibility.Public;
// Space "Forum" only for members and not encrypted
odelcroi marked this conversation as resolved.
Show resolved Hide resolved
if (parentSpace) {
createRoomOpts.visibility = Visibility.PrivateChat;
} else { //"Forum" only for tchap members and not encrypted
createRoomOpts.visibility = Visibility.Public;
}
createRoomOpts.preset = Preset.PublicChat;
// Here we could have used createRoomOpts.accessRule directly,
// but since accessRules are a custom Tchap event, it is ignored by later code.
Expand All @@ -46,7 +55,12 @@ export default class TchapCreateRoom {
state_key: "",
});

opts.joinRule = JoinRule.Public;
//Open to space by default
if (parentSpace) {
opts.joinRule = JoinRule.Restricted;
} else {
opts.joinRule = JoinRule.Public;
}
opts.encryption = false;
opts.historyVisibility = HistoryVisibility.Shared;
break;
Expand All @@ -62,7 +76,12 @@ export default class TchapCreateRoom {
type: TchapRoomAccessRulesEventId,
state_key: "",
});
opts.joinRule = JoinRule.Invite;
//Open to space by default
if (parentSpace) {
opts.joinRule = JoinRule.Restricted;
} else {
opts.joinRule = JoinRule.Invite;
}
opts.encryption = true;
opts.historyVisibility = HistoryVisibility.Invited;
break;
Expand All @@ -78,7 +97,12 @@ export default class TchapCreateRoom {
type: TchapRoomAccessRulesEventId,
state_key: "",
});
opts.joinRule = JoinRule.Invite;
//Open to space by default
if (parentSpace) {
opts.joinRule = JoinRule.Restricted;
} else {
opts.joinRule = JoinRule.Invite;
}
opts.encryption = true;
opts.historyVisibility = HistoryVisibility.Invited;
break;
Expand Down
Loading