Skip to content

Commit

Permalink
Créer les salons dans un espace
Browse files Browse the repository at this point in the history
  • Loading branch information
jdauphant authored Sep 5, 2023
1 parent 201869d commit b33c60c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
9 changes: 7 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 @@ -43,13 +43,16 @@ interface IState {
tchapRoomType: TchapRoomType;
forumFederationSwitchValue: boolean;
showFederateSwitch: boolean;
createRoomInSpace: boolean;
}

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 All @@ -59,6 +62,7 @@ export default class TchapCreateRoomDialog extends React.Component<IProps, IStat
tchapRoomType: TchapRoomType.Private,
forumFederationSwitchValue: federationOptions.forumFederationSwitchDefaultValue,
showFederateSwitch: federationOptions.showForumFederationSwitch,
createRoomInSpace: createRoomInSpace,
};
}

Expand Down Expand Up @@ -149,7 +153,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 +180,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.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.createRoomInSpace ? _t("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.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
34 changes: 29 additions & 5 deletions src/tchap/lib/createTchapRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ export default class TchapCreateRoom {
createRoomOpts.creation_content = { "m.federate": federate };
createRoomOpts.initial_state = createRoomOpts.initial_state || [];

opts.parentSpace = this.props.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
if (this.props.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 +52,12 @@ export default class TchapCreateRoom {
state_key: "",
});

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



return opts;
}
}

0 comments on commit b33c60c

Please sign in to comment.