Track restricted join rule support in the SpaceStore for sync access

pull/21833/head
Michael Telatynski 2021-07-06 10:09:35 +01:00
parent 82100df9ea
commit 692347843d
1 changed files with 64 additions and 56 deletions

View File

@ -19,6 +19,8 @@ import { ListIteratee, Many, sortBy, throttle } from "lodash";
import { EventType, RoomType } from "matrix-js-sdk/src/@types/event"; import { EventType, RoomType } from "matrix-js-sdk/src/@types/event";
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { JoinRule } from "matrix-js-sdk/src/@types/partials";
import { IRoomCapability } from "matrix-js-sdk/src/client";
import { AsyncStoreWithClient } from "./AsyncStoreWithClient"; import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
import defaultDispatcher from "../dispatcher/dispatcher"; import defaultDispatcher from "../dispatcher/dispatcher";
@ -45,7 +47,6 @@ import { _t } from "../languageHandler";
import GenericToast from "../components/views/toasts/GenericToast"; import GenericToast from "../components/views/toasts/GenericToast";
import Modal from "../Modal"; import Modal from "../Modal";
import InfoDialog from "../components/views/dialogs/InfoDialog"; import InfoDialog from "../components/views/dialogs/InfoDialog";
import { JoinRule } from "../../../matrix-js-sdk/src/@types/partials";
type SpaceKey = string | symbol; type SpaceKey = string | symbol;
@ -115,6 +116,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
private _suggestedRooms: ISuggestedRoom[] = []; private _suggestedRooms: ISuggestedRoom[] = [];
private _invitedSpaces = new Set<Room>(); private _invitedSpaces = new Set<Room>();
private spaceOrderLocalEchoMap = new Map<string, string>(); private spaceOrderLocalEchoMap = new Map<string, string>();
private _restrictedJoinRuleSupport?: IRoomCapability;
public get invitedSpaces(): Room[] { public get invitedSpaces(): Room[] {
return Array.from(this._invitedSpaces); return Array.from(this._invitedSpaces);
@ -132,6 +134,10 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
return this._suggestedRooms; return this._suggestedRooms;
} }
public get restrictedJoinRuleSupport(): IRoomCapability {
return this._restrictedJoinRuleSupport;
}
/** /**
* Sets the active space, updates room list filters, * Sets the active space, updates room list filters,
* optionally switches the user's room back to where they were when they last viewed that space. * optionally switches the user's room back to where they were when they last viewed that space.
@ -182,66 +188,63 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
} }
// New in Spaces beta toast for Restricted Join Rule // New in Spaces beta toast for Restricted Join Rule
(async () => { const lsKey = "mx_SpaceBeta_restrictedJoinRuleToastSeen";
const lsKey = "mx_SpaceBeta_restrictedJoinRuleToastSeen"; if (contextSwitch && space?.getJoinRule() === JoinRule.Invite && shouldShowSpaceSettings(space) &&
if (contextSwitch && space?.getJoinRule() === JoinRule.Invite && shouldShowSpaceSettings(space) && space.getJoinedMemberCount() > 1 && !localStorage.getItem(lsKey)
space.getJoinedMemberCount() > 1 && !localStorage.getItem(lsKey) /*&& && this.restrictedJoinRuleSupport?.preferred
(await this.matrixClient.getCapabilities()) ) {
?.["m.room_versions"]?.["org.matrix.msc3244.room_capabilities"]?.["restricted"]?.preferred*/ const toastKey = "restrictedjoinrule";
) { ToastStore.sharedInstance().addOrReplaceToast({
const toastKey = "restrictedjoinrule"; key: toastKey,
ToastStore.sharedInstance().addOrReplaceToast({ title: _t("New in the Spaces beta"),
key: toastKey, props: {
title: _t("New in the Spaces beta"), description: _t("Help people in spaces to find and join private rooms"),
props: { acceptLabel: _t("Learn more"),
description: _t("Help people in spaces to find and join private rooms"), onAccept: () => {
acceptLabel: _t("Learn more"), localStorage.setItem(lsKey, "true");
onAccept: () => { ToastStore.sharedInstance().dismissToast(toastKey);
localStorage.setItem(lsKey, "true");
ToastStore.sharedInstance().dismissToast(toastKey);
Modal.createTrackedDialog("New in the Spaces beta", "restricted join rule", InfoDialog, { Modal.createTrackedDialog("New in the Spaces beta", "restricted join rule", InfoDialog, {
title: _t("Help space members find private rooms"), title: _t("Help space members find private rooms"),
description: <> description: <>
<p>{ _t("To help space members find and join a private room, " + <p>{ _t("To help space members find and join a private room, " +
"go to that room's Security & Privacy settings.") }</p> "go to that room's Security & Privacy settings.") }</p>
{ /* Reuses classes from TabbedView for simplicity, non-interactive */ } { /* Reuses classes from TabbedView for simplicity, non-interactive */ }
<div style={{ width: "190px" }}> <div style={{ width: "190px" }}>
<div className="mx_TabbedView_tabLabel"> <div className="mx_TabbedView_tabLabel">
<span className="mx_TabbedView_maskedIcon mx_RoomSettingsDialog_settingsIcon" /> <span className="mx_TabbedView_maskedIcon mx_RoomSettingsDialog_settingsIcon" />
<span className="mx_TabbedView_tabLabel_text">{ _t("General") }</span> <span className="mx_TabbedView_tabLabel_text">{ _t("General") }</span>
</div>
<div className="mx_TabbedView_tabLabel mx_TabbedView_tabLabel_active">
<span className="mx_TabbedView_maskedIcon mx_RoomSettingsDialog_securityIcon" />
<span className="mx_TabbedView_tabLabel_text">{ _t("Security & Privacy") }</span>
</div>
<div className="mx_TabbedView_tabLabel">
<span className="mx_TabbedView_maskedIcon mx_RoomSettingsDialog_rolesIcon" />
<span className="mx_TabbedView_tabLabel_text">{ _t("Roles & Permissions") }</span>
</div>
</div> </div>
<div className="mx_TabbedView_tabLabel mx_TabbedView_tabLabel_active">
<span className="mx_TabbedView_maskedIcon mx_RoomSettingsDialog_securityIcon" />
<span className="mx_TabbedView_tabLabel_text">{ _t("Security & Privacy") }</span>
</div>
<div className="mx_TabbedView_tabLabel">
<span className="mx_TabbedView_maskedIcon mx_RoomSettingsDialog_rolesIcon" />
<span className="mx_TabbedView_tabLabel_text">{ _t("Roles & Permissions") }</span>
</div>
</div>
<p>{ _t("This make it easy for rooms to stay private to a space, " + <p>{ _t("This make it easy for rooms to stay private to a space, " +
"while letting people in the space find and join them. " + "while letting people in the space find and join them. " +
"All new rooms in a space will have this option available.")}</p> "All new rooms in a space will have this option available.")}</p>
</>, </>,
button: _t("OK"), button: _t("OK"),
hasCloseButton: false, hasCloseButton: false,
fixedWidth: true, fixedWidth: true,
}); });
},
rejectLabel: _t("Skip"),
onReject: () => {
localStorage.setItem(lsKey, "true");
ToastStore.sharedInstance().dismissToast(toastKey);
},
}, },
component: GenericToast, rejectLabel: _t("Skip"),
priority: 35, onReject: () => {
}); localStorage.setItem(lsKey, "true");
} ToastStore.sharedInstance().dismissToast(toastKey);
})().then(); },
},
component: GenericToast,
priority: 35,
});
}
if (space) { if (space) {
const suggestedRooms = await this.fetchSuggestedRooms(space); const suggestedRooms = await this.fetchSuggestedRooms(space);
@ -709,6 +712,11 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
this.matrixClient.on("accountData", this.onAccountData); this.matrixClient.on("accountData", this.onAccountData);
} }
this.matrixClient.getCapabilities().then(capabilities => {
this._restrictedJoinRuleSupport = capabilities
?.["m.room_versions"]?.["org.matrix.msc3244.room_capabilities"]?.["restricted"];
});
await this.onSpaceUpdate(); // trigger an initial update await this.onSpaceUpdate(); // trigger an initial update
// restore selected state from last session if any and still valid // restore selected state from last session if any and still valid